예제 #1
0
 def __init__(self,
              name,
              default_executable=None,
              default_repository=None,
              default_main_file=None,
              default_launch_mode=None,
              data_store='default',
              record_store='default',
              on_changed='error',
              description='',
              data_label=None,
              input_datastore=None,
              label_generator='timestamp',
              timestamp_format=TIMESTAMP_FORMAT,
              allow_command_line_parameters=True,
              plugins=[]):
     self.path = os.getcwd()
     if not os.path.exists(".smt"):
         os.mkdir(".smt")
     if os.path.exists(_get_project_file(self.path)):
         raise Exception(
             "Sumatra project already exists in this directory.")
     if re.match(Project.valid_name_pattern, name):
         self.name = name
     else:
         raise ValueError(
             "Invalid project name. Names may only contain letters, numbers, spaces and hyphens"
         )
     self.default_executable = default_executable
     self.default_repository = default_repository  # maybe we should be storing the working copy instead, as this has a ref to the repository anyway
     self.default_main_file = default_main_file
     self.default_launch_mode = default_launch_mode
     if data_store == 'default':
         data_store = datastore.FileSystemDataStore(None)
     self.data_store = data_store  # a data store object
     self.input_datastore = input_datastore or self.data_store
     if record_store == 'default':
         record_store = DefaultRecordStore(os.path.abspath(".smt/records"))
     self.record_store = record_store
     self.on_changed = on_changed
     self.description = description
     self.data_label = data_label
     self.label_generator = label_generator
     self.timestamp_format = timestamp_format
     self.sumatra_version = sumatra.__version__
     self.allow_command_line_parameters = allow_command_line_parameters
     self._most_recent = None
     self.plugins = []
     self.load_plugins(*plugins)
     self.save()
     print("Sumatra project successfully set up")
예제 #2
0
def build_record(data):
    """Create a Sumatra record from a nested dictionary."""
    edata = data["executable"]
    cls = get_registered_components(programs.Executable).get(edata["name"], programs.Executable)
    executable = cls(edata["path"], edata["version"], edata.get("options", ""))
    executable.name = edata["name"]
    rdata = data["repository"]
    repos_cls = None
    for m in versioncontrol.vcs_list:
        if hasattr(m, rdata["type"]):
            repos_cls = getattr(m, rdata["type"])
            break
    if repos_cls is None:
        repos_cls = versioncontrol.base.Repository
    repository = repos_cls(rdata["url"])
    repository.upstream = rdata.get("upstream", None)
    pdata = data["parameters"]
    if pdata["type"] == "dict":
        parameter_set = eval(pdata["content"])
        assert isinstance(parameter_set, dict)
    else:
        parameter_set = getattr(parameters, pdata["type"])(pdata["content"])
    ldata = data["launch_mode"]
    lm_parameters = ldata["parameters"]
    if isinstance(lm_parameters, str):  # prior to 0.3
        lm_parameters = eval(lm_parameters)
    launch_mode = getattr(launch, ldata["type"])(**keys2str(lm_parameters))

    def build_data_store(ddata):
        ds_parameters = ddata["parameters"]
        if isinstance(ds_parameters, str):  # prior to 0.3
            ds_parameters = eval(ds_parameters)
        return getattr(datastore, ddata["type"])(**keys2str(ds_parameters))
    data_store = build_data_store(data["datastore"])
    if "input_datastore" in data:  # 0.4 onwards
        input_datastore = build_data_store(data["input_datastore"])
    else:
        input_datastore = datastore.FileSystemDataStore("/")
    input_data = data.get("input_data", [])
    if isinstance(input_data, str):  # 0.3
        input_data = eval(input_data)
    if input_data:
        if isinstance(input_data[0], str):  # versions prior to 0.4
            input_data = [datastore.DataKey(path, digest=datastore.IGNORE_DIGEST, creation=None)
                          for path in input_data]
        else:
            input_data = [datastore.DataKey(keydata["path"], keydata["digest"],
                                            creation=datestring_to_datetime(keydata.get("creation", None)),
                                            **keys2str(keydata["metadata"]))
                          for keydata in input_data]
    record = Record(executable, repository, data["main_file"],
                    data["version"], launch_mode, data_store, parameter_set,
                    input_data, data.get("script_arguments", ""),
                    data["label"], data["reason"], data["diff"],
                    data.get("user", ""), input_datastore=input_datastore,
                    timestamp=datestring_to_datetime(data["timestamp"]))
    tags = data["tags"]
    if not hasattr(tags, "__iter__"):
        tags = (tags,)
    record.tags = set(tags)
    record.output_data = []
    if "output_data" in data:
        for keydata in data["output_data"]:
            data_key = datastore.DataKey(keydata["path"], keydata["digest"],
                                         creation=datestring_to_datetime(keydata.get("creation", None)),
                                         **keys2str(keydata["metadata"]))
            record.output_data.append(data_key)
    elif "data_key" in data:  # (versions prior to 0.4)
        for path in eval(data["data_key"]):
            data_key = datastore.DataKey(path, digest=datastore.IGNORE_DIGEST,
                                         creation=None)
            record.output_data.append(data_key)
    record.duration = data["duration"]
    record.outcome = data["outcome"]
    record.stdout_stderr = data.get("stdout_stderr", "")
    record.platforms = [launch.PlatformInformation(**keys2str(pldata)) for pldata in data["platforms"]]
    record.dependencies = []
    for depdata in data["dependencies"]:
        dep_args = [depdata["name"], depdata["path"], depdata["version"],
                    depdata["diff"]]
        if "source" in depdata:  # 0.5 onwards
            dep_args.append(depdata["source"])
        dep = getattr(dependency_finder, depdata["module"]).Dependency(*dep_args)
        record.dependencies.append(dep)
    record.repeats = data.get("repeats", None)
    return record