diff -r 6b7f4c6745a0 -r 47b0b08fbb4b cubicweb/server/serverctl.py --- a/cubicweb/server/serverctl.py Wed Jun 22 15:57:17 2016 +0200 +++ b/cubicweb/server/serverctl.py Wed Jun 22 11:38:53 2016 +0200 @@ -969,21 +969,25 @@ class SynchronizeSourceCommand(Command): - """Force a source synchronization. + """Force sources synchronization. the identifier of the instance - the name of the source to synchronize. + names of the sources to synchronize, if empty all sources will be synced. """ name = 'source-sync' - arguments = ' ' - min_args = max_args = 2 + arguments = ' [ ...]' + min_args = 1 options = ( ('loglevel', {'short': 'l', 'type': 'choice', 'metavar': '', 'default': 'info', 'choices': ('debug', 'info', 'warning', 'error')}, ), + ('force', + {'short': 'f', 'action': 'store_true', 'default': False, + 'help': 'force source synchronization (ignore synchronization interval)'}, + ), ) def run(self, args): @@ -995,25 +999,38 @@ init_cmdline_log_threshold(config, self['loglevel']) repo = repoapi.get_repository(config=config) repo.hm.call_hooks('server_maintenance', repo=repo) - status = 0 - try: - try: - source = repo.sources_by_uri[args[1]] - except KeyError: - raise ExecutionError('no source named %r' % args[1]) - with repo.internal_cnx() as cnx: + errors = False + with repo.internal_cnx() as cnx: + sources = [] + if len(args) >= 2: + for name in args[1:]: + try: + source = repo.sources_by_uri[name] + except KeyError: + cnx.error('no source named %r' % name) + errors = True + else: + sources.append(source) + else: + for uri, source in list(repo.sources_by_uri.items()): + if (uri != 'system' and + repo.config.source_enabled(source) and + source.config['synchronize']): + sources.append(source) + + for source in sources: try: - stats = source.pull_data(cnx, force=True, raise_on_error=True) - except SourceException as exc: - print("can't synchronize the source:", exc) - status = 1 - stats = {} - finally: - repo.shutdown() - for key, val in stats.items(): - if val: - print(key, ':', val) - sys.exit(status) + stats = source.pull_data(cnx, force=self['force'], raise_on_error=True) + except Exception: + cnx.exception('while trying to update source %s', source) + errors = True + else: + for key, val in stats.items(): + if val: + print(key, ':', val) + + if errors: + raise ExecutionError('All sources where not synced') def permissionshandler(relation, perms):