result = [_load_data(f) for f in files] # not bundles print "Result: ", result return dict(output=result) def _load_data(name): print name friendly_name = File.objects.get(name=name.split('/')[-1]).friendly_name if os.path.splitext(friendly_name)[1] == ".DIV": return read_div(myfilestr=name) else: return read_sample(myfilestr=name) load = load_module(id='sans.load', datatype=SANS_DATA, version='1.0', action=load_action) # Save module def save_action(input=[], ext='', **kwargs): for f in input: _save_one(f, ext) # not bundles return {} def _save_one(input, ext): outname = initname = map_files('save') if ext is not None: outname = ".".join([os.path.splitext(outname)[0], ext]) print "saving", initname, 'as', outname
# operate on a bundle rather than individual input # because the multiple field is True for bundle in input: flat.extend(bundle) result = [_data_randomize(f, max_change) for f in flat] return dict(output=result) rand = random_module(id='rowan.random', datatype=ROWAN_DATA, version='1.0', action=random_action) # ======== Other modules ========== def load_action(files=None, intent=None): """Loads files for data manipulation""" print "loading", files result = [load_data(f) for f in files] return dict(output=result) load = load_module(id='rowan.load', datatype=ROWAN_DATA, version='1.0', action=load_action) def save_action(input=None, ext=None): """Saves files to another extension""" for f in input: _save_one(f, ext) return {} def _save_one(input, ext): outname = input['name'] if ext is not None: outname = ".".join([os.path.splitext(outname)[0], ext]) print "saving", input['name'], 'as', outname save_data(input, name=outname) # the 'ext'ension field; there's no use in saving fields though (hopefully there will be a need later?) save_ext = { "type":"[string]", "label": "Save extension",
plot='sansplot') # Load module def load_action(files=None, intent=None): print "loading", files result = [_load_data(f) for f in files] # not bundles return dict(output=result) def _load_data(name): print name if os.path.splitext(name)[1] == ".DIV": return read_div(myfilestr=name) else: return read_sample(myfilestr=name) load = load_module(id='sans.load', datatype=SANS_DATA, version='1.0', action=load_action) # Save module def save_action(input=None, ext=None): for f in input: _save_one(f, ext) # not bundles return {} def _save_one(input, ext): outname = initname = "/home/elakian/.txt" if ext is not None: outname = ".".join([os.path.splitext(outname)[0], ext]) print "saving", initname, 'as', outname with open(outname, 'w') as f: f.write(str(input.__str__())) save = save_module(id='sans.save', datatype=SANS_DATA, version='1.0', action=save_action)
datatype=ROWAN_DATA, version='1.0', action=random_action) # ======== Other modules ========== def load_action(files=None, intent=None): """Loads files for data manipulation""" print "loading", files result = [load_data(f) for f in files] return dict(output=result) load = load_module(id='rowan.load', datatype=ROWAN_DATA, version='1.0', action=load_action) def save_action(input=None, ext=None): """Saves files to another extension""" for f in input: _save_one(f, ext) return {} def _save_one(input, ext): outname = input['name'] if ext is not None: outname = ".".join([os.path.splitext(outname)[0], ext]) print "saving", input['name'], 'as', outname