def fetch_app_source(url, ref, request_id): """ Fetch the application source code that was requested and put it in long-term storage. :param str url: the source control URL to pull the source from :param str ref: the source control reference :param int request_id: the Cachito request ID this is for """ log.info('Fetching the source from "%s" at reference "%s"', url, ref) set_request_state(request_id, 'in_progress', 'Fetching the application source') try: # Default to Git for now scm = Git(url, ref) scm.fetch_source() except requests.Timeout: raise CachitoError( 'The connection timed out while downloading the source') except CachitoError: log.exception( 'Failed to fetch the source from the URL "%s" and reference "%s"', url, ref) raise # Extract the archive contents to the temporary directory of where the bundle is being created. # This will eventually end up in the bundle the user downloads. This is extracted now since # some package managers may add dependency replacements, which require edits to source files. request_bundle_dir = get_request_bundle_dir(request_id) if not os.path.exists(request_bundle_dir): log.debug('Creating %s', request_bundle_dir) os.makedirs(request_bundle_dir, exist_ok=True) log.debug('Extracting %s to %s', scm.archive_path, request_bundle_dir) extract_app_src(scm.archive_path, request_bundle_dir)
def fetch_app_source(url, ref, request_id, gitsubmodule=False): """ Fetch the application source code that was requested and put it in long-term storage. :param str url: the source control URL to pull the source from :param str ref: the source control reference :param int request_id: the Cachito request ID this is for :param bool gitsubmodule: a bool to determine whether git submodules need to be processed. """ log.info('Fetching the source from "%s" at reference "%s"', url, ref) set_request_state(request_id, "in_progress", "Fetching the application source") try: # Default to Git for now scm = Git(url, ref) scm.fetch_source(gitsubmodule=gitsubmodule) except requests.Timeout: raise CachitoError( "The connection timed out while downloading the source") except CachitoError: log.exception( 'Failed to fetch the source from the URL "%s" and reference "%s"', url, ref) raise # Extract the archive contents to the temporary directory of where the bundle is being created. # This will eventually end up in the bundle the user downloads. This is extracted now since # some package managers may add dependency replacements, which require edits to source files. bundle_dir = RequestBundleDir(request_id) log.debug("Extracting %s to %s", scm.sources_dir.archive_path, bundle_dir) shutil.unpack_archive(str(scm.sources_dir.archive_path), str(bundle_dir)) _enforce_sandbox(bundle_dir.source_root_dir)
def fetch_app_source(url, ref, request_id_to_update=None): """ Fetch the application source code that was requested and put it in long-term storage. :param str url: the source control URL to pull the source from :param str ref: the source control reference :param int request_id_to_update: the Cachito request ID this is for; if specified, this will update the request's state """ log.info('Fetching the source from "%s" at reference "%s"', url, ref) if request_id_to_update: set_request_state(request_id_to_update, 'in_progress', 'Fetching the application source') try: # Default to Git for now scm = Git(url, ref) scm.fetch_source() except requests.Timeout: raise CachitoError( 'The connection timed out while downloading the source') except CachitoError: log.exception( 'Failed to fetch the source from the URL "%s" and reference "%s"', url, ref) raise return scm.archive_path