diff --git a/fluents/workflow.py b/fluents/workflow.py index 16b6654..c876e57 100644 --- a/fluents/workflow.py +++ b/fluents/workflow.py @@ -63,6 +63,19 @@ class Workflow: self.stages_by_id = {} 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): self.stages.append(stage) self.stages_by_id[stage.id] = stage diff --git a/workflows/test_workflow.py b/workflows/test_workflow.py index f7bead8..d085ba0 100644 --- a/workflows/test_workflow.py +++ b/workflows/test_workflow.py @@ -17,6 +17,7 @@ class TestWorkflow (workflow.Workflow): load = workflow.Stage('load', 'Load Data') load.add_function(CelFileImportFunction()) + load.add_function(DataLoadTestFunction(self)) load.add_function(TestDataFunction()) load.add_function(DatasetLoadFunction()) load.add_function(SelectFunction()) @@ -257,6 +258,22 @@ class CelFileImportFunction(workflow.Function): 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): """Generic PCA function.""" def __init__(self, wf):