Parcourir la source

Swap first_op and last_op when needed.

pitchum il y a 8 ans
Parent
commit
9f9a144a94
1 fichiers modifiés avec 8 ajouts et 2 suppressions
  1. 8 2
      ccoop_resplit.py

+ 8 - 2
ccoop_resplit.py

@@ -67,6 +67,12 @@ class CsvStatementParser(object):
         # Remember first line of each CSV file
         if filename not in self.last_ops:
             self.last_ops[filename] = ophash
+        # CSV files are sometimes sorted by date ASC and sometimes
+        # sorted by date DESC. So we may need to swap first_op and last_op.
+        if (int(self.first_ops[filename][0:10].replace('-', '')) > int(self.last_ops[filename][0:10].replace('-', ''))):
+               tmp = self.first_ops[filename]
+               self.first_ops[filename] = self.last_ops[filename]
+               self.last_ops[filename] = tmp
     
     
     def dump_full(self, output_filename):
@@ -125,7 +131,7 @@ class CsvStatementParser(object):
                         if self.first_ops[candidate] == first_op:
                             otherfiles.remove(candidate)
                 if len(otherfiles) == 0:
-                    print("Attention. Il y a peut-être des écritures manquantes après le %s (fichier %s)." % (first_op[0:10], os.path.basename(filename)))
+                    print("Attention. Il y a peut-être des écritures manquantes avant le %s (fichier %s)." % (first_op[0:10], os.path.basename(filename)))
         
         for filename, last_op in self.last_ops.items():
             if last_op in self.overlap_detector:
@@ -137,7 +143,7 @@ class CsvStatementParser(object):
                         if self.last_ops[candidate] == last_op:
                             otherfiles.remove(candidate)
                 if len(otherfiles) == 0:
-                    print("Attention. Il y a peut-être des écritures manquantes avant le %s (fichier %s)." % (last_op[0:10], os.path.basename(filename)))
+                    print("Attention. Il y a peut-être des écritures manquantes après le %s (fichier %s)." % (last_op[0:10], os.path.basename(filename)))
         print("")
 
 def start_cli(dirpath):