當前位置: 首頁>>代碼示例>>Python>>正文


Python configparser.SafeConfigParser方法代碼示例

本文整理匯總了Python中configparser.SafeConfigParser方法的典型用法代碼示例。如果您正苦於以下問題:Python configparser.SafeConfigParser方法的具體用法?Python configparser.SafeConfigParser怎麽用?Python configparser.SafeConfigParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在configparser的用法示例。


在下文中一共展示了configparser.SafeConfigParser方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_from_file

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def load_from_file(path):
    """
    Load settings from an INI file.

    This will check the configuration file for a lowercase version of all of
    the settings in this module. It will look in a section called "base".

    The example below will set PORTAL_SERVER_PORT.

        [base]
        portal_server_port = 4444
    """
    config = configparser.SafeConfigParser()
    config.read(path)

    mod = sys.modules[__name__]
    for name, _ in iterate_module_attributes(mod):
        # Check if lowercase version exists in the file and load the
        # appropriately-typed value.
        key = name.lower()
        if config.has_option(constants.BASE_SETTINGS_SECTION, key):
            value = config.get(constants.BASE_SETTINGS_SECTION, key)
            setattr(mod, name, parseValue(value)) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:25,代碼來源:settings.py

示例2: get_config_from_root

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def get_config_from_root(root):
    # This might raise EnvironmentError (if setup.cfg is missing), or
    # configparser.NoSectionError (if it lacks a [versioneer] section), or
    # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
    # the top of versioneer.py for instructions on writing your setup.cfg .
    setup_cfg = os.path.join(root, "setup.cfg")
    parser = configparser.SafeConfigParser()
    with open(setup_cfg, "r") as f:
        parser.readfp(f)
    VCS = parser.get("versioneer", "VCS")  # mandatory

    def get(parser, name):
        if parser.has_option("versioneer", name):
            return parser.get("versioneer", name)
        return None
    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg 
開發者ID:menpo,項目名稱:landmarkerio-server,代碼行數:26,代碼來源:versioneer.py

示例3: __init__

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def __init__(self):
        if sys.version_info < (3, 2):
            self.parser = ConfigParser.SafeConfigParser(os.environ)
        else:
            self.parser = ConfigParser.ConfigParser(defaults=os.environ)

        if 'RUCIO_CONFIG' in os.environ:
            self.configfile = os.environ['RUCIO_CONFIG']
        else:
            configs = [os.path.join(confdir, 'rucio.cfg') for confdir in get_config_dirs()]
            self.configfile = next(iter(filter(os.path.exists, configs)), None)
            if self.configfile is None:
                raise RuntimeError('Could not load Rucio configuration file. '
                                   'Rucio looked in the following paths for a configuration file, in order:'
                                   '\n\t' + '\n\t'.join(configs))

        if not self.parser.read(self.configfile) == [self.configfile]:
            raise RuntimeError('Could not load Rucio configuration file. '
                               'Rucio tried loading the following configuration file:'
                               '\n\t' + self.configfile) 
開發者ID:rucio,項目名稱:rucio,代碼行數:22,代碼來源:config.py

示例4: get_config_from_root

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def get_config_from_root(root):
    """Read the project setup.cfg file to determine Versioneer config."""
    # This might raise EnvironmentError (if setup.cfg is missing), or
    # configparser.NoSectionError (if it lacks a [versioneer] section), or
    # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
    # the top of versioneer.py for instructions on writing your setup.cfg .
    setup_cfg = os.path.join(root, "setup.cfg")
    parser = configparser.SafeConfigParser()
    with open(setup_cfg, "r") as f:
        parser.readfp(f)
    VCS = parser.get("versioneer", "VCS")  # mandatory

    def get(parser, name):
        if parser.has_option("versioneer", name):
            return parser.get("versioneer", name)
        return None
    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg 
開發者ID:spencerahill,項目名稱:aospy,代碼行數:29,代碼來源:versioneer.py

示例5: create

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def create():
    this.config = SafeConfigParser()
    return this.config 
開發者ID:rtshome,項目名稱:pgrepup,代碼行數:5,代碼來源:config.py

示例6: load

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def load(filename):
    this.config = SafeConfigParser()
    load_result = this.config.read(os.path.expanduser(filename))
    if len(load_result) != 1:
        raise ConfigFileNotFound("The configuration file %s does not exist" % filename)
    this.filename = os.path.expanduser(filename) 
開發者ID:rtshome,項目名稱:pgrepup,代碼行數:8,代碼來源:config.py

示例7: get_config_map

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def get_config_map():
    mysql_config_map = {}
    if_config_map = {}
    home_path = os.getcwd()
    try:
        if os.path.exists(os.path.join(home_path, Constant.CONFIG_FILE)):
            parser = SafeConfigParser()
            parser.read(os.path.join(home_path, Constant.CONFIG_FILE))
            # MySql config
            mysql_config_map[Constant.HOST_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.HOST_CONFIG)
            mysql_config_map[Constant.DATABASE_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.DATABASE_CONFIG)
            mysql_config_map[Constant.USER_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.USER_CONFIG)
            mysql_config_map[Constant.PASSWORD_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.PASSWORD_CONFIG)
            mysql_config_map[Constant.TABLE_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.TABLE_CONFIG)
            mysql_config_map[Constant.INSTANCE_NAME_FIELD_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.INSTANCE_NAME_FIELD_CONFIG)
            mysql_config_map[Constant.TIMESTAMP_FIELD_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.TIMESTAMP_FIELD_CONFIG)
            mysql_config_map[Constant.TIMESTAMP_FORMAT_CONFIG] = parser.get(Constant.MYSQL_TAG, Constant.TIMESTAMP_FORMAT_CONFIG, raw=True)
            check_config_parameters(mysql_config_map)
            # InsightFinder config
            if_config_map[Constant.LICENSE_KEY_CONFIG] = parser.get(Constant.IF_TAG, Constant.LICENSE_KEY_CONFIG)
            if_config_map[Constant.PROJECT_NAME_CONFIG] = parser.get(Constant.IF_TAG, Constant.PROJECT_NAME_CONFIG)
            if_config_map[Constant.USER_NAME_CONFIG] = parser.get(Constant.IF_TAG, Constant.USER_NAME_CONFIG)
            if_config_map[Constant.SERVER_URL_CONFIG] = parser.get(Constant.IF_TAG, Constant.SERVER_URL_CONFIG)
            if_config_map[Constant.SAMPLING_INTERVAL] = parser.get(Constant.IF_TAG, Constant.SAMPLING_INTERVAL)
            check_config_parameters(if_config_map)
            print("Loaded all parameters from config file")
    except IOError:
        print("config.ini file is missing")
    return mysql_config_map, if_config_map 
開發者ID:insightfinder,項目名稱:InsightAgent,代碼行數:31,代碼來源:getlogs_mysql.py

示例8: get_config_map

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def get_config_map():
    mssql_config_map = {}
    if_config_map = {}
    home_path = os.getcwd()
    try:
        if os.path.exists(os.path.join(home_path, Constant.CONFIG_FILE)):
            parser = SafeConfigParser()
            parser.read(os.path.join(home_path, Constant.CONFIG_FILE))
            # MSSql config
            mssql_config_map[Constant.HOST_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.HOST_CONFIG)
            mssql_config_map[Constant.DATABASE_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.DATABASE_CONFIG)
            mssql_config_map[Constant.USER_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.USER_CONFIG)
            mssql_config_map[Constant.PASSWORD_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.PASSWORD_CONFIG)
            mssql_config_map[Constant.TABLE_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.TABLE_CONFIG)
            mssql_config_map[Constant.DRIVER_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.DRIVER_CONFIG)
            mssql_config_map[Constant.INSTANCE_NAME_FIELD_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.INSTANCE_NAME_FIELD_CONFIG)
            mssql_config_map[Constant.TIMESTAMP_FIELD_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.TIMESTAMP_FIELD_CONFIG)
            mssql_config_map[Constant.TIMESTAMP_FORMAT_CONFIG] = parser.get(Constant.MSSQL_TAG, Constant.TIMESTAMP_FORMAT_CONFIG, raw=True)
            check_config_parameters(mssql_config_map)
            # InsightFinder config
            if_config_map[Constant.LICENSE_KEY_CONFIG] = parser.get(Constant.IF_TAG, Constant.LICENSE_KEY_CONFIG)
            if_config_map[Constant.PROJECT_NAME_CONFIG] = parser.get(Constant.IF_TAG, Constant.PROJECT_NAME_CONFIG)
            if_config_map[Constant.USER_NAME_CONFIG] = parser.get(Constant.IF_TAG, Constant.USER_NAME_CONFIG)
            if_config_map[Constant.SERVER_URL_CONFIG] = parser.get(Constant.IF_TAG, Constant.SERVER_URL_CONFIG)
            if_config_map[Constant.SAMPLING_INTERVAL] = parser.get(Constant.IF_TAG, Constant.SAMPLING_INTERVAL)
            check_config_parameters(if_config_map)
            print("Loaded all parameters from config file")
    except IOError:
        print("config.ini file is missing")
    return mssql_config_map, if_config_map 
開發者ID:insightfinder,項目名稱:InsightAgent,代碼行數:32,代碼來源:get_logs_mssql.py

示例9: get

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def get(self, key, filepath):
        """Get configuration parameter.

        Reads 'key' configuration parameter from the configuration file given
        in 'filepath'. Configuration parameter in 'key' must follow the schema
        <section>.<option> .

        :param key: key to get
        :param filepath: configuration file
        """
        if not filepath:
            raise RuntimeError("Configuration file not given")

        if not self.__check_config_key(key):
            raise RuntimeError("%s parameter does not exists" % key)

        if not os.path.isfile(filepath):
            raise RuntimeError("%s config file does not exist" % filepath)

        section, option = key.split('.')

        config = configparser.SafeConfigParser()
        config.read(filepath)

        try:
            option = config.get(section, option)
            self.display('config.tmpl', key=key, option=option)
        except (configparser.NoSectionError, configparser.NoOptionError):
            pass

        return CMD_SUCCESS 
開發者ID:chaoss,項目名稱:grimoirelab-sortinghat,代碼行數:33,代碼來源:config.py

示例10: set

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def set(self, key, value, filepath):
        """Set configuration parameter.

        Writes 'value' on 'key' to the configuration file given in
        'filepath'. Configuration parameter in 'key' must follow the schema
        <section>.<option> .

        :param key: key to set
        :param value: value to set
        :param filepath: configuration file
        """
        if not filepath:
            raise RuntimeError("Configuration file not given")

        if not self.__check_config_key(key):
            raise RuntimeError("%s parameter does not exists or cannot be set" % key)

        config = configparser.SafeConfigParser()

        if os.path.isfile(filepath):
            config.read(filepath)

        section, option = key.split('.')

        if section not in config.sections():
            config.add_section(section)

        try:
            config.set(section, option, value)
        except TypeError as e:
            raise RuntimeError(str(e))

        try:
            with open(filepath, 'w') as f:
                config.write(f)
        except IOError as e:
            raise RuntimeError(str(e))

        return CMD_SUCCESS 
開發者ID:chaoss,項目名稱:grimoirelab-sortinghat,代碼行數:41,代碼來源:config.py

示例11: test_set_value

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def test_set_value(self):
        """Check set method"""

        import shutil
        import tempfile

        # Copy the reference config file to a temporary directory
        testpath = tempfile.mkdtemp(prefix='sortinghat_')
        shutil.copy(MOCK_CONFIG_FILE, testpath)
        filepath = os.path.join(testpath, 'mock_config_file.cfg')

        # First read initial values
        config = configparser.SafeConfigParser()
        config.read(filepath)

        self.assertEqual(config.get('db', 'user'), 'root')
        self.assertEqual(config.get('db', 'database'), 'testdb')

        # Set the new values
        retcode = self.cmd.set('db.user', 'jsmith', filepath)
        self.assertEqual(retcode, CMD_SUCCESS)

        retcode = self.cmd.set('db.database', 'mydb', filepath)
        self.assertEqual(retcode, CMD_SUCCESS)

        # Check the new values
        config.read(filepath)
        self.assertEqual(config.get('db', 'user'), 'jsmith')
        self.assertEqual(config.get('db', 'password'), '****')
        self.assertEqual(config.get('db', 'database'), 'mydb')

        shutil.rmtree(testpath) 
開發者ID:chaoss,項目名稱:grimoirelab-sortinghat,代碼行數:34,代碼來源:test_cmd_config.py

示例12: main

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def main():
  print('Usage: Pressing just the [Enter] key will display the latest voltage readings, type ^C to exit')
  print('       Type in the cell # that you want to calibrate followed by [Enter]')
  print('       Then type in the mesured voltage for that cell followed by [Enter]')
  print()
  print('       Make sure the Battery Monitoring software is running otherwise the summary file will not be current')
  print('       This program uses the data from the log file generated by the Battery Monitoring software')
  print('       Make sure that the Battery Monitoring software is logging to a real file and not /dev/null')
  print('       This program averages the data from the log file for the last 100 seconds.')
  print('       To make sure that the calibration is accurate make sure the input voltages are not varying')
  avvolts=[]
  while True:
    try:
      loadconfig()
      avvolts=avv()
#      time.sleep(60.0)
      what = input(">")
      if len(what)>0:
        realvolts = eval(input("Cell " + what + " reading "))
        what=int(what)
        config['calibrate']['measured'][what] = round(realvolts,3)
        config['calibrate']['displayed'][what] = round(avvolts[what],3)
        batconfigdata=SafeConfigParser()
        batconfigdata.read('battery.cfg')
        batconfigdata.set('calibrate','measured',str(config['calibrate']['measured']))
        batconfigdata.set('calibrate','displayed',str(config['calibrate']['displayed']))
        with open('battery.cfg', 'w') as batconfig:
          batconfigdata.write(batconfig)
        batconfig.closed


    except KeyboardInterrupt:
      break 
開發者ID:simat,項目名稱:BatteryMonitor,代碼行數:35,代碼來源:calvcourse.py

示例13: main

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def main():
  print('Usage: Pressing just the [Enter] key will display the latest voltage readings, type ^C to exit')
  print('       Type in the cell # that you want to calibrate followed by [Enter]')
  print('       Then type in the mesured voltage for that cell followed by [Enter]')
  print()
  print('       Make sure the Battery Monitoring software is running otherwise the summary file will not be current')
  print('       This program uses the data from the log file generated by the Battery Monitoring software')
  print('       Make sure that the Battery Monitoring software is logging to a real file and not /dev/null')
  print('       This program averages the data from the log file for the last 100 seconds.')
  print('       To make sure that the calibration is accurate make sure the input voltages are not varying')
  avvolts=[]
  while True:
    try:
      loadconfig()
      avvolts=avv()
#      time.sleep(60.0)
      what = input(">")
      if len(what)>0:
        realvolts = eval(input("Cell " + what + " reading "))
        what=int(what)
        config['calibrate']['delta'][what-1] = round(avvolts[what-1]-realvolts+config['calibrate']['delta'][what-1],3)
        batconfigdata=SafeConfigParser()
        batconfigdata.read('battery.cfg')
        batconfigdata.set('calibrate','delta',str(config['calibrate']['delta']))
        with open('battery.cfg', 'w') as batconfig:
          batconfigdata.write(batconfig)
        batconfig.closed


    except KeyboardInterrupt:
      break 
開發者ID:simat,項目名稱:BatteryMonitor,代碼行數:33,代碼來源:calvfine.py

示例14: main

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def main():
  print('Usage: Pressing just the [Enter] key will display the latest voltage readings, type ^C to exit')
  print('       Press any other key to change the voltage calibration of all the voltage readings')
  print()
  print('       Make sure the Battery Monitoring software is running otherwise the summary file will not be current')
  print('       This program uses the data from the log file generated by the Battery Monitoring software')
  print('       Make sure that the Battery Monitoring software is logging to a real file and not /dev/null')
  print('       This program averages the data from the log file for the last 100 seconds.')
  print('       To make sure that the calibration is accurate make sure the input voltages are not varying')


  avvolts=[]
  while True:
    try:

      loadconfig()
      avvolts=avv()
#      time.sleep(60.0)
      what = input(">")
      if len(what)>0:
        realvolts = eval(input("All Cell readings "))
        for i in range(numcells):
          config['calibrate']['delta'][i] = round(avvolts[i]-realvolts+config['calibrate']['delta'][i],3)
        print(config['calibrate']['delta'])
        batconfigdata=SafeConfigParser()
        batconfigdata.read('battery.cfg')
        batconfigdata.set('calibrate','delta',str(config['calibrate']['delta']))
        with open('battery.cfg', 'w') as batconfig:
          batconfigdata.write(batconfig)
        batconfig.closed


    except KeyboardInterrupt:
      break 
開發者ID:simat,項目名稱:BatteryMonitor,代碼行數:36,代碼來源:calvfineall.py

示例15: main

# 需要導入模塊: import configparser [as 別名]
# 或者: from configparser import SafeConfigParser [as 別名]
def main():
  print('Usage: At > prompt enter current input channel number to change then [Enter] key')
  print('       Pressing just the [Enter] key will display the latest current readings, type ^C to exit')
  print()
  print('       Make sure the Battery Monitoring software is running otherwise the summary file will not be current')
  print('       This program uses the data from the log file generated by the Battery Monitoring software')
  print('       Make sure that the Battery Monitoring software is logging to a real file and not /dev/null')
  print('       This program averages the data from the log file for the last 100 seconds.')
  print('       To make sure that the calibartion is accurate make sure the current on the input being calibrated is not varying')   
  while True:
    try:
#      time.sleep(60.0)
      geti()
      what = input(">")
      if len(what)>0:
        avi=getavi()
        reali = eval(input("Input " + what + " multimeter reading "))
        if reali == 0:
          print("Input Error: Zero not valid current input")
        else:
          what=int(what)
          config['calibrate']['currentgain'][what-1] = config['calibrate']['currentgain'][what-1]*reali/avi[what-1]
          print('Recalculated gain: ' + str(config['calibrate']['currentgain']))
          batconfigdata=SafeConfigParser()
          batconfigdata.read('battery.cfg')
          batconfigdata.set('calibrate','currentgain',str(config['calibrate']['currentgain']))
          with open('battery.cfg', 'w') as batconfig:
            batconfigdata.write(batconfig)
          batconfig.closed



    except KeyboardInterrupt:
      break 
開發者ID:simat,項目名稱:BatteryMonitor,代碼行數:36,代碼來源:caligain.py


注:本文中的configparser.SafeConfigParser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。