Esempio n. 1
0
    def __init__(self):
        """
        Initialize a new Config instance
        """
        self.dirs = AppDirs('MangaDL', 'Makoto')

        # Internal file and ConfigParser placeholders
        self._app_cfgfile = None
        self._app_config = ConfigParser(interpolation=ExtendedInterpolation())

        # Set the path information
        self.app_config_dir = self.dirs.user_config_dir
        self.app_config_file = "manga-dl.cfg"
        self.app_config_path = path.join(self.app_config_dir,
                                         self.app_config_file)
    def parse_configuration_file(self, modelFileName):
        config = ConfigParser(interpolation=ExtendedInterpolation())
        config.optionxform = str
        config.read(modelFileName)

        # sections in configuration file
        self.allSections = config.sections()

        # read all sections
        for section in self.allSections:
            vars(self)[section] = {}
            options = config.options(section)
            for option in options:
                val = config.get(section, option)
                self.__getattribute__(section)[option] = val
Esempio n. 3
0
def set_session(options, cookies, source):
    print_debug(options, cookies)
    config_file = options.get('config')
    config = ConfigParser(interpolation=ExtendedInterpolation())
    config.read(config_file)

    if 'fofa' in source:
        config.set('Cookies', 'fofa', cookies)
    if 'shodan' in source:
        config.set('Cookies', 'shodan', cookies)
    if 'censys' in source:
        config.set('Cookies', 'censys', cookies)

    with open(config_file, 'w') as configfile:
        config.write(configfile)
Esempio n. 4
0
def get_config_var(sec, var):
	try:
		path_config = get_app_dir()+"/haproxy-webintarface.config"
		config = ConfigParser(interpolation=ExtendedInterpolation())
		config.read(path_config)
	except:
		print('Content-type: text/html\n')
		print('<center><div class="alert alert-danger">Check the config file, whether it exists and the path. Must be: app/haproxy-webintarface.config</div>')

	try:
		var = config.get(sec, var)
		return var
	except:
		print('Content-type: text/html\n')
		print('<center><div class="alert alert-danger">Check the config file. Presence section %s and parameter %s</div>' % (sec, var))
Esempio n. 5
0
    def __init__(self,
                 defaults_file=os.path.join('config', 'defaults.cfg'),
                 config_file='',
                 **kwargs):
        """"""

        #super(Config, self).__init__(defaults=kwargs.pop('DEFAULT', {}))
        super(Config, self).__init__(interpolation=ExtendedInterpolation())
        self.read([defaults_file, config_file])
        for section, options in six.iteritems(kwargs):
            if section != 'DEFAULT' and not self.has_section(section):
                self.add_section(section)
            for option, value in six.iteritems(options):
                self.set(section, option, str(value))
        return
Esempio n. 6
0
    def load_config(filename):
        """Load the parameter configuration file.

        Parameters:
            filename (str): YSO configuration file name.
        """
        # Verify file
        name = os.path.realpath(os.path.expanduser(filename))
        assert os.path.isfile(name)

        # Load file
        parser = myConfigParser(interpolation=ExtendedInterpolation())
        parser.read(name)

        return parser
Esempio n. 7
0
def parse(cfile=None):
    """
    Instantiates parser for INI (config) file
    :param cfile: absolute filepath to config INI file
    :return: ConfigParser object with configurations loaded
    """
    if not cfile:
        dir_path = os.path.dirname(os.path.realpath(__file__))
        cfile = os.path.join(dir_path, "my_bb_configs.ini")

    print("Loading configs: " + cfile)
    parser = ConfigParser(interpolation=ExtendedInterpolation())
    parser.read(cfile)

    return parser
Esempio n. 8
0
 def read_position(self, typology, key, Locale):
     file = self.cfg['REFERENCIAL']['referencialposition'] + str(
         typology) + '.ini'
     res = {}
     if os.path.isfile(file):
         parser = ConfigParser(interpolation=ExtendedInterpolation())
         parser.read(file)
         for section in parser.sections():
             if section == key:
                 for info in parser[section]:
                     res[info] = parser[section][info]
     if res and res['regex']:
         localeList = Locale.get()
         res['regex'] = localeList[res['regex']]
     return res
Esempio n. 9
0
    def parseConfig(file):
        """
        Parses the config file.  The file must be of ini format.
        If the file exists but is empty and exception will be generated.

        :param file: The path of the file to parse
        :return: Return a config object
        """
        # make sure the file is not empty
        size = Path(file).stat().st_size
        if size != 0:
            config = ConfigParser(interpolation=ExtendedInterpolation())
            config.read(file.__str__())
            return config
        else:
            raise Exception('File is empty.')
Esempio n. 10
0
	def readTestbenchConfiguration(self):
		from configparser import ConfigParser, ExtendedInterpolation
	
		tbConfigFilePath = self.directories["PoCRoot"] / self.pocConfig['PoC.DirectoryNames']['TestbenchFiles'] / self.__tbConfigFileName
		self.files["PoCTBConfig"] = tbConfigFilePath
		
		self.printDebug("Reading testbench configuration from '%s'" % str(tbConfigFilePath))
		if not tbConfigFilePath.exists():	raise NotConfiguredException("PoC testbench configuration file does not exist. (%s)" % str(tbConfigFilePath))
			
		self.tbConfig = ConfigParser(interpolation=ExtendedInterpolation())
		self.tbConfig.optionxform = str
		self.tbConfig.read([
			str(self.files["PoCPrivateConfig"]),
			str(self.files["PoCPublicConfig"]),
			str(self.files["PoCTBConfig"])
		])
def get_config(path):
    """
    Return config variables
    :param path(String): path to config file
    :return configparser: user settings
    :return configparser: developer settings
    """

    config = configparser.ConfigParser(interpolation=ExtendedInterpolation())

    config.read(path)

    config_user = config['user_settings']
    config_dev = config['developer_settings']

    return config_user, config_dev
Esempio n. 12
0
    def __init__(self, config_file):
        InstallationComponent.__init__(self)
        ConfigParser.__init__(self,
                              interpolation=ExtendedInterpolation(),
                              allow_no_value=True)
        self.optionxform = str  # preserves case-sensitivity

        config_dir = os.path.dirname(config_file)
        credentials_file = os.path.join(config_dir, Config.CREDENTIALS_FILE)

        if not os.path.exists(credentials_file):
            self.raise_exception(
                f'The file with credentials: {credentials_file} '
                f"does not exist")

        self.read([credentials_file, config_file])
Esempio n. 13
0
def get_config_var(sec, var):
    from configparser import ConfigParser, ExtendedInterpolation
    try:
        path_config = "/opt/smon/smon.cfg"
        config = ConfigParser(interpolation=ExtendedInterpolation())
        config.read(path_config)
    except:
        logger.fatal(
            'Check the config file, whether it exists and the path. Must be: /opt/smon/smon.cfg'
        )
    try:
        return config.get(sec, var)
    except:
        logger.fatal(
            'Check the config file. Presence section %s and parameter %s' %
            (sec, var))
Esempio n. 14
0
def create_config(options):
    cfg = ConfigParser(interpolation=ExtendedInterpolation())
    conf_path = os.path.join(dataPath, 'dscan.conf')
    if options.config:
        conf_path = os.path.join(options.name, options.config)
    data = open(conf_path)
    cfg.read_file(data)
    data.close()
    config = Config(cfg, options)

    handler = logging.FileHandler(os.path.join(args.name, f"drecon-{now}.log"))
    handler.setFormatter(logging.Formatter(FORMAT))
    log = logging.getLogger()
    log.addHandler(handler)
    log.setLevel(logging.DEBUG)
    return config
Esempio n. 15
0
    def __init__(self, config_override_filename=None):
        """Load the configuration (usually config.ini)."""
        if config_override_filename and not os.path.isfile(
                config_override_filename):
            raise ValueError("Unable to find config file {}".format(
                config_override_filename))

        main_file = os.path.join(get_dir('codebase'), 'config.ini')

        self.config = ConfigParser(interpolation=ExtendedInterpolation())
        self.config.optionxform = str  # enforce case sensitivity on key

        if config_override_filename:  # custom config
            self.config.read([main_file, config_override_filename])
        else:  # no custom file
            self.config.read(main_file)
Esempio n. 16
0
    def _read(self, config_file=None):
        """
        Reads config_file and returns a configparser object of it

        :param config_file:
        :return config:
        """
        config_file = config_file if config_file is not None else self.config_file

        config = ConfigParser(interpolation=ExtendedInterpolation())
        config.read(config_file)

        if not config.sections():
            self._create()

        return config
Esempio n. 17
0
 def __init__(self, config_path):
     assert os.path.exists(config_path), '{} not exists.'.format(config_path)
     self.config = ConfigParser(
         delimiters='=',
         interpolation=ExtendedInterpolation())
     self.config.read(config_path)
     try:
         self.lambda1_stud = self.config.getfloat('stud', 'lambda1_stud')
     except:
         logger.warning('lambda1_stud not found in config file')
         self.lambda1_stud = 0
     try:
         self.lambda2_stud = self.config.getfloat('stud', 'lambda2_stud')
     except:
         logger.warning('lambda2_stud not found in config file')
         self.lambda2_stud = 0
Esempio n. 18
0
    def get_curr_feedback(self):
        uomid = self.utility.get_uomid_of_current_dir()
        if uomid == -1:
            print('Error: You have to be in a student directory')
        else:
            try:
                log_path = self.feedback_dir + '/' + self.FEEDBACK_LOG_NAME

                parser = ConfigParser(interpolation=ExtendedInterpolation())
                parser.read(log_path)

                for option in parser[uomid]:
                    print(option + ' : ' + parser.get(uomid, option))
            except:
                print('You currently have not assigned any feedback')
        pass
Esempio n. 19
0
    def __init__(self, filename, overrides=None):
        self._parser = ConfigParser(interpolation=ExtendedInterpolation(),
                                    allow_no_value=True)
        self.filename = filename
        self.sections = []

        with open(self.filename) as fhandle:
            data = expand_env_vars(fhandle.read().strip())

        # Read the defaults first
        self._parser.read_dict({'train': TRAIN_DEFAULTS})

        # Read the config
        self._parser.read_string(data)

        if overrides is not None:
            # ex: train.batch_size:32
            self.overrides = self.parse_overrides(overrides)

        for section in self._parser.sections():
            opts = {}
            self.sections.append(section)

            for key, value in self._parser[section].items():
                opts[key] = resolve_path(_parse_value(value))

            if section in self.overrides:
                for (key, value) in self.overrides[section].items():
                    opts[key] = value

            setattr(self, section, opts)

        # Sanity check for [train]
        train_keys = list(self.train.keys())
        def_keys = list(TRAIN_DEFAULTS.keys())
        assert len(train_keys) == len(set(train_keys)), \
            "Duplicate arguments found in config's [train] section."

        invalid_keys = set(train_keys).difference(set(TRAIN_DEFAULTS))
        for key in invalid_keys:
            match = get_close_matches(key, def_keys, n=1)
            msg = "{}:train: Unknown option '{}'.".format(self.filename, key)
            if match:
                msg += "  Did you mean '{}' ?".format(match[0])
            print(msg)
        if invalid_keys:
            sys.exit(1)
Esempio n. 20
0
def quoteWatchInit():
    print("in quoteWatchInit\r\n")
    #cfg = ConfigParser()
    cfg = ConfigParser(interpolation=ExtendedInterpolation())
    try:
        cfg.read('./config.ini')
        cfg.sections()

        #cfgSet.api_key = str(cfg.get('Unity','api_key'))
        #cfgSet.seceret_key = str(cfg.get('Unity','seceret_key'))
        #cfgSet.passphrase = str(cfg.get('Unity','passphrase'))
        #log.info(cfgSet.api_key+","+cfgSet.seceret_key+","+cfgSet.passphrase)
        cfgSet.phoneKey = str(cfg.get('Unity', 'phoneKey'))
        log.info(cfgSet.phoneKey)

        cfgSet.phone = cfg.get('Unity', 'phone')
        log.info(str(cfgSet.phone))

        cfgSet.symbol1 = str(cfg.get('pair1', 'symbol'))
        cfgSet.priceHigh1 = cfg.getfloat('pair1', 'priceHigh')
        cfgSet.priceLow1 = cfg.getfloat('pair1', 'priceLow')
        log.info("pair1: " + str(cfgSet.symbol1) + " " +
                 str(cfgSet.priceHigh1) + " " + str(cfgSet.priceLow1))
        print(("pair1: " + str(cfgSet.symbol1) + " " + str(cfgSet.priceHigh1) +
               " " + str(cfgSet.priceLow1)))

        cfgSet.symbol2 = str(cfg.get('pair2', 'symbol'))
        cfgSet.priceHigh2 = cfg.getfloat('pair2', 'priceHigh')
        cfgSet.priceLow2 = cfg.getfloat('pair2', 'priceLow')
        log.info("pair2: " + str(cfgSet.symbol2) + " " +
                 str(cfgSet.priceHigh2) + " " + str(cfgSet.priceLow2))

        cfgSet.symbol3 = str(cfg.get('pair3', 'symbol'))
        cfgSet.priceHigh3 = cfg.getfloat('pair3', 'priceHigh')
        cfgSet.priceLow3 = cfg.getfloat('pair3', 'priceLow')
        log.info("pair3: " + str(cfgSet.symbol3) + " " +
                 str(cfgSet.priceHigh3) + " " + str(cfgSet.priceLow3))

        cfgSet.symbol4 = str(cfg.get('pair4', 'symbol'))
        cfgSet.priceHigh4 = cfg.getfloat('pair4', 'priceHigh')
        cfgSet.priceLow4 = cfg.getfloat('pair4', 'priceLow')
        log.info("pair4: " + str(cfgSet.symbol4) + " " +
                 str(cfgSet.priceHigh4) + " " + str(cfgSet.priceLow4))

    except Exception as e:
        log.error("config error ", str(e))
        print("config error ", str(e))
class ResourceLinks(BetterLogger):
    audio: PathConfigParser = PathConfigParser(
        interpolation=ExtendedInterpolation())
    font: PathConfigParser = PathConfigParser(
        interpolation=ExtendedInterpolation())
    language: PathConfigParser = PathConfigParser(
        interpolation=ExtendedInterpolation())
    texture: PathConfigParser = PathConfigParser(
        interpolation=ExtendedInterpolation())
    model: PathConfigParser = PathConfigParser(
        interpolation=ExtendedInterpolation())
    gameConfig: PathConfigParser = PathConfigParser(
        interpolation=ExtendedInterpolation())

    audio_file_name: str = "audioLink.ini"
    font_file_name: str = "fontLink.ini"
    language_file_name: str = "langLink.ini"
    texture_file_name: str = "textureLink.ini"
    model_file_name: str = "modelLink.ini"
    game_data_file_name: str = "gameConfigLink.ini"

    array: {
        str: PathConfigParser
    } = {
        "audio": audio,
        "font": font,
        "language": language,
        "texture": texture,
        "model": model,
        "gameConfig": gameConfig
    }

    def __init__(self, *args, **kwargs):
        BetterLogger.__init__(self, *args, **kwargs)
        self.audio.__log_name_prefix__ = "Audio_"
        self.font.__log_name_prefix__ = "Font_"
        self.language.__log_name_prefix__ = "Language_"
        self.texture.__log_name_prefix__ = "Textures_"
        self.model.__log_name_prefix__ = "Models_"
        self.gameConfig.__log_name_prefix__ = "GameConfig_"

    def load_link_files(self):
        self.log_debug("Loading link files")

        self.audio.read(os.path.join(resources_dir, self.audio_file_name))
        self.font.read(os.path.join(resources_dir, self.font_file_name))
        self.language.read(os.path.join(resources_dir,
                                        self.language_file_name))
        self.texture.read(os.path.join(resources_dir, self.texture_file_name))
        self.model.read(os.path.join(resources_dir, self.model_file_name))
        self.gameConfig.read(
            os.path.join(resources_dir, self.game_data_file_name))

        self.log_info("Loaded link files")
Esempio n. 22
0
    def __init__(self, section):
        self._config = ConfigParser(interpolation=ExtendedInterpolation())
        self._section = section

        # Potential config files
        LOCATIONS = [
            '/etc/griotte.ini', '/usr/local/etc/griotte.ini',
            os.path.expanduser("~") + '/.griotte.ini'
        ]

        for file in LOCATIONS:
            if os.path.exists(file):
                logging.info("reading config file %s" % file)
                self._config.read_file(open(file))

        self._translate_to_tornado()
        options.parse_command_line()
Esempio n. 23
0
    def __init__(self):
        path_module = 'path'
        file_module = 'file'
        model_module = 'filter model'
        file_dir = os.path.abspath(os.path.dirname(__file__))
        # file_dir = os.path.split(os.path.realpath(__file__))[0]
        config_file_name = os.path.join(file_dir, 'conf.ini')
        configreader = ConfigParser(interpolation=ExtendedInterpolation())
        configreader.read(config_file_name)

        # path
        self.data_path = configreader.get(path_module, 'data_path')
        self.origin_path = configreader.get(path_module, 'origin_path')
        self.autophrase_path = configreader.get(path_module, 'autophrase_path')

        self.ner_service_command = configreader.get(path_module,
                                                    'ner_service_command')
        # self.ark_service_command = configreader.get(path_module, 'ark_service_command')
        # self.ark_service_command = '/home/nfs/cdong/tw/src/tools/ark-tweet-nlp-0.3.2.jar'

        # files
        self.pre_dict_file = configreader.get(file_module, 'pre_dict_file')
        self.post_dict_file = configreader.get(file_module, 'post_dict_file')

        # files
        self.afinn_file = configreader.get(model_module, 'afinn_file')
        self.black_list_file = configreader.get(model_module,
                                                'black_list_file')

        self.clf_model_file = configreader.get(model_module, 'clf_model_file')

        self.class_dist_file = configreader.get(model_module,
                                                'class_dist_file')
        self.chat_filter_file = configreader.get(model_module,
                                                 'chat_filter_file')
        self.is_noise_dict_file = configreader.get(model_module,
                                                   'is_noise_dict_file')
        self.orgn_predict_label_file = configreader.get(
            model_module, 'orgn_predict_label_file')

        self.terror_ft_model_file = configreader.get(model_module,
                                                     'terror_ft_model_file')
        self.terror_lr_model_file = configreader.get(model_module,
                                                     'terror_lr_model_file')
        self.korea_ft_model_file = configreader.get(model_module,
                                                    'korea_ft_model_fiel')
def run(_cfg,source_data=None):
    cfg = ConfigParser(interpolation=ExtendedInterpolation())
    cfg.read(_cfg)

    left = aux.read.into_list(cfg['mat']['left_nodes'])
    right = aux.read.into_list(cfg['mat']['right_nodes'])
    data = []
    
    add_data(cfg,data,['all','all'])
    add_data(cfg,data,['all','low'],edge_filter=low_pass_edge_filter,args=35)
    add_data(cfg,data,['all','mid'],edge_filter=mid_pass_edge_filter,args=(35,66))
    add_data(cfg,data,['all','high'],edge_filter=high_pass_edge_filter,args=66)
    add_data(cfg,data,['ipsilateral','all'],edge_filter=ipsilateral_pass_filter,args=[left,right])
    add_data(cfg,data,['contralateral','all'],edge_filter=contralateral_pass_filter,args=[left,right])
    
    df = pd.DataFrame(data,columns=["Comparison","Network","Edge threshold","Measure","Cell","Jaccard Distance"])
    if source_data: df.to_csv(source_data,index=False)
Esempio n. 25
0
    def __init__(self, xl_name="data_obj_cfg"):
        """
        Initialize ParametersParser

        Looks for Excel named range xl_name that contains ParametersParser object
        Parameters
        ----------
        xl_name
        """

        self.xl: w32 = xl_app()
        self.xl_name = xl_name

        self._log = logging.getLogger(__name__)

        ConfigParser.__init__(self, interpolation=ExtendedInterpolation())
        self._log.info(f"{__class__.__name__}({len(self)} groups)")
Esempio n. 26
0
 def __init__(self, filename=None, *, string="", obj=None, mapping=None):
     self.cfg = ConfigParser(interpolation=ExtendedInterpolation())
     if filename:
         self.filename = filename
         self.cfg.read(self.filename)
     elif string:
         self.filename = "_string.ini"
         self.cfg.read_string(string, self.filename)
     elif obj:
         self.filename = "_fileobj.ini"
         self.cfg.read_file(string, self.filename)
     elif mapping:
         self.filename = "_mapping.ini"
         self.cfg.read_dict(mapping, self.filename)
     else:
         self.filename = "_default.ini"
         self.cfg.read_string(DEFAULT_CONFIG, self.filename)
def treat_common_args(args):
    if args.version:
        sys.exit(0)
    parser = ConfigParser(interpolation=ExtendedInterpolation())
    variables.config = copy.deepcopy(defaultconfig)
    variables.loader = LoaderClass()

    # Read actual config file
    parser.read(args.config)
    variables.configfile = parser
    arg = vars(args)
    update_conf(arg, "common")

    # logconf = variables.config["common"]['logconfigfile']
    if os.path.isfile(args.logconfigfile):
        logging.config.fileConfig(args.logconfigfile,
                                  disable_existing_loggers=False)
Esempio n. 28
0
def get_cred(options, source):
    config_file = options.get('config')
    config = ConfigParser(interpolation=ExtendedInterpolation())
    config.read(config_file)

    if 'fofa' in source:
        cred = config.get('Credentials', 'fofa')
    if 'shodan' in source:
        cred = config.get('Credentials', 'shodan')
    if 'censys' in source:
        cred = config.get('Credentials', 'censys')

    print_debug(options, cred)
    username = cred.split(':')[0].strip()
    password = cred.split(':')[1].strip()

    return username, password
Esempio n. 29
0
 def init(self, filename: str = None) -> bool:
     defaults = {
         CLEANUP: 'automatic',
         ENABLED: 'false',
         INTEGRITY_CHECK: 'sha256',
         LOG_LEVEL: 'WARNING',
         LOG_METHOD: 'console',
         MAX_SIZE: '10MB',
     }
     self.parser = ConfigParser(defaults=defaults,
                                interpolation=ExtendedInterpolation())
     for dict_ in [malwarepatrol, sanesecurity, securiteinfo, urlhaus]:
         self.parser.read_dict(dict_)
     if filename:
         parsed = self.parser.read([filename])
         return len(parsed) == 1
     return True
    def __load_ini_file(file_path):
        """
        This method will load key-value pairs store in ini file and stores them in configuration manager.

        Args:
            file_path(str): Path of ini file.

        Returns:
            None
        """
        config = ConfigParser(interpolation=ExtendedInterpolation())
        config.read(file_path)

        for each_section in config.sections():
            for key, value in config.items(each_section):
                ConfigurationsManager().set_object_for_key(key=key,
                                                           value=value)