Skip to content
Snippets Groups Projects
Commit 42698fe2 authored by Tim O'Donnell's avatar Tim O'Donnell
Browse files

fix

parent 035f56b1
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,8 @@ from collections import OrderedDict
from appdirs import user_data_dir
from pkg_resources import resource_string
import pandas
ENVIRONMENT_VARIABLES = [
"MHCFLURRY_DATA_DIR",
"MHCFLURRY_DOWNLOADS_CURRENT_RELEASE",
......@@ -130,15 +132,30 @@ def get_current_release_downloads():
metadata : dict
Info about the download from downloads.yml such as URL
up_to_date : bool or None
Whether the download URL(s) match what was used to download the current
data. This is None if it cannot be determined.
"""
downloads = (
get_downloads_metadata()
['releases']
[get_current_release()]
['downloads'])
def up_to_date(dir, urls):
try:
df = pandas.read_csv(join(dir, "DOWNLOAD_INFO.csv"))
return list(df.url) == list(urls)
except IOError:
return None
return OrderedDict(
(download["name"], {
'downloaded': exists(join(get_downloads_dir(), download["name"])),
'up_to_date': up_to_date(
join(get_downloads_dir(), download["name"]),
[download['url']] if 'url' in download else download['part_urls']),
'metadata': download,
}) for download in downloads
)
......
......@@ -36,6 +36,7 @@ from tqdm import tqdm
tqdm.monitor_interval = 0 # see https://github.com/tqdm/tqdm/issues/481
import posixpath
import pandas
try:
from urllib.request import urlretrieve
......@@ -262,6 +263,10 @@ def fetch_subcommand(args):
for member in tqdm(tar.getmembers(), desc='Extracting'):
tar.extractall(path=result_dir, members=[member])
tar.close()
# Save URLs that were used for this download.
pandas.DataFrame({"url": urls}).to_csv(
os.path.join(result_dir, "DOWNLOAD_INFO.csv"), index=False)
qprint("Extracted %d files to: %s" % (
len(names), quote(result_dir)))
finally:
......@@ -298,8 +303,8 @@ def info_subcommand(args):
downloads = get_current_release_downloads()
format_string = "%-40s %-12s %-20s "
print(format_string % ("DOWNLOAD NAME", "DOWNLOADED?", "URL"))
format_string = "%-40s %-12s %-12s %-20s "
print(format_string % ("DOWNLOAD NAME", "DOWNLOADED?", "UP TO DATE?", "URL"))
for (item, info) in downloads.items():
urls = (
......@@ -313,6 +318,10 @@ def info_subcommand(args):
print(format_string % (
item,
yes_no(info['downloaded']),
"" if not info['downloaded'] else (
"UNKNOWN" if info['up_to_date'] is None
else yes_no(info['up_to_date'])
),
url_description))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment