Created
November 10, 2016 16:05
-
-
Save SimplyAhmazing/0156d3c8315c3ec2df661942bba08597 to your computer and use it in GitHub Desktop.
get latest n builds from ot-app-builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import boto | |
import boto.s3.connection | |
access_key = os.environ.get('AWS_ACCESS_KEY_ID') | |
secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY') | |
conn = boto.connect_s3( | |
aws_access_key_id = access_key, | |
aws_secret_access_key = secret_key, | |
) | |
bucket = conn.get_bucket('ot-app-builds') | |
def get_builds_by_prefix(prefix): | |
return sorted(bucket.list(prefix=prefix), key=lambda k: k.last_modified) | |
def get_latest_builds(prefix, lim=10): | |
all_builds = get_builds_by_prefix(prefix) | |
# keep builds that end with zip, exe or deb ignore dmgs, nupks, etc... | |
can_keep = lambda x: any([x.name.endswith(i) for i in ('.zip', '.exe', '.deb')]) | |
clean_list = filter(can_keep, all_builds) | |
# return last n builds in reverse order | |
return list(clean_list)[-lim:][::-1] | |
def print_latest(): | |
prefixes = ['mac', 'win', 'linux'] | |
url_tmpl = "https://s3.amazonaws.com/ot-app-builds/{name}" | |
for prefix in prefixes: | |
print('-' * 30, '{} BUILDS'.format(prefix.upper()), '-' * 30) | |
for i, key in enumerate(get_latest_builds(prefix)): | |
print('Build #{}'.format(i + 1)) | |
print(url_tmpl.format(name=key.name)) | |
print('-' * 80) | |
print('\n') | |
if __name__ == '__main__': | |
print_latest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment