From fe074715e14ae91fca85e5b4df36a3a3c65b3ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 10 May 2016 18:18:09 +0200 Subject: [PATCH] Simplified files_make_public_t management command. 'except Exception: pass' is always bad. --- pillar/manage.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/pillar/manage.py b/pillar/manage.py index d6090343..96f77b8c 100755 --- a/pillar/manage.py +++ b/pillar/manage.py @@ -687,26 +687,27 @@ def files_make_public_t(): from gcloud.exceptions import InternalServerError from application.utils.gcs import GoogleCloudStorageBucket files_collection = app.data.driver.db['files'] + for f in files_collection.find({'backend': 'gcs'}): - if 'variations' in f: - variation_t = next((item for item in f['variations'] \ - if item['size'] == 't'), None) - if variation_t: - try: - storage = GoogleCloudStorageBucket(str(f['project'])) - blob = storage.Get(variation_t['file_path'], to_dict=False) - if blob: - try: - print("Making blob public: {0}".format(blob.path)) - blob.make_public() - except InternalServerError: - print("Internal Server Error") - except Exception: - pass - except InternalServerError: - print("Internal Server Error") - except Exception: - pass + if 'variations' not in f: + continue + + variation_t = next((item for item in f['variations'] + if item['size'] == 't'), None) + if not variation_t: + continue + + try: + storage = GoogleCloudStorageBucket(str(f['project'])) + blob = storage.Get(variation_t['file_path'], to_dict=False) + if not blob: + print('Unable to find blob for project %s file %s', f['project'], f['_id']) + continue + + print('Making blob public: {0}'.format(blob.path)) + blob.make_public() + except InternalServerError as ex: + print('Internal Server Error: ', ex) @manager.command