def _makeitso_(): assert (self.annotations is not None) and (len(self.annotations) > 0) stage = m.add_sample_stage( sample.obfuscated_id, self.method.obfuscated_id, ';'.join(map(str, self.annotations)), m.get_sample_stages(sample.obfuscated_id)[1]) for datafile in self.datafiles: m.add_file(os.path.relpath(datafile.path, config.UPLOAD_PATH), stage.obfuscated_id) return stage
def _makeitso_(): assert (self.annotations is not None) and (len(self.annotations) > 0) stage = m.add_sample_stage( sample.obfuscated_id, self.method.obfuscated_id, ';'.join(map(str, self.annotations)), m.get_sample_stages(sample.obfuscated_id)[1]) for datafile in self.datafiles: m.add_file( os.path.relpath(datafile.path, config.UPLOAD_PATH), stage.obfuscated_id) return stage
def complete_file_upload(): request_data = json.loads(request.data) file_identifier = request_data['upload-id'] file_name = secure_filename(request_data['file-name']) project = request_data['project'] sample = request_data['sample'] sample_stage = as_id(request_data['sample-stage']) req_checksum_value = request_data['checksum-value'] req_checksum_method = request_data['checksum-method'] part_upload_dir = upload_dir(file_identifier) reconstituted_file_name = os.path.join(part_upload_dir, file_name) parts = sorted(glob.glob(os.path.join(part_upload_dir, '*.part'))) part_digester = checksum.get_digester(req_checksum_method) with open(reconstituted_file_name, 'w') as target: def consume_part(data): target.write(data) part_digester.update(data) for part_name in parts: file.FileProcessor(part_name, consume_part).process() computed_checksum_value = part_digester.hexdigest() if computed_checksum_value != req_checksum_value: raise checksum.ChecksumMismatch(reconstituted_file_name, req_checksum_method, req_checksum_value, computed_checksum_value) with open('.'.join([reconstituted_file_name, CHECKSUM_EXT]), 'w') as cf: json.dump({ 'method': req_checksum_method, 'value': req_checksum_value }, cf) logmsg = 'Successfully reconsitituted file: %s (%s=%s)' \ % (reconstituted_file_name, req_checksum_method, req_checksum_value) app.logger.info(logmsg) models.add_file( os.path.relpath(reconstituted_file_name, app.config['UPLOAD_PATH']), sample_stage) return (json.dumps({ 'identifier': file_identifier, 'file-name': file_name }), http.HTTP_202_ACCEPTED)
def test_add_file(storepath, sample_with_stages): ssf = models.add_file('source-file', sample_with_stages['stages'][0].obfuscated_id) assert 1 == ssf.id assert 'w4Kbn' == ssf.obfuscated_id assert models.FileStatus.staged == ssf.status assert models.FileStatus.staged.value == ssf._status assert sample_with_stages['stages'][0].id == ssf._sample_stage_id
def stage_file(storepath, sample_with_stages): parts_dir = ''.join([random.choice('0123456789ABCDEF') for i in range(3)]) ssf = models.add_file(os.path.join(parts_dir, 'uploaded-file'), sample_with_stages['stages'][0].obfuscated_id) src_fname = os.path.join(sagittariidae.app.app.config['UPLOAD_PATH'], ssf.relative_source_path) tgt_fname = os.path.join(sagittariidae.app.app.config['STORE_PATH'], ssf.relative_target_path) return {'model': ssf, 'source': src_fname, 'target': tgt_fname}
def stage_file(storepath, sample_with_stages): parts_dir = ''.join([random.choice('0123456789ABCDEF') for i in range(3)]) ssf = models.add_file( os.path.join(parts_dir, 'uploaded-file'), sample_with_stages['stages'][0].obfuscated_id) src_fname = os.path.join( sagittariidae.app.app.config['UPLOAD_PATH'], ssf.relative_source_path) tgt_fname = os.path.join( sagittariidae.app.app.config['STORE_PATH'], ssf.relative_target_path) return {'model' : ssf, 'source' : src_fname, 'target' : tgt_fname}
def test_complete_file(sample_with_stages): ssf = models.add_file('source-file', sample_with_stages['stages'][0].obfuscated_id) assert models.FileStatus.staged == ssf.status