From 4be05c8b5753365f6021e2cb3be2fa7695ecae6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 13 Sep 2017 10:20:52 +0200 Subject: [PATCH] Orphan finder: when iterating all projects, gracefully stop at CTRL+C --- pillar/cli/maintenance.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pillar/cli/maintenance.py b/pillar/cli/maintenance.py index ee953d1c..b0f3f943 100644 --- a/pillar/cli/maintenance.py +++ b/pillar/cli/maintenance.py @@ -605,9 +605,13 @@ def find_orphan_files(proj_url): if proj_url == 'all': log.warning('Iterating over ALL projects, may take a while') orphans = set() - for project in projects_coll.find({'_deleted': {'$ne': True}}, projection={'_id': 1}): - proj_orphans = _find_orphan_files(project['_id']) - orphans.update(proj_orphans) + try: + for project in projects_coll.find({'_deleted': {'$ne': True}}, projection={'_id': 1}): + proj_orphans = _find_orphan_files(project['_id']) + orphans.update(proj_orphans) + except KeyboardInterrupt: + log.warning('Keyboard interrupt received, stopping now ' + 'and showing intermediary results.') else: project = projects_coll.find_one({'url': proj_url}, projection={'_id': 1}) if not project: