Commit b106d22f authored by plb's avatar plb
Browse files

Some cleaning & help

parent ed51b0fc
......@@ -21,18 +21,21 @@ sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
def process_args(argv):
options = {}
usage = u'himport -a -p -d -v -y'
usage = u'''Usage: himport -v -y <YEAR> [ -y <YEAR> ] ...
options:
-v : verbose mode
-y <YEAR> : import the corresponding accounting year
'''
try:
opts, args = getopt.getopt(
argv, "hp:P:advy:",
argv, "hvy:",
["mysql-password=", "mysql-port", "year="]
)
except getopt.GetoptError:
print "himport: Invalid options"
print usage
sys.exit(2)
options['alchemy'] = False
options['pdb'] = False
options['years'] = list()
options['verbose'] = 0
......@@ -40,19 +43,17 @@ def process_args(argv):
if opt == '-h':
print usage
sys.exit()
elif opt in ("-p", "--mysql-password"):
options['mysql_password'] = arg
elif opt in ("-P", "--mysql-port"):
options['mysql_port'] = arg
elif opt in ("-a", "--alchemy"):
options['alchemy'] = True
elif opt in ("-v", "--verbose"):
options['verbose'] += 1
elif opt in ("-d", "--pdb"):
options['pdb'] = True
elif opt in ("-y", "--year"):
options['years'].append(str(arg))
if len(options['years']) == 0:
print "You need to specify the accounting years"
print ""
print usage
sys.exit(1)
return options
......@@ -61,16 +62,10 @@ def do_sqlalchemy(options):
s = settings.get('MYSQL_SETTINGS')
password = s['password']
if 'mysql_password' in options:
password = options['mysql_password']
if password is None or password == "":
password = getpass.getpass("password for mysql user '%s': " % (s['user']))
port = s['port']
if 'mysql_port' in options:
port = options['mysql_port']
dolibarr = HledgerDolibarrSQLAlchemy(s['host'], port, s['database'], s['user'], password, options['verbose'] >= 2)
dolibarr = HledgerDolibarrSQLAlchemy(s['host'], s['port'], s['database'], s['user'], password, options['verbose'] >= 2)
dolibarr.connect()
bank_journal = dolibarr.get_bank_journal()
......@@ -103,10 +98,7 @@ def main(argv):
locale.setlocale(locale.LC_ALL, b'fr_FR.utf-8')
options = process_args(argv)
if options['alchemy']:
do_sqlalchemy(options)
else:
raise Exception("Not implemented")
do_sqlalchemy(options)
if __name__ == "__main__":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment