Преглед на файлове

check: Make sure all non-critical output is sent to stdout

Jonas Borgström преди 11 години
родител
ревизия
477e1a39dd
променени са 2 файла, в които са добавени 12 реда и са изтрити 12 реда
  1. 5 1
      attic/archiver.py
  2. 7 11
      attic/repository.py

+ 5 - 1
attic/archiver.py

@@ -73,7 +73,11 @@ in data loss.
 Type "Yes I am sure" if you understand this and want to continue.\n""")
                 if input('Do you want to continue? ') == 'Yes I am sure':
                     break
-        if args.phase in ('all', 'repository') and not repository.check(repair=args.repair):
+        if args.phase in ('all', 'repository'):
+            print('Starting repository check...')
+            if repository.check(repair=args.repair):
+                print('Repository check complete, no problems found.')
+            else:
                 return 1
         if args.phase in ('all', 'archive') and not ArchiveChecker().check(repository, repair=args.repair):
                 return 1

+ 7 - 11
attic/repository.py

@@ -240,15 +240,13 @@ class Repository(object):
         the index is consistent with the data stored in the segments.
         """
         error_found = False
-        def report_progress(msg, error=False):
+        def report_error(msg):
             nonlocal error_found
-            if error:
-                error_found = True
+            error_found = True
             print(msg, file=sys.stderr)
             sys.stderr.flush()
 
         assert not self._active_txn
-        report_progress('Starting repository check...')
         try:
             transaction_id = self.get_transaction_id()
             current_index = self.get_read_only_index(transaction_id)
@@ -267,7 +265,7 @@ class Repository(object):
             try:
                 objects = list(self.io.iter_objects(segment))
             except (IntegrityError, struct.error):
-                report_progress('Error reading segment {}'.format(segment), error=True)
+                report_error('Error reading segment {}'.format(segment))
                 objects = []
                 if repair:
                     self.io.recover_segment(segment, filename)
@@ -294,22 +292,20 @@ class Repository(object):
                 elif tag == TAG_COMMIT:
                     continue
                 else:
-                    report_progress('Unexpected tag {} in segment {}'.format(tag, segment), error=True)
+                    report_error('Unexpected tag {} in segment {}'.format(tag, segment))
         # We might need to add a commit tag if no committed segment is found
         if repair and segments_transaction_id is None:
-            report_progress('Adding commit tag to segment {}'.format(transaction_id))
+            report_error('Adding commit tag to segment {}'.format(transaction_id))
             self.io.segment = transaction_id + 1
             self.io.write_commit()
             self.io.close_segment()
         if current_index and not repair:
             if len(current_index) != len(self.index):
-                report_progress('Index object count mismatch. {} != {}'.format(len(current_index), len(self.index)), error=True)
+                report_error('Index object count mismatch. {} != {}'.format(len(current_index), len(self.index)))
             elif current_index:
                 for key, value in self.index.iteritems():
                     if current_index.get(key, (-1, -1)) != value:
-                        report_progress('Index mismatch for key {}. {} != {}'.format(key, value, current_index.get(key, (-1, -1))), error=True)
-        if not error_found:
-            report_progress('Repository check complete, no problems found.')
+                        report_error('Index mismatch for key {}. {} != {}'.format(key, value, current_index.get(key, (-1, -1))))
         if repair:
             self.compact_segments()
             self.write_index()