archiver: rename print_x methods so they correspond to log levels

also:

remove some "Warning: " msg prefixes - if we emit at WARNING level,
it is obviously a warning.

remove some "borg: " msg prefixes.
This commit is contained in:
Thomas Waldmann 2015-10-25 02:35:42 +02:00
parent d8d3c8521b
commit 7b73abdcda
1 changed files with 25 additions and 21 deletions

View File

@ -51,17 +51,21 @@ class Archiver:
def print_error(self, msg, *args): def print_error(self, msg, *args):
msg = args and msg % args or msg msg = args and msg % args or msg
self.exit_code = EXIT_WARNING # we do not terminate here, so it is a warning self.exit_code = EXIT_ERROR
logger.error('borg: ' + msg) logger.error(msg)
def print_verbose(self, msg, *args): def print_warning(self, msg, *args):
msg = args and msg % args or msg
self.exit_code = EXIT_WARNING # we do not terminate here, so it is a warning
logger.warning(msg)
def print_info(self, msg, *args):
if self.verbose: if self.verbose:
msg = args and msg % args or msg msg = args and msg % args or msg
logger.info(msg) logger.info(msg)
def print_status(self, status, path): def print_status(self, status, path):
if self.verbose: self.print_info("%1s %s", status, remove_surrogates(path))
logger.info("%1s %s", status, remove_surrogates(path))
def do_serve(self, args): def do_serve(self, args):
"""Start in server mode. This command is usually not used manually. """Start in server mode. This command is usually not used manually.
@ -85,7 +89,7 @@ class Archiver:
repository = self.open_repository(args.repository, exclusive=args.repair) repository = self.open_repository(args.repository, exclusive=args.repair)
if args.repair: if args.repair:
while not os.environ.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'): while not os.environ.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'):
self.print_error("""Warning: 'check --repair' is an experimental feature that might result self.print_warning("""'check --repair' is an experimental feature that might result
in data loss. in data loss.
Type "Yes I am sure" if you understand this and want to continue.\n""") Type "Yes I am sure" if you understand this and want to continue.\n""")
@ -147,7 +151,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
try: try:
status = archive.process_stdin(path, cache) status = archive.process_stdin(path, cache)
except IOError as e: except IOError as e:
self.print_error('%s: %s', path, e) self.print_warning('%s: %s', path, e)
else: else:
status = '-' status = '-'
self.print_status(status, path) self.print_status(status, path)
@ -157,7 +161,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
try: try:
restrict_dev = os.lstat(path).st_dev restrict_dev = os.lstat(path).st_dev
except OSError as e: except OSError as e:
self.print_error('%s: %s', path, e) self.print_warning('%s: %s', path, e)
continue continue
else: else:
restrict_dev = None restrict_dev = None
@ -184,7 +188,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
try: try:
st = os.lstat(path) st = os.lstat(path)
except OSError as e: except OSError as e:
self.print_error('%s: %s', path, e) self.print_warning('%s: %s', path, e)
return return
if (st.st_ino, st.st_dev) in skip_inodes: if (st.st_ino, st.st_dev) in skip_inodes:
return return
@ -201,7 +205,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
try: try:
status = archive.process_file(path, st, cache) status = archive.process_file(path, st, cache)
except IOError as e: except IOError as e:
self.print_error('%s: %s', path, e) self.print_warning('%s: %s', path, e)
elif stat.S_ISDIR(st.st_mode): elif stat.S_ISDIR(st.st_mode):
if exclude_caches and is_cachedir(path): if exclude_caches and is_cachedir(path):
return return
@ -210,7 +214,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
try: try:
entries = os.listdir(path) entries = os.listdir(path)
except OSError as e: except OSError as e:
self.print_error('%s: %s', path, e) self.print_warning('%s: %s', path, e)
else: else:
for filename in sorted(entries): for filename in sorted(entries):
entry_path = os.path.normpath(os.path.join(path, filename)) entry_path = os.path.normpath(os.path.join(path, filename))
@ -230,7 +234,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
# Ignore unix sockets # Ignore unix sockets
return return
else: else:
self.print_error('Unknown file type: %s', path) self.print_warning('Unknown file type: %s', path)
return return
# Status output # Status output
# A lowercase character means a file type other than a regular file, # A lowercase character means a file type other than a regular file,
@ -273,7 +277,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
if not args.dry_run: if not args.dry_run:
while dirs and not item[b'path'].startswith(dirs[-1][b'path']): while dirs and not item[b'path'].startswith(dirs[-1][b'path']):
archive.extract_item(dirs.pop(-1), stdout=stdout) archive.extract_item(dirs.pop(-1), stdout=stdout)
self.print_verbose(remove_surrogates(orig_path)) self.print_info(remove_surrogates(orig_path))
try: try:
if dry_run: if dry_run:
archive.extract_item(item, dry_run=True) archive.extract_item(item, dry_run=True)
@ -284,14 +288,14 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
else: else:
archive.extract_item(item, stdout=stdout, sparse=sparse) archive.extract_item(item, stdout=stdout, sparse=sparse)
except IOError as e: except IOError as e:
self.print_error('%s: %s', remove_surrogates(orig_path), e) self.print_warning('%s: %s', remove_surrogates(orig_path), e)
if not args.dry_run: if not args.dry_run:
while dirs: while dirs:
archive.extract_item(dirs.pop(-1)) archive.extract_item(dirs.pop(-1))
for pattern in (patterns or []): for pattern in (patterns or []):
if isinstance(pattern, IncludePattern) and pattern.match_count == 0: if isinstance(pattern, IncludePattern) and pattern.match_count == 0:
self.print_error("Warning: Include pattern '%s' never matched.", pattern) self.print_warning("Include pattern '%s' never matched.", pattern)
return self.exit_code return self.exit_code
def do_rename(self, args): def do_rename(self, args):
@ -343,7 +347,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
try: try:
from .fuse import FuseOperations from .fuse import FuseOperations
except ImportError as e: except ImportError as e:
self.print_error('loading fuse support failed [ImportError: %s]' % str(e)) self.print_error('Loading fuse support failed [ImportError: %s]' % str(e))
return self.exit_code return self.exit_code
if not os.path.isdir(args.mountpoint) or not os.access(args.mountpoint, os.R_OK | os.W_OK | os.X_OK): if not os.path.isdir(args.mountpoint) or not os.access(args.mountpoint, os.R_OK | os.W_OK | os.X_OK):
@ -357,7 +361,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
else: else:
archive = None archive = None
operations = FuseOperations(key, repository, manifest, archive) operations = FuseOperations(key, repository, manifest, archive)
self.print_verbose("Mounting filesystem") self.print_info("Mounting filesystem")
try: try:
operations.mount(args.mountpoint, args.options, args.foreground) operations.mount(args.mountpoint, args.options, args.foreground)
except RuntimeError: except RuntimeError:
@ -435,7 +439,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
if args.hourly + args.daily + args.weekly + args.monthly + args.yearly == 0 and args.within is None: if args.hourly + args.daily + args.weekly + args.monthly + args.yearly == 0 and args.within is None:
self.print_error('At least one of the "within", "keep-hourly", "keep-daily", "keep-weekly", ' self.print_error('At least one of the "within", "keep-hourly", "keep-daily", "keep-weekly", '
'"keep-monthly" or "keep-yearly" settings must be specified') '"keep-monthly" or "keep-yearly" settings must be specified')
return EXIT_ERROR return self.exit_code
if args.prefix: if args.prefix:
archives = [archive for archive in archives if archive.name.startswith(args.prefix)] archives = [archive for archive in archives if archive.name.startswith(args.prefix)]
keep = [] keep = []
@ -456,12 +460,12 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
to_delete = [a for a in archives if a not in keep] to_delete = [a for a in archives if a not in keep]
stats = Statistics() stats = Statistics()
for archive in keep: for archive in keep:
self.print_verbose('Keeping archive: %s' % format_archive(archive)) self.print_info('Keeping archive: %s' % format_archive(archive))
for archive in to_delete: for archive in to_delete:
if args.dry_run: if args.dry_run:
self.print_verbose('Would prune: %s' % format_archive(archive)) self.print_info('Would prune: %s' % format_archive(archive))
else: else:
self.print_verbose('Pruning archive: %s' % format_archive(archive)) self.print_info('Pruning archive: %s' % format_archive(archive))
Archive(repository, key, manifest, archive.name, cache).delete(stats) Archive(repository, key, manifest, archive.name, cache).delete(stats)
if to_delete and not args.dry_run: if to_delete and not args.dry_run:
manifest.write() manifest.write()