Added Workflow.get_data_file_name() which returns the full path to a given
data file, or None if the file does not exist. This is tested in the test workflow.
This commit is contained in:
parent
934640ea62
commit
89636962a7
|
@ -63,6 +63,19 @@ class Workflow:
|
||||||
self.stages_by_id = {}
|
self.stages_by_id = {}
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
|
def get_data_file_name(self, filename):
|
||||||
|
"""Checks if a file with the given name exists in the data directory.
|
||||||
|
Returns the file name if the file exists in the data directory, which
|
||||||
|
is defined as datadir/workflowname. If the file does not exist, or the
|
||||||
|
workflow does not have an identificator, this method returns None."""
|
||||||
|
print os.path.join(self.app.options.datadir, self.ident, filename)
|
||||||
|
if self.ident == None:
|
||||||
|
return None
|
||||||
|
fn = os.path.join(self.app.options.datadir, self.ident, filename)
|
||||||
|
if os.path.isfile(fn):
|
||||||
|
return fn
|
||||||
|
return None
|
||||||
|
|
||||||
def add_stage(self, stage):
|
def add_stage(self, stage):
|
||||||
self.stages.append(stage)
|
self.stages.append(stage)
|
||||||
self.stages_by_id[stage.id] = stage
|
self.stages_by_id[stage.id] = stage
|
||||||
|
|
|
@ -17,6 +17,7 @@ class TestWorkflow (workflow.Workflow):
|
||||||
|
|
||||||
load = workflow.Stage('load', 'Load Data')
|
load = workflow.Stage('load', 'Load Data')
|
||||||
load.add_function(CelFileImportFunction())
|
load.add_function(CelFileImportFunction())
|
||||||
|
load.add_function(DataLoadTestFunction(self))
|
||||||
load.add_function(TestDataFunction())
|
load.add_function(TestDataFunction())
|
||||||
load.add_function(DatasetLoadFunction())
|
load.add_function(DatasetLoadFunction())
|
||||||
load.add_function(SelectFunction())
|
load.add_function(SelectFunction())
|
||||||
|
@ -257,6 +258,22 @@ class CelFileImportFunction(workflow.Function):
|
||||||
chooser.destroy()
|
chooser.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
class DataLoadTestFunction(workflow.Function):
|
||||||
|
def __init__(self, wf):
|
||||||
|
workflow.Function.__init__(self, 'datadirload', 'Load from datadir')
|
||||||
|
self._wf = wf
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
print self._wf.get_data_file_name('smoker-x.ftsv')
|
||||||
|
fn = self._wf.get_data_file_name('smoker-x.ftsv')
|
||||||
|
if fn:
|
||||||
|
fd = open(fn)
|
||||||
|
ds = dataset.read_ftsv(fd)
|
||||||
|
return [ds]
|
||||||
|
else:
|
||||||
|
print "Cannot find file %s" % fn
|
||||||
|
return []
|
||||||
|
|
||||||
class PCAFunction(workflow.Function):
|
class PCAFunction(workflow.Function):
|
||||||
"""Generic PCA function."""
|
"""Generic PCA function."""
|
||||||
def __init__(self, wf):
|
def __init__(self, wf):
|
||||||
|
|
Reference in New Issue