Exemplo n.º 1
0
 def open(cls):
     """deserialize settings"""    
     directory = os.path.join(BASE_DIR, cls.DIR)
     config = base_cfg.get_config_file(cls.FILE_NAME, directory, cls=WorkspacesConf)
     if config is None:
         config =  WorkspacesConf()
     return config
Exemplo n.º 2
0
 def open():
     """Open config from saved file (if exists)."""
     config = base_cfg.get_config_file(_Config.SERIAL_FILE,
                                       _Config.CONFIG_DIR,
                                       cls=_Config)
     if config is None:
         config = _Config()
     return config
Exemplo n.º 3
0
 def open(cls, id=None):
     directory = os.path.join(BASE_DIR, cls.DIR)
     fn = cls.FILE_NAME
     if id is not None:
         fn += "_" + str(id)
     config = cfg.get_config_file(fn, directory, cls=cls)
     if config is None:
         config = cls()
     return config
Exemplo n.º 4
0
def test_config_save_and_load():
    #config dir exist
    assert os.path.isdir(config.__config_dir__)
    data = DataForTest()
    data.inner.a = 6
    data.name = "test1"
    config.save_config_file("test_data", data)
    data.inner.a = 7
    data.name = "test2"
    data = config.get_config_file("test_data", cls=DataForTest)
    assert data.inner.a == 6
    assert data.name == "test1"
    data.inner.a = 7
    data.name = "test2"
    config.save_config_file("test_data", data)
    data = config.get_config_file("test_data", cls=DataForTest)
    assert data.inner.a == 7
    assert data.name == "test2"
    config.delete_config_file("test_data")
    data = config.get_config_file("test_data")
    assert data == None
    config.delete_config_file("test_data")
Exemplo n.º 5
0
    def open_from_mj(mj_dir, analysis_name='N/A'):
        """Retrieve analysis from multijob directory."""
        analysis = config.get_config_file(ANALYSIS_MAIN_FILE_NAME,
                                          directory=os.path.join(
                                              mj_dir, MJ_CONFIG_DIR),
                                          extension=ANALYSIS_MAIN_FILE_EXT,
                                          cls=Analysis)
        if analysis is None:
            raise InvalidAnalysis("Selected analysis is invalid.")

        analysis.analysis_dir = mj_dir
        analysis.filename = os.path.join(mj_dir, ANALYSIS_MAIN_FILE)
        analysis.workspace = None
        analysis.name = analysis_name

        return analysis
Exemplo n.º 6
0
    def open(workspace, analysis_name, sync_files=False):
        """Retrieve analysis from settings by its name and workspace."""
        if analysis_name is None:
            raise InvalidAnalysis("No analysis specified.")
        if workspace is None:
            raise InvalidAnalysis("No workspace specified.")
        directory = os.path.join(workspace, analysis_name)
        analysis = config.get_config_file(ANALYSIS_MAIN_FILE_NAME,
                                          directory=directory,
                                          extension=ANALYSIS_MAIN_FILE_EXT,
                                          cls=Analysis)
        if analysis is None:
            raise InvalidAnalysis("Selected analysis is invalid.")

        analysis.analysis_dir = directory
        analysis.filename = os.path.join(directory, ANALYSIS_MAIN_FILE)
        analysis.workspace = workspace
        analysis.name = analysis_name

        # scan and update files
        if sync_files:
            analysis.sync_files()

        return analysis
Exemplo n.º 7
0
 def open():
     directory = os.path.join(BASE_DIR, ConfigData.DIR)
     config = cfg.get_config_file(ConfigData.FILE_NAME, directory, cls=ConfigData)
     if config is None:
         config = ConfigData()
     return config