Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
args = parse_args(sys.argv[1:])
downloader = Downloader(max_conn=args.max_conn, file_progress=not args.no_file_progress, overwrite=args.overwrite)
for url in args.urls:
downloader.enqueue_file(url, path=args.directory)
results = downloader.download()
for i in results:
print(i)
err_str = ''
for err in results.errors:
err_str += f'{err.url} \t {err.exception}\n'
if err_str:
sys.exit(err_str)
def getenvironment(self):
try:
from parfive import Downloader
except ImportError:
log.error("To use gammapy download, install the parfive package!")
return
dl = Downloader(progress=False, file_progress=False)
filename_env = "gammapy-" + self.release + "-environment.yml"
url_file_env = RELEASES_BASE_URL + "/install/" + filename_env
filepath_env = str(self.outfolder / filename_env)
dl.enqueue_file(url_file_env, path=filepath_env)
try:
log.info(f"Downloading {url_file_env}")
Path(filepath_env).parent.mkdir(parents=True, exist_ok=True)
dl.download()
except Exception as ex:
log.error(ex)
exit()
def run(self):
try:
from parfive import Downloader
except ImportError:
log.error("To use gammapy download, install the parfive package!")
return
if self.listfiles:
log.info(f"Content will be downloaded in {self.outfolder}")
dl = Downloader(progress=self.progress, file_progress=False)
for rec in self.listfiles:
url = self.listfiles[rec]["url"]
path = self.outfolder / self.listfiles[rec]["path"]
md5 = ""
if "hashmd5" in self.listfiles[rec]:
md5 = self.listfiles[rec]["hashmd5"]
retrieve = True
if md5 and path.exists():
md5local = hashlib.md5(path.read_bytes()).hexdigest()
if md5local == md5:
retrieve = False
if retrieve:
dl.enqueue_file(url, path=str(path.parent))
log.info(f"{dl.queued_downloads} files to download.")
res = dl.download()