def get_context(self): """ Finalize the context """ self.context = None if os.path.splitext(self.filename)[1] == '.pickle': self.context = DataContext.load_context_from_file(self.filename) elif self.model: if isinstance(self.model, FileLogReaderUI): reader = self.model.active_reader if reader: log_info = reader.read_info(self.filename) self.context = create_geo_context( reader.read_data(self.filename, log_info), log_info.well_name) else: self.context = self.model.read_data() return
def load_project_from_file(self, file_path): """ Load a project from .prj files. Parameters: ----------- file_path: Str Complete file-path where the project is saved. """ logger.debug('BlockUnit: Loading project from %s' %file_path) del self.block_unit self.block_unit = BlockUnit() if not os.path.exists(file_path): msg = 'BlockUnit: Loading of project at ' + \ file_path + ' failed: Path does not exist.' logger.error(msg) return self.project_file_path = file_path # Read the .prj file and retrieve information about where the script # and context are separately saved. file_object = open(file_path, 'rb') lines = file_object.readlines() lines_split = [line.split('=') for line in lines] lines_dict = {} for line in lines_split: key = line[0].strip().lower() if key != '': lines_dict[key] = line[1].strip() file_object.close() # Read the code and build the block s_path = 'script_path' if lines_dict.has_key(s_path) and os.path.exists(lines_dict[s_path]): self.load_block_from_file(lines_dict[s_path]) else: msg = 'BlockUnit: Loading of script for project at ' + \ file_path + ' failed.' logger.error(msg) # Read the context file context, c_path = None, 'context_path' if lines_dict.has_key(c_path) and os.path.exists(lines_dict[c_path]): context = DataContext.load_context_from_file(lines_dict[c_path]) # Read the layout file l_path = 'layout_path' if lines_dict.has_key(l_path) and os.path.exists(lines_dict[l_path]): self.block_unit.codeblock_ui.block_controller.layout_engine.load_layout(lines_dict[l_path]) # Assign the context if any if context is not None: self.block_unit.data_context = context else: msg = 'BlockUnit: Loading of context for project at ' + \ file_path + ' failed.' logger.error(msg) # Interactor range files for key in INTERACTOR_LIST: if lines_dict.has_key(key): self.interactor_range_files[key] = lines_dict[key] # Loading saved contexts self.exec_context.saved_contexts = {} saved_context_keys = [key for key in lines_dict.keys() if key.startswith(saved_context_prefix) ] if len(saved_context_keys): for key in saved_context_keys: final_key = key.replace(saved_context_prefix,'') self.exec_context.saved_contexts[final_key] = lines_dict[key] return