Skip to content

Commit

Permalink
Use distutils rather than which to check PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
egh committed Oct 12, 2016
1 parent 9877a70 commit 72f9a18
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions ledgerautosync/ledgerwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,14 @@ def mk_ledger(ledger_file):
import ledger
return LedgerPython(ledger_file, string_read=False)
except ImportError:
if os.name == 'posix':
if ((subprocess.call("which ledger > /dev/null", shell=True) == 0)
and (Popen(["ledger", "--version"], stdout=PIPE).
communicate()[0]).startswith("Ledger 3")):
if ((distutils.spawn.find_executable('ledger') is not None) and
(Popen(["ledger", "--version"], stdout=PIPE).
communicate()[0]).startswith("Ledger 3")):
return Ledger(ledger_file)
elif subprocess.call("which hledger > /dev/null", shell=True) == 0:
return HLedger(ledger_file)
else:
raise Exception("Neither ledger 3 nor hledger found!")
elif distutils.spawn.find_executable('hledger') is not None:
return HLedger(ledger_file)
else:
# windows, I guess ... just assume ledger
return Ledger(ledger_file)

raise Exception("Neither ledger 3 nor hledger found!")

class Ledger(object):
def __init__(self, ledger_file=None, no_pipe=True):
Expand Down

0 comments on commit 72f9a18

Please sign in to comment.