Browse Source

python 3 compatiblity

Philippe Le Brouster 8 years ago
parent
commit
50a2ce3e71
4 changed files with 19 additions and 17 deletions
  1. 7 7
      bin/himport
  2. 8 8
      himports/dolibarrAlchemyHledger.py
  3. 1 1
      himports/dolibarrWriter.py
  4. 3 1
      himports/settings.py

+ 7 - 7
bin/himport

@@ -32,8 +32,8 @@ def process_args(argv):
             ["mysql-password=", "mysql-port", "year="]
         )
     except getopt.GetoptError:
-        print "himport: Invalid options"
-        print usage
+        print("himport: Invalid options")
+        print(usage)
         sys.exit(2)
 
     options['years'] = list()
@@ -41,7 +41,7 @@ def process_args(argv):
 
     for opt, arg in opts:
         if opt == '-h':
-            print usage
+            print(usage)
             sys.exit()
         elif opt in ("-v", "--verbose"):
             options['verbose'] += 1
@@ -49,9 +49,9 @@ def process_args(argv):
             options['years'].append(str(arg))
 
     if len(options['years']) == 0:
-        print "You need to specify the accounting years"
-        print ""
-        print usage
+        print("You need to specify the accounting years")
+        print("")
+        print(usage)
         sys.exit(1)
 
     return options
@@ -80,7 +80,7 @@ def do_sqlalchemy(options):
     pc_missing.update(supplier_journal.check_pc())
     pc_missing.update(social_journal.check_pc())
     if len(pc_missing) > 0:
-        print "WARNING: poste comptable manquant"
+        print("WARNING: poste comptable manquant")
         for pc in pc_missing:
             sys.stdout.write("%s\n" % (pc))
 

+ 8 - 8
himports/dolibarrAlchemyHledger.py

@@ -41,7 +41,7 @@ class HledgerEntry(object):
 
     # get_ledger : Print ledger output. Only defined in derived class
     def get_ledger(self):
-        print "WARNING: get_ledger not done"
+        print("WARNING: get_ledger not done")
         return u""
 
     # check_pc : verify the accounting chart corresponding to the entry. Only defined in derived class.
@@ -137,7 +137,7 @@ class HledgerBankEntry(HledgerEntry):
             for fn in fns:
                 try:
                     third_code = fn(e)
-                    if third_code is None or not isinstance(third_code, unicode):
+                    if third_code is None or not isinstance(third_code, str):
                         third_code = ""
                 except:
                     third_code = ""
@@ -332,11 +332,11 @@ class HledgerSupplierEntry(HledgerBillingEntry):
             total_ht -= ed.total_ht
 
         if total_ttc > 1e-10:
-            print "Erreur dans l'écriture %s: total ttc = %s" % (e.ref_supplier, total_ttc)
+            print("Erreur dans l'écriture %s: total ttc = %s" % (e.ref_supplier, total_ttc))
         if total_ht > 1e-10:
-            print "Erreur dans l'écriture %s: total ht = %s" % (e.ref_supplier, total_ht)
+            print("Erreur dans l'écriture %s: total ht = %s" % (e.ref_supplier, total_ht))
         if total_tva > 1e-10:
-            print "Erreur dans l'écriture %s: total tva = %s" % (e.ref_supplier, total_tva)
+            print("Erreur dans l'écriture %s: total tva = %s" % (e.ref_supplier, total_tva))
 
     # getMissingPC: retrieve missing accounts
     def getMissingPC(self):
@@ -519,11 +519,11 @@ class HledgerSellEntry(HledgerBillingEntry):
             total_ht -= ed.total_ht
 
         if total_ttc > 1e-10:
-            print "Erreur dans l'écriture %s: total ttc = %s" % (e.facnumber, total_ttc)
+            print("Erreur dans l'écriture %s: total ttc = %s" % (e.facnumber, total_ttc))
         if total_ht > 1e-10:
-            print "Erreur dans l'écriture %s: total ht = %s" % (e.facnumber, total_ht)
+            print("Erreur dans l'écriture %s: total ht = %s" % (e.facnumber, total_ht))
         if total_tva > 1e-10:
-            print "Erreur dans l'écriture %s: total tva = %s" % (e.facnumber, total_tva)
+            print("Erreur dans l'écriture %s: total tva = %s" % (e.facnumber, total_tva))
 
 
 #

+ 1 - 1
himports/dolibarrWriter.py

@@ -20,7 +20,7 @@ class Writer(object):
                 if not os.path.exists(output_dir):
                     os.makedirs(os.path.dirname(output_file))
                 elif not os.path.isdir(output_dir):
-                    print "Error: %s is not a dir\n" % (output_dir)
+                    print("Error: %s is not a dir\n" % (output_dir))
                     raise os.error()
 
                 f = codecs.open(output_file, 'w', 'utf-8')

+ 3 - 1
himports/settings.py

@@ -30,7 +30,9 @@ def get_ledger_account(code):
 __settings = {}
 for conf_file in CONF_FILES:
     if os.path.isfile(conf_file):
-        execfile(conf_file, __settings)
+        with open(conf_file) as f:
+            code = compile(f.read(), conf_file, 'exec')
+            exec(code, __settings)
 
 if __settings is None:
     raise Exception(