mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Convert some logging calls to exception raises
This commit is contained in:
parent
798bcf384c
commit
233e8524ab
1 changed files with 21 additions and 13 deletions
|
|
@ -32,6 +32,10 @@ cli_logger = log.get(__name__)
|
||||||
PROJECT_HOME = 'https://github.com/untitaker/vdirsyncer'
|
PROJECT_HOME = 'https://github.com/untitaker/vdirsyncer'
|
||||||
|
|
||||||
|
|
||||||
|
class CliError(RuntimeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_status_name(pair, collection):
|
def get_status_name(pair, collection):
|
||||||
if collection is None:
|
if collection is None:
|
||||||
return pair
|
return pair
|
||||||
|
|
@ -69,14 +73,14 @@ def load_config(fname, pair_options=('collections', 'conflict_resolution')):
|
||||||
elif section == 'general':
|
elif section == 'general':
|
||||||
general = get_options(section)
|
general = get_options(section)
|
||||||
else:
|
else:
|
||||||
cli_logger.error(
|
cli_logger.error('Unknown section in {}: {}'
|
||||||
'Unknown section in {}: {}'.format(fname, section))
|
.format(fname, section))
|
||||||
|
|
||||||
if general is None:
|
if general is None:
|
||||||
cli_logger.error('Unable to find general section. You should copy the '
|
raise CliError(
|
||||||
'example config from the repository and edit it.')
|
'Unable to find general section. You should copy the example '
|
||||||
cli_logger.error(PROJECT_HOME)
|
'config from the repository and edit it.\n{}'.format(PROJECT_HOME)
|
||||||
sys.exit(1)
|
)
|
||||||
|
|
||||||
return general, pairs, storages
|
return general, pairs, storages
|
||||||
|
|
||||||
|
|
@ -94,7 +98,7 @@ def save_status(path, status_name, status):
|
||||||
base_path = os.path.dirname(full_path)
|
base_path = os.path.dirname(full_path)
|
||||||
|
|
||||||
if os.path.isfile(base_path):
|
if os.path.isfile(base_path):
|
||||||
raise RuntimeError('{} is probably a legacy file and could be removed '
|
raise CliError('{} is probably a legacy file and could be removed '
|
||||||
'automatically, but this choice is left to the '
|
'automatically, but this choice is left to the '
|
||||||
'user. If you think this is an error, please file '
|
'user. If you think this is an error, please file '
|
||||||
'a bug at {}'.format(base_path, PROJECT_HOME))
|
'a bug at {}'.format(base_path, PROJECT_HOME))
|
||||||
|
|
@ -279,7 +283,12 @@ def _main(env, file_cfg):
|
||||||
p.map_async(_sync_collection, actions).get(10**9)
|
p.map_async(_sync_collection, actions).get(10**9)
|
||||||
|
|
||||||
app.register_command('sync', sync_command)
|
app.register_command('sync', sync_command)
|
||||||
|
|
||||||
|
try:
|
||||||
app()
|
app()
|
||||||
|
except CliError as e:
|
||||||
|
cli_logger.critical(str(e))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def _sync_collection(x):
|
def _sync_collection(x):
|
||||||
|
|
@ -306,12 +315,11 @@ def sync_collection(config_a, config_b, pair_name, collection, pair_options,
|
||||||
except exceptions.StorageEmpty as e:
|
except exceptions.StorageEmpty as e:
|
||||||
side = 'a' if e.empty_storage is a else 'b'
|
side = 'a' if e.empty_storage is a else 'b'
|
||||||
storage = e.empty_storage
|
storage = e.empty_storage
|
||||||
cli_logger.critical(
|
raise CliError(
|
||||||
'{collection_description}: Storage "{side}" ({storage}) was '
|
'{collection_description}: Storage "{side}" ({storage}) was '
|
||||||
'completely emptied. Use "--force-delete {status_name}" to '
|
'completely emptied. Use "--force-delete {status_name}" to '
|
||||||
'synchronize that emptyness to the other side, or delete the '
|
'synchronize that emptyness to the other side, or delete the '
|
||||||
'status by yourself to restore the items from the non-empty '
|
'status by yourself to restore the items from the non-empty '
|
||||||
'side.'.format(**locals())
|
'side.'.format(**locals())
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
|
||||||
save_status(general['status_path'], status_name, status)
|
save_status(general['status_path'], status_name, status)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue