comparison snp-cache.py @ 41:9022b00a9198

planemo upload commit 0399c6bd696435a7a99d8d8b4c237e5a78ee5856-dirty
author jpayne
date Thu, 01 Mar 2018 15:37:04 -0500
parents 6adaecff5f2b
children 11296a86e01b
comparison
equal deleted inserted replaced
40:02733e77f84f 41:9022b00a9198
93 93
94 94
95 def main(table, id, command=None, output=None, *a, **k): 95 def main(table, id, command=None, output=None, *a, **k):
96 id = id.strip() 96 id = id.strip()
97 table = table.strip() 97 table = table.strip()
98 name = f"{table}/{id}" 98 name = "{table}/{id}".format(**locals())
99 with open(output, 'wb') as output_f: 99 with open(output, 'wb') as output_f:
100 #lookup ID in table and get a FH to the resource 100 #lookup ID in table and get a FH to the resource
101 try: 101 try:
102 api_key = os.environ.get('AWS_API_KEY', '') 102 api_key = os.environ.get('AWS_API_KEY', '')
103 s3 = boto3.resource('s3').Bucket(CACHE_NAMESPACE) 103 s3 = boto3.resource('s3').Bucket(CACHE_NAMESPACE)
104 s3.download_fileobj(name, output_f) 104 s3.download_fileobj(name, output_f)
105 logging.getLogger('snp-cache.cache').info(f"cache hit on {name}, retrieved.") 105 logging.getLogger('snp-cache.cache').info("cache hit on {name}, retrieved.".format(**locals()))
106 except (DataNotFoundError, NoCredentialsError, BotoCoreError, ClientError) as e: 106 except (DataNotFoundError, NoCredentialsError, BotoCoreError, ClientError) as e:
107 if type(e) is DataNotFoundError: 107 if type(e) is DataNotFoundError:
108 logging.getLogger('snp-cache.cache').info(f"cache miss on {name}") 108 logging.getLogger('snp-cache.cache').info("cache miss on {name}".format(**locals()))
109 else: 109 else:
110 logging.getLogger('snp-cache.cache').error(e) 110 logging.getLogger('snp-cache.cache').error(e)
111 #if we couldn't find the data, we need to run the command to generate it 111 #if we couldn't find the data, we need to run the command to generate it
112 if not command: 112 if not command:
113 raise NoCacheNoCommandException("No cached result for this id, and no command given to generate.") 113 raise NoCacheNoCommandException("No cached result for this id, and no command given to generate.")