Skip to content

Commit

Permalink
Merge pull request #36 from genxnetwork/fix_validate_files
Browse files Browse the repository at this point in the history
Fixed validate files for cases with concatenating public keys
  • Loading branch information
alex-medvedev-msc authored Dec 6, 2021
2 parents bb321fb + d0cf9aa commit 66ad710
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions validate_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def wrapper(*args, **kwargs):
try:
result = func(*args, **kwargs)
return result
except Exception:
except Exception as e:
pass
return wrapper
return dec
Expand All @@ -41,15 +41,25 @@ def get_http_filesize(url):
url = urlunparse(url_parsed)

file = urlopen(Request(url, method='HEAD'))
return file.headers.get('Content-Length')
return int(file.headers.get('Content-Length'))


def get_filesize(data):
url = data['url']
def get_url(url, access_keys):
if url.startswith('https://dataset1000genomes.blob.core.windows.net'):
return url + access_keys['1000g_public_key']
if url.startswith('https://bioinformatics.file.core.windows.net'):
return url + access_keys['azure_public_key']
return url


def get_filesize(data, access_keys):
if 'expand_rule' in data:
url = data['url']
key = data['expand_rule']['key']
values = data['expand_rule']['values']
return [get_filesize({'url': url.replace(key, str(val))}) for val in values]
return [get_filesize({'url': url.replace(key, str(val))}, access_keys) for val in values]
else:
url = get_url(data['url'], access_keys)

if urlparse(url).scheme == 'ftp':
return get_ftp_filesize(url)
Expand All @@ -59,12 +69,12 @@ def get_filesize(data):
def main(yaml_url):
with open(yaml_url, 'r') as file:
content = yaml.safe_load(file)

access_keys = {k: content.get(k) for k in ('azure_public_key', '1000g_public_key')}
errors = {}
for k, v in content['reference'].items():
if 'url' not in v or 'filesize' not in v:
continue
filesize = get_filesize(v)
filesize = get_filesize(v, access_keys)
if str(filesize) != str(v['filesize']):
errors[k] = f'Expected {v["filesize"]}, got {filesize}'

Expand Down

0 comments on commit 66ad710

Please sign in to comment.