def add_download(self, project, env_spec_name, env_var, url, filename=None, hash_algorithm=None, hash_value=None): """Attempt to download the URL; if successful, add it as a download to the project. The returned ``Status`` should be a ``RequirementStatus`` for the download requirement if it evaluates to True (on success), but may be another subtype of ``Status`` on failure. A False status will have an ``errors`` property with a list of error strings. Args: project (Project): the project env_spec_name (str): environment spec name or None for all environment specs env_var (str): env var to store the local filename url (str): url to download filename (optional, str): Name to give file or directory after downloading hash_algorithm (optional, str): Name of the algorithm to use for checksum verification must be present if hash_value is entered hash_value (optional, str): Checksum value to use for verification must be present if hash_algorithm is entered Returns: ``Status`` instance """ return project_ops.add_download( project=project, env_spec_name=env_spec_name, env_var=env_var, url=url, filename=filename, hash_algorithm=hash_algorithm, hash_value=hash_value)
def add_download(project_dir, filename_variable, download_url, filename, hash_algorithm, hash_value): """Add an item to the downloads section.""" project = load_project(project_dir) if (hash_algorithm or hash_value) and not bool(hash_algorithm and hash_value): print("Error: mutually dependant parameters: --hash-algorithm and --hash-value.", file=sys.stderr) return 1 status = project_ops.add_download(project, env_var=filename_variable, url=download_url, filename=filename, hash_algorithm=hash_algorithm, hash_value=hash_value) if status: print(status.status_description) print("Added %s to the project file." % download_url) return 0 else: console_utils.print_status_errors(status) return 1