<commit_before>import boto
from boto.exception import  S3ResponseError
from boto.s3.lifecycle import Lifecycle,Expiration
def delete(bucket_name):
    if bucket_name == 'ndp-from-data-to-gpu-bioc-test0':
        return True
s3 = boto.connect_s3()
del_all_pattern = '%s-lc-delete-all'
for b in s3.get_all_buckets():
    if delete( b.name ):
        print b.name
        try:
            config = b.get_lifecycle_config()
            for r in config:
                if r.id == del_all_pattern % b.name:
                    if len(b.get_all_keys()) > 0:
                        print "Want to delete %s but not empty" % b.name
                        print "Try again tomorrow"
                    else:
                        b.delete()
        except S3ResponseError as sre:
            if sre.error_code == 'NoSuchLifecycleConfiguration':
                print "Setting deletion lifecycle rule"
                lf = Lifecycle()
                lf.add_rule( id=del_all_pattern % b.name, expiration=Expiration(days=1),
                        prefix='', status='Enabled',transition=None  )
                b.configure_lifecycle(lf)
<commit_msg>Interesting pattern for bucket deletion.<commit_after>import boto
from boto.exception import  S3ResponseError
from boto.s3.lifecycle import Lifecycle,Expiration
deletable = ['ndp-from-gpu-to-agg-bioc-test0', 'diraclog-dev']
def delete(bucket_name):
    if bucket_name in deletable:
        return True
    prefix = 'an-from-data-to-gpu-'
    if bucket_name[:len(prefix)] == prefix:
        return True
    return False
s3 = boto.connect_s3()
del_all_pattern = '%s-lc-delete-all'
for b in s3.get_all_buckets():
    if delete( b.name ):
        print b.name
        try:
            config = b.get_lifecycle_config()
            for r in config:
                if r.id == del_all_pattern % b.name:
                    if len(b.get_all_keys()) > 0:
                        print "Want to delete %s but not empty" % b.name
                        print "Try again tomorrow"
                    else:
                        b.delete()
        except S3ResponseError as sre:
            if sre.error_code == 'NoSuchLifecycleConfiguration':
                print "Setting deletion lifecycle rule"
                lf = Lifecycle()
                lf.add_rule( id=del_all_pattern % b.name, expiration=Expiration(days=3),
                        prefix='', status='Enabled',transition=None  )
                b.configure_lifecycle(lf)

{'fraction_non_alphanumeric': 0.09550789154188588, 'fraction_numerical': 0.007284500202347228, 'mean_word_length': 1.831615120274914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7116170', 'n_tokens_mistral': 753, 'n_tokens_neox': 707, 'n_words': 177}