def get_schema(schema_version): hit = next(get_resolver().ifcb.adc.schema(schema_version),None) def text2schema(): for col,typ in zip(re.split(' ',hit['columns']),re.split(' ',hit['types'])): if typ in _TYPE_CONV: yield col,_TYPE_CONV[typ] else: yield col,str return list(text2schema())
def parsed_pid2fileset(parsed_pid,roots): paths = {} for root in roots: try: p = next(get_resolver().ifcb.files.find_raw_fileset(root=root,**parsed_pid)) paths.update(p) if paths: return paths except StopIteration: pass # try the next one # we tried all roots and it's not there raise NotFound('No raw data found for %s' % parsed_pid['bin_lid'])
def get_product_file(parsed, product_type): parsed = dict(parsed.items()) time_series = parsed['ts_label'] data_roots = list(get_data_roots(time_series,product_type)) parsed['product'] = product_type for root in data_roots: try: hit = next(get_resolver().ifcb.files.find_product(root=root,**parsed)) return hit['product_path'] except StopIteration: pass raise NotFound
def get_product_destination(session, pid, product_type=None): parsed = parse_pid(pid) if product_type is None: product_type = parsed[PRODUCT] ts_label = parsed[TS_LABEL] if product_type=='multiblob': # sidecar files for features product_type='features' roots = get_data_roots(session, ts_label, product_type=product_type) if not roots: raise NotFound('no product destination found') root = roots[0] S = next(get_resolver().ifcb.files.product_path(root=root,**parsed)) return S[FILE_PATH]
def accession_demo(session,ts_label,root): # now accede for fs in get_resolver().ifcb.files.list_raw_filesets(root): lid = fs['lid'] try: parsed = parse_pid(lid) except: print 'barf %s' % lid raise ts = text2utcdatetime(parsed['timestamp'], parsed['timestamp_format']) b = Bin(ts_label=ts_label, lid=lid, sample_time=ts) session.add(b) # now make mostly bogus fixity entries now = datetime.now() paths = [fs['hdr_path'], fs['adc_path'], fs['roi_path']] filetypes = ['hdr','adc','roi'] for path,filetype in zip(paths,filetypes): length = os.stat(path).st_size name = os.path.basename(path) #checksum = sha1_file(path) checksum = 'placeholder' f = File(local_path=path, filename=name, length=length, filetype=filetype, sha1=checksum, fix_time=now) b.files.append(f) session.commit()
def list_filesets(root): return get_resolver().ifcb.files.list_raw_filesets(root)
def as_product(pid,product): """compute a product pid given a pid and a product name""" return next(get_resolver().ifcb.as_product(pid=pid,product=product))[PID]
def parse_pid(pid): """use the IFCB resolver to parse a pid""" try: return next(get_resolver().ifcb.pid(pid)) except StopIteration: raise
def ifcb(): return get_resolver().ifcb