def build_partial_mar(to_mar_url, to_mar_hash, from_mar_url, from_mar_hash, identifier, channel_id, product_version): """ Function that returns the partial MAR file to transition from the mar given by from_mar_url to to_mar_url """ log.debug('Creating temporary working directories') TMP_MAR_STORAGE = tempfile.mkdtemp(prefix='mar_') TMP_WORKING_DIR = tempfile.mkdtemp(prefix='wd_') log.debug('MAR storage: %s', TMP_MAR_STORAGE) log.debug('Working dir storage: %s', TMP_WORKING_DIR) to_mar = os.path.join(TMP_MAR_STORAGE, 'new.mar') from_mar = os.path.join(TMP_MAR_STORAGE, 'old.mar') log.info('Looking up the complete MARs required') get_complete_mar(to_mar_url, to_mar_hash, to_mar) get_complete_mar(from_mar_url, from_mar_hash, from_mar) log.info('Creating cache connections') try: partial_file = generate_partial_mar( to_mar, from_mar, channel_id, product_version, working_dir=TMP_WORKING_DIR) log.debug('Partial MAR generated at %s', partial_file) except: cache.delete('partial', identifier) raise log.info('Saving partial MAR %s to cache with key %s', partial_file, identifier) cache.save(partial_file, 'partial', identifier, isfilename=True)
def save_patch(): """ Function to cache a patch in funsize """ required_params = ('sha_from', 'sha_to') if not all(p in flask.request.form.keys() for p in required_params): log.info('Parameters could not be validated') flask.abort(400) files = flask.request.files if 'patch_file' not in files.keys(): log.debug('Parameters passed could not be found on disk') flask.abort(400) storage = files.get('patch_file') form = flask.request.form sha_from, sha_to = form['sha_from'], form['sha_to'] identifier = _get_identifier(sha_from, sha_to) log.debug('Saving patch file to cache with key %s', identifier) cache.save(storage.stream, 'patch', identifier) url = flask.url_for('get_patch', sha_from=sha_from, sha_to=sha_to) return flask.Response( json.dumps({"result": url}), status=200, mimetype='application/json')
def build_partial_mar(to_mar_url, to_mar_hash, from_mar_url, from_mar_hash, identifier, channel_id, product_version): """ Function that returns the partial MAR file to transition from the mar given by from_mar_url to to_mar_url """ log.debug('Creating temporary working directories') TMP_MAR_STORAGE = tempfile.mkdtemp(prefix='mar_') TMP_WORKING_DIR = tempfile.mkdtemp(prefix='wd_') log.debug('MAR storage: %s', TMP_MAR_STORAGE) log.debug('Working dir storage: %s', TMP_WORKING_DIR) to_mar = os.path.join(TMP_MAR_STORAGE, 'new.mar') from_mar = os.path.join(TMP_MAR_STORAGE, 'old.mar') log.info('Looking up the complete MARs required') get_complete_mar(to_mar_url, to_mar_hash, to_mar) get_complete_mar(from_mar_url, from_mar_hash, from_mar) log.info('Creating cache connections') try: partial_file = generate_partial_mar(to_mar, from_mar, channel_id, product_version, working_dir=TMP_WORKING_DIR) log.debug('Partial MAR generated at %s', partial_file) except: cache.delete('partial', identifier) raise log.info('Saving partial MAR %s to cache with key %s', partial_file, identifier) cache.save(partial_file, 'partial', identifier, isfilename=True)
def get_complete_mar(url, mar_hash, output_file): """ Return binary string if no output_file specified """ log.info('Downloading complete MAR %s with mar_hash %s', url, mar_hash) if url.startswith('http://') or url.startswith('https://'): fetch.download_mar(url, mar_hash, output_file) cache.save(output_file, 'complete', mar_hash, isfilename=True) else: cache.retrieve_to_file('complete', mar_hash, output_file=output_file) log.info('Satisfied request for complete MAR %s with mar_hash %s', url, mar_hash)
def save_patch(): """ Function to cache a patch in funsize """ required_params = ('sha_from', 'sha_to') if not all(p in flask.request.form.keys() for p in required_params): log.info('Parameters could not be validated') flask.abort(400) files = flask.request.files if 'patch_file' not in files.keys(): log.debug('Parameters passed could not be found on disk') flask.abort(400) storage = files.get('patch_file') form = flask.request.form sha_from, sha_to = form['sha_from'], form['sha_to'] identifier = _get_identifier(sha_from, sha_to) log.debug('Saving patch file to cache with key %s', identifier) cache.save(storage.stream, 'patch', identifier) url = flask.url_for('get_patch', sha_from=sha_from, sha_to=sha_to) return flask.Response(json.dumps({"result": url}), status=200, mimetype='application/json')