aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Copeland <ben.copeland@linaro.org>2017-01-09 12:00:06 +0000
committerBen Copeland <ben.copeland@linaro.org>2017-01-11 09:49:09 +0000
commit5c9407fbda4c2e5fffe07c50b2720f1898df4db2 (patch)
treeb7cf40d4a23e061290aa4f7972c13df2045c25ce
parentc7e6b4253ffef89cd34823a76c682b4edbe74395 (diff)
downloadlinaro-license-protection-5c9407fbda4c2e5fffe07c50b2720f1898df4db2.tar.gz
S3 Purge: accept wildcard exclude
Using fnmatch we can use Unix style regex, to exclude filenames/folders Change-Id: I837beb433d0f5aae287b1639bacbdc3913e30aa5 Reviewed-on: https://review.linaro.org/16654 Reviewed-by: Andy Doan <andy.doan@linaro.org>
-rw-r--r--license_protected_downloads/management/commands/s3_purge.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/license_protected_downloads/management/commands/s3_purge.py b/license_protected_downloads/management/commands/s3_purge.py
index d12810e..d8f754a 100644
--- a/license_protected_downloads/management/commands/s3_purge.py
+++ b/license_protected_downloads/management/commands/s3_purge.py
@@ -3,6 +3,7 @@ from django.core.management.base import BaseCommand
import logging
import datetime
+import fnmatch
from boto.s3.connection import S3Connection
logging.getLogger().setLevel(logging.INFO)
@@ -30,12 +31,12 @@ class Command(BaseCommand):
settings.AWS_SECRET_ACCESS_KEY)
bucket = conn.get_bucket(settings.S3_BUCKET, validate=False)
bucket_key = bucket.list(options['prefix'])
-
now = self.x_days_ago(int(options['days']))
for key in bucket_key:
- if not any(map(key.name.startswith, settings.S3_PURGE_EXCLUDES)):
- if key.last_modified < now:
+ if key.last_modified < now:
+ if not any(fnmatch.fnmatch(key.name, p) for p in
+ settings.S3_PURGE_EXCLUDES):
if options['dryrun']:
logging.info('Will delete %s', key.name)
else:
@@ -44,4 +45,4 @@ class Command(BaseCommand):
bucket.delete_key(key)
except Exception:
logging.exception('S3Connection error for %s',
- key.name)
+ key.name)