def load(self, dirname): """ Loads the project from the given directory. The existing state of the project is completely modified. """ # TODO: We should formalize this dependency at some point and move # this import to the top level from configobj import ConfigObj if dirname == "": raise IOError("Cannot load project from empty path.") elif not os.path.isdir(dirname): raise IOError("Cannot find directory: " + dirname) filename = abspath(join(dirname, self.PROJECT_FILE_NAME)) if not os.path.isfile(filename): raise IOError('Cannot load %s from project directory "%s".' % \ (self.PROJECT_FILE_NAME, dirname)) # Every project is saved as a text ConfigObj file that describes # the name and location of the real data files. configspec = ConfigObj(self.CONFIG_SPEC, list_values=False) config = ConfigObj(filename, configspec=configspec) contexts = [] for context_config in config["Contexts"].values(): ctx = DataContext.load(join(dirname, context_config["file"])) ctx.name = context_config["name"] contexts.append(ctx) self.contexts = contexts experiments = [] if hasattr(scripting, "app"): app = scripting.app else: app = None for exp_config in config["Experiments"].values(): experiment = Experiment() exp_dir = join(dirname, exp_config["save_dir"]) experiment.load_from_config(exp_config, exp_dir, project=self) experiments.append(experiment) self.experiments = experiments proj_config = config["Project"] if proj_config.has_key("active_experiment"): self.active_experiment = self.find_experiment(proj_config["active_experiment"]) # Update Project Save Path self.project_save_path = dirname return
def load_from_config(self, config, dirname, project=None): """ Loads the experiment. The existing state of the experiment is completely modified. Parameters ---------- config: a dict-like object The keys should correspond to the configspec for experiments as defined in project_config_spec. dirname: a string the absolute path to the subdirectory of the project that holds the experiment's saved data project: Project instance If provided, the project is used to hook up references to the shared context. """ join = os.path.join self.name = config.get("name", "") if "code_file" in config: # Clear out the old references self.canvas = self.controller = self.exec_model = None self.exec_model = ExecutionModel.from_file(join(dirname, config["code_file"])) self.controller = BlockGraphController(execution_model = self.exec_model) self.canvas = BlockCanvas(graph_controller=self.controller) self.controller.canvas = self.canvas if "layout_file" in config: self.canvas.load_layout(join(dirname, config["layout_file"])) if "local_context" in config: self._local_context = DataContext.load(join(dirname, config["local_context"])) shared_context = None if project is not None: name = config.get("shared_context") if name != "": shared_context = project.find_context(name) self._shared_context = shared_context self._update_exec_context()