Exemplo n.º 1
0
    def parse_and_save_meta_config(cls, input_file='inputfile.txt', 
            output_folder='Config', update_rules=False, debug=False):
        """ Parse an input file containing a meta-configuration, generate the differnt 
        configs, and save them as files.

        Parameters
        ----------
            input_file: str
                where the file containing the meta configuration is
            output_folder: str, none
                In which folder to store the configs
            update_rules: bool
                rules to apply when generating the configs
            debug: bool
                debug mode
        """
        list_configs = cls.parse_meta_config(input_file, update_rules, debug=debug)
        for conf in list_configs:
            name_conf = 'config_' + conf['_RES_NAME']
            if(not(output_folder is None)):
                pathlib.Path(output_folder).mkdir(parents=True, exist_ok=True) 
                name_conf = os.path.join(output_folder, name_conf)
            ut.dico_to_text_rep(conf, fileName = name_conf, typeWrite = 'w')
Exemplo n.º 2
0
    def write_one_res(cls, res, name_res = None, folder = None):
        """ Write a res as a text file. 

        Arguments:
            + res - a dictionnary
            + folder - in which folder to write the results
            + forceName - Force the name given to the file (if None look for 
                         a key name in the results, if none use default name)
        """
        #Create name of the file
        if(name_res is None):
            if("_RES_NAME" in res):
                name = res['_RES_NAME']
            else:
                name = cls._DEF_RES_NAME
        else:
            name = name_res

        if(not(folder is None)):
            pathlib.Path(folder).mkdir(parents=True, exist_ok=True) 
            name = os.path.join(folder, name)     
        
        #Write
        ut.dico_to_text_rep(res, fileName = name, typeWrite = 'w')