Commit d373ca10 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

handle date type

parent 409f873f
...@@ -15,71 +15,10 @@ ...@@ -15,71 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import types
import os import os
import inspect import inspect
from ConfigParser import ConfigParser, NoOptionError from ConfigParser import ConfigParser, NoOptionError
from jflow.parameter import Parameter
class WorkflowConfigReader(object):
"""
"""
def __init__(self, path):
"""
"""
self.reader = ConfigParser()
self.reader.read(path)
def get_name(self):
return self.reader.get("global", "name")
def get_description(self):
return self.reader.get("global", "description")
def get_parameters(self):
"""
"""
parameters = []
try:
params = {}
# First grab all parameters name
for param in self.reader.items("parameters"):
cvalue = self.reader.get("parameters", param[0])
cparam = param[0].split(".")[0]
ckey = param[0].split(".")[1]
if not params.has_key(cparam):
params[cparam] = {ckey: cvalue}
else:
params[cparam][ckey] = cvalue
# Then build params
for param in params:
name = params[param]["name"]
flag = params[param]["flag"]
help = params[param]["help"]
try: default = params[param]["default"]
except: default = None
try:
type = eval(params[param]["type"])
metavar = params[param]["type"]
except:
type = types.StringType
metavar = "str"
try: required = params[param]["required"].lower() in ("yes", "y", "true", "t", "1")
except: required = False
try: action = params[param]["action"]
except: action = "store"
try: choices = params[param]["choices"].split("|")
except: choices = None
oparam = Parameter(name=name, flag=flag, help=help, default=default,
type=type, required=required, metavar=metavar,
action=action, choices=choices)
parameters.append(oparam)
except:
pass
return parameters
class JFlowConfigReader(object): class JFlowConfigReader(object):
......
...@@ -24,12 +24,15 @@ import tempfile ...@@ -24,12 +24,15 @@ import tempfile
import pickle import pickle
import time import time
import threading import threading
import datetime
from ConfigParser import ConfigParser, NoOptionError
import types
import jflow.components import jflow.components
import jflow.utils as utils import jflow.utils as utils
from jflow.config_reader import WorkflowConfigReader
from jflow.parameter import Parameter from jflow.parameter import Parameter
from jflow.workflows_manager import WorkflowsManager, JFlowConfigReader from jflow.workflows_manager import WorkflowsManager, JFlowConfigReader
from jflow.parameter import Parameter
from weaver.script import ABSTRACTIONS from weaver.script import ABSTRACTIONS
from weaver.script import DATASETS from weaver.script import DATASETS
...@@ -42,6 +45,11 @@ from weaver.options import Options ...@@ -42,6 +45,11 @@ from weaver.options import Options
from cctools.makeflow import MakeflowLog from cctools.makeflow import MakeflowLog
from cctools.makeflow.log import Node from cctools.makeflow.log import Node
def date(datestr):
try: return datetime.datetime.strptime(datestr, '%d-%m-%Y')
except: return datetime.datetime.strptime(datestr, '%d/%m/%Y')
class Workflow(threading.Thread): class Workflow(threading.Thread):
""" """
""" """
...@@ -60,7 +68,6 @@ class Workflow(threading.Thread): ...@@ -60,7 +68,6 @@ class Workflow(threading.Thread):
""" """
# define as a thread # define as a thread
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.config_reader = WorkflowConfigReader(self._get_property_path())
self.jflow_config_reader = JFlowConfigReader() self.jflow_config_reader = JFlowConfigReader()
self.manager = WorkflowsManager() self.manager = WorkflowsManager()
self.components = [] self.components = []
...@@ -81,14 +88,11 @@ class Workflow(threading.Thread): ...@@ -81,14 +88,11 @@ class Workflow(threading.Thread):
if type: self.engine_arguments += ' -T ' + type if type: self.engine_arguments += ' -T ' + type
if options : self.engine_arguments += ' -B "' + options + '"' if options : self.engine_arguments += ' -B "' + options + '"'
except: self.engine_arguments = None except: self.engine_arguments = None
try: #try:
# Add name and description values # Add config information
self.name = self.config_reader.get_name() self.name, self.description, self.parameters = self._get_from_config()
self.description = self.config_reader.get_description() #except:
# Add parameter values # raise IOError(self.__class__.__name__ + " workflow property file not found or invalid.")
self.parameters = self.config_reader.get_parameters()
except:
raise IOError(self.__class__.__name__ + " workflow property file not found or invalid.")
self.id = id self.id = id
if self.id is not None: if self.id is not None:
self.directory = self.manager.get_workflow_directory(self.name, self.id) self.directory = self.manager.get_workflow_directory(self.name, self.id)
...@@ -186,6 +190,55 @@ class Workflow(threading.Thread): ...@@ -186,6 +190,55 @@ class Workflow(threading.Thread):
self.end_time = time.time() self.end_time = time.time()
self._serialize() self._serialize()
def _get_from_config(self):
reader = ConfigParser()
reader.read(self._get_property_path())
parameters = []
#try:
params = {}
# First grab all parameters name
for param in reader.items("parameters"):
cvalue = reader.get("parameters", param[0])
cparam = param[0].split(".")[0]
ckey = param[0].split(".")[1]
if not params.has_key(cparam):
params[cparam] = {ckey: cvalue}
else:
params[cparam][ckey] = cvalue
# Then build params
for param in params:
name = params[param]["name"]
flag = params[param]["flag"]
help = params[param]["help"]
try: default = params[param]["default"]
except: default = None
# handle type values
try:
if params[param]["type"] == "date":
type = date
metavar = "datetime"
else:
type = eval(params[param]["type"])
metavar = params[param]["type"]
except:
type = types.StringType
metavar = "str"
try: required = params[param]["required"].lower() in ("yes", "y", "true", "t", "1")
except: required = False
try: action = params[param]["action"]
except: action = "store"
try: choices = params[param]["choices"].split("|")
except: choices = None
oparam = Parameter(name=name, flag=flag, help=help, default=default,
type=type, required=required, metavar=metavar,
action=action, choices=choices)
parameters.append(oparam)
#except:
# pass
return [reader.get("global", "name"),
reader.get("global", "description"),
parameters]
def _update_status_from_log(self): def _update_status_from_log(self):
# first update the status from weaver folders # first update the status from weaver folders
# TODO update self.end_time # TODO update self.end_time
......
...@@ -26,7 +26,7 @@ description = align reads against a reference genome ...@@ -26,7 +26,7 @@ description = align reads against a reference genome
# .flag: the command line flag to use the argument # .flag: the command line flag to use the argument
# .help: a brief description of what the parameter does # .help: a brief description of what the parameter does
# .default [None]: the value produced if the parameter is not provided # .default [None]: the value produced if the parameter is not provided
# .type [str]: the parameter type that should be tested (str|int|file|long|bool|...) # .type [str]: the parameter type that should be tested (str|int|date|file|long|bool|...)
# .choices [None]: a container of the allowable values for the parameter # .choices [None]: a container of the allowable values for the parameter
# .required [False]: whether or not the command-line option may be omitted # .required [False]: whether or not the command-line option may be omitted
# .action [store]: the basic type of action to be taken when this argument is encountered at the command line. # .action [store]: the basic type of action to be taken when this argument is encountered at the command line.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment