From 477e1a39ddecbda24a63dfe6d6bc7a62355cd39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Tue, 4 Mar 2014 21:21:58 +0100 Subject: [PATCH] check: Make sure all non-critical output is sent to stdout --- attic/archiver.py | 6 +++++- attic/repository.py | 18 +++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/attic/archiver.py b/attic/archiver.py index eec1045a0..2a5a80225 100644 --- a/attic/archiver.py +++ b/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 diff --git a/attic/repository.py b/attic/repository.py index bc7b62a68..05105da61 100644 --- a/attic/repository.py +++ b/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()