当前位置: 首页>>代码示例>>Python>>正文


Python ConfigParser.add_section方法代码示例

本文整理汇总了Python中ConfigParser.ConfigParser.add_section方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.add_section方法的具体用法?Python ConfigParser.add_section怎么用?Python ConfigParser.add_section使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConfigParser.ConfigParser的用法示例。


在下文中一共展示了ConfigParser.add_section方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_typical

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
 def test_typical(self):
     """
     Test a non-broken, typical setup
     """
     from ConfigParser import ConfigParser
     from velouria.config import VelouriaConfigKeyboard
     from gi.repository import Gdk
     
     config = ConfigParser()
     config.add_section("keyboard")
     config.set("keyboard", "quit", "META_MASK+KEY_q\nKEY_x")
     config.set("keyboard", "fullscreen", "CONTROL_MASK+KEY_r")
     config.set("keyboard", "pause", "")
     
     keyconfig = VelouriaConfigKeyboard(config)
     
     expected = self._defaults()
     
     # override quit and fullscreen actions
     expected['pause'] = None
     expected['quit'] = [
         {'key': Gdk.KEY_x, 'modifiers': 0},
         {'key': Gdk.KEY_q, 'modifiers': Gdk.ModifierType.META_MASK},
     ]
     expected['fullscreen'] = [
         {'key': Gdk.KEY_r, 'modifiers': Gdk.ModifierType.CONTROL_MASK},
     ]
     
     self.assertItemsEqual(expected['quit'], keyconfig.quit)
     self.assertItemsEqual(expected['fullscreen'], keyconfig.fullscreen)
     self.assertIsNone(keyconfig.pause)
开发者ID:jjmojojjmojo,项目名称:velouria,代码行数:33,代码来源:test_config.py

示例2: config_parser

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
def config_parser(role='agent'):
    config_parser = ConfigParser()
    config_parser.add_section(role)
    config_parser.set(role, 'APP_ID', '1')
    config_parser.set(role, 'IPOP_BASE_NAMESPACE', 'http://example.org:443')
    config_parser.set(role, 'CONPAAS_HOME', IPOP_CONF_DIR)
    return config_parser
开发者ID:ConPaaS-team,项目名称:conpaas,代码行数:9,代码来源:test_ipop.py

示例3: __init__

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
class UserConfig:

    def __init__(self, filename=default_user_config_file):
        self.parser = ConfigParser()
        self.parser.read(filename)
        self.filename = filename
        if not isfile(self.filename):
            self.parser.add_section('diaspora')
            self.set_activated(False)
            self.__save()
        else:
            self.parser.read(self.filename)

        if not self.parser.has_section('diaspora'):
            self.parser.add_section('diaspora')

    def is_installed(self):
        return self.parser.getboolean('diaspora', 'activated')

    def set_activated(self, value):
        self.parser.set('diaspora', 'activated', str(value))
        self.__save()

    def __save(self):
        with open(self.filename, 'wb') as f:
            self.parser.write(f)
开发者ID:syncloud,项目名称:diaspora,代码行数:28,代码来源:config.py

示例4: set_auto_rsvp_groups

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
def set_auto_rsvp_groups():
    '''Generates a group config file from user input. The config file is saved
    to CONFIG_FILENAME specified above.

    All groups of the current member are printed to the config file. However,
    any groups the user doesn't want to auto RSVP will be commented out with a
    '#'.
    '''
    groups = get_groups()

    config_groups = []
    for group in groups:
        ans = raw_input(
            'Automatically RSVP yes for %s? [y/n]: ' % group['name']
        ).lower()

        while ans not in ['y', 'n']:
            print 'Please enter a \'y\' or \'n\'.'
            ans = raw_input(
                'Automatically RSVP yes for %s? [y/n]: ' % group['name']
            ).lower()
        
        if ans == 'y':
            # We want to auto-rsvp for this group
            config_groups.append((str(group['id']), group['name']))
        else:
            # Don't auto RSVP. We'll write add this group with a comment
            # preceding the line.
            config_groups.append(('#%s' % str(group['id']), group['name']))

    config = ConfigParser()
    config.add_section('rsvp_groups')
    [config.set('rsvp_groups', group_id, group_name) for group_id, group_name
        in config_groups]
    write_config(config)
开发者ID:jimmyfallon,项目名称:meetup-rsvper,代码行数:37,代码来源:meetup-rsvper.py

示例5: initConfig

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
    def initConfig(self):
        kate.debug("initConfig()")
        config_path = kate.pate.pluginDirectories[1] + "/%s/%s.conf" % (__name__, __name__)
        config_file = QFileInfo(config_path)

        if not config_file.exists():
            open(config_path, "w").close()

        config = ConfigParser()
        config.read(config_path)

        # init the DEFAULT options if they don't exist
        # the DEFAULT section is special and doesn't need to be created: if not config.has_section('DEFAULT'): config.add_section('DEFAULT')
        if not config.has_option("DEFAULT", "ignore"):
            config.set("DEFAULT", "ignore", "")
        if not config.has_option("DEFAULT", "filter"):
            config.set("DEFAULT", "filter", "*")
        if not config.has_option("DEFAULT", "finder_size"):
            config.set("DEFAULT", "finder_size", "400x450")
        if not config.has_option("DEFAULT", "config_size"):
            config.set("DEFAULT", "config_size", "300x350")
        if not config.has_option("DEFAULT", "search_type"):
            config.set("DEFAULT", "search_type", "word")

        # create the general section if it doesn't exist
        if not config.has_section("general"):
            config.add_section("general")

        # flush the config file
        config.write(open(config_path, "w"))

        # save the config object and config path as instance vars for use later
        self.config = config
        self.config_path = config_path
开发者ID:jorrel,项目名称:kate_directory_project,代码行数:36,代码来源:directory_project.py

示例6: startCompetitorDialog

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
    def startCompetitorDialog(self):
        pbText = str(self.startStopPB.text())

        if pbText == "Start":
            self.newCompetitorDialog.show()
        if pbText == "Stop":
            self.timer.stop()
            self.updateStartStop("Start")

            log = ConfigParser()
            log.add_section("Scoreboard")
            log.set("Scoreboard","MinesDetected",self.mineDetectedLB.text())
            log.set("Scoreboard","WrongMinesDetected",self.wrongMinesDetectedLB.text())
            log.set("Scoreboard","ExplodedMines",len(self.minesExploded))
            log.set("Scoreboard","ExplodedMinesDetected",len(self.minesExplodedDetected))
            log.set("Scoreboard","Time",self.timeLB.text())

            undetected = undetectedCovered = 0
            mWidth, mHeight = self.width/self.cellXSize,self.height/self.cellYSize
            for m in self.mines:
                if not self.minesDetected.has_key(tuple(m)):
                    x, y = m[0]/self.cellXSize+mWidth/2., mHeight/2. - m[1]/self.cellYSize
                    if (x<0) or (y<0) or (y >self.Map.shape[0]) or (x >self.Map.shape[1]):
                        undetected += 1
                        continue
                    if self.actionCoilsSignal.isChecked():
                        if self.Map[y,x] != 220:
                            undetectedCovered += 1
                        else:
                            undetected += 1
                    else:
                        if self.Map[y,x] == 183:
                            undetectedCovered += 1
                        else:
                            undetected += 1

            log.set("Scoreboard","Undetected", undetected)
            log.set("Scoreboard","UndetectedCovered", undetectedCovered)


            percent = 0.0
            if self.actionCoilsSignal.isChecked():
                percent = self.Map[self.Map != 220].size/float(self.Map.size)
            else:
                percent = self.Map[self.Map == 183].size/float(self.Map.size)
            log.set("Scoreboard","Covered Area",percent)

            path = os.path.expanduser("~/HRATC 2014 Simulator/")
            if not os.path.exists(path):
                os.mkdir(path)

            path += "logs/"
            if not os.path.exists(path):
                os.mkdir(path)

            cfile = open(path+"/log_{}.log".format(self.competitorName),"w")  
            log.write(cfile)
            cfile.close()

            self.competitorName = None
开发者ID:mikepurvis,项目名称:hratc2014_framework,代码行数:62,代码来源:minewindow.py

示例7: NightscoutConfig

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
class NightscoutConfig(object):
    FILENAME = 'config'
    SECTION = 'NightscoutMenubar'
    HOST = 'nightscout_host'
    USE_MMOL = 'use_mmol'

    def __init__(self, app_name):
        self.config_path = os.path.join(rumps.application_support(app_name), self.FILENAME)
        self.config = ConfigParser()
        self.config.read([self.config_path])
        if not self.config.has_section(self.SECTION):
            self.config.add_section(self.SECTION)
        if not self.config.has_option(self.SECTION, self.HOST):
            self.set_host('')
        if not self.config.has_option(self.SECTION, self.USE_MMOL):
            self.set_use_mmol(False)

    def get_host(self):
        return self.config.get(self.SECTION, self.HOST)

    def set_host(self, host):
        self.config.set(self.SECTION, self.HOST, host)
        with open(self.config_path, 'w') as f:
            self.config.write(f)

    def get_use_mmol(self):
        return bool(self.config.get(self.SECTION, self.USE_MMOL))

    def set_use_mmol(self, mmol):
        self.config.set(self.SECTION, self.USE_MMOL, 'true' if mmol else '')
        with open(self.config_path, 'w') as f:
            self.config.write(f)
开发者ID:mddub,项目名称:nightscout-osx-menubar,代码行数:34,代码来源:nightscout_osx_menubar.py

示例8: addRegra

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
	def addRegra(self, ipORrede, nome, banda_liberada, banda_down, prio, delimitado, isolado):
		#system("tc qdisc del dev %s root"%self.device)
		arquivo = ConfigParser()
		arquivo.read( '/var/lib/netcontrol/plugins/limite_banda/etc/config_server' )
		
		if not arquivo.has_section("contador_regras"):
			arquivo.add_section("contador_regras")
			arquivo.set("contador_regras","contador",1)
			arquivo.write( open('/var/lib/netcontrol/plugins/limite_banda/etc/config_server','w') )
			cont = "1"
		else:
			cont = int(arquivo.get("contador_regras", "contador")) + 1
			arquivo.set("contador_regras","contador", cont)
			arquivo.write( open('/var/lib/netcontrol/plugins/limite_banda/etc/config_server','w') )
			cont = str(cont)
		cont = "000%s"%(cont)
		ip   = ipORrede.replace('.','_').replace('/','_')
		user = nome.replace(' ','_')
		nome = "cbq-%s.%s%s-in"%(cont[-4:],ip,user)
		regra = "DEVICE=%s,%s,%s\n" \
				"RATE=%sKbit\n"   \
				"WEIGHT=%sKbit\n" \
				"PRIO=%s\n"       \
				"RULE=%s\n"       \
				"BOUNDED=%s\n"    \
				"ISOLATED=%s"%(self.device, self.banda_total, self.banda_total_down, banda_liberada, banda_down, prio, ipORrede, delimitado, isolado)
		open('%s%s'%(self.etc,nome),'w').write(regra)
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:29,代码来源:GerenciaShaper.py

示例9: createNodeInfoFile

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
def createNodeInfoFile(dirPath, toKeep):
	"""
	Creates the .nodeInfo file in the directory specified by dirPath.
	The Node:Type must be set by concrete nodes
	@precondition: dirPath is a valid directory
	@postcondition: All sections/tags are created and set except "Type".
		"Type" must be set by concrete nodes.
	"""
	username = getUsername()
	timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
	
	nodeInfo = ConfigParser()
	nodeInfo.add_section('Node')
	nodeInfo.set('Node', 'Type', '')
	
	nodeInfo.add_section('Versioning')
	nodeInfo.set('Versioning', 'LatestVersion', '0')
	nodeInfo.set('Versioning', 'VersionsToKeep', str(toKeep))
	nodeInfo.set('Versioning', 'Locked', 'False')
	nodeInfo.set('Versioning', 'LastCheckoutTime', timestamp)
	nodeInfo.set('Versioning', 'LastCheckoutUser', username)
	nodeInfo.set('Versioning', 'LastCheckinTime', timestamp)
	nodeInfo.set('Versioning', 'LastCheckinUser', username)
	
	_writeConfigFile(os.path.join(dirPath, ".nodeInfo"), nodeInfo)
开发者ID:sm-github,项目名称:ramshorn-tools,代码行数:27,代码来源:utilities.py

示例10: set_config_to_path

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
def set_config_to_path(configPath, section, option, value):

    read = False

    #check if config file exists
    if ( os.path.isfile(configPath)):
        configPath = os.path.realpath(configPath);
        config = ConfigParser();
        #try to read the value from ini file
        try:
            config.read(configPath)
            if config.has_section(section) :
                    #Update the new values
                config.set(section, option, value)
                read = True
        except: #read failed due currupted ini file that can happen due to suddent power of during update
            print "except"
    if( read == False): #file not exist and needs to be creatred
        config = ConfigParser();
        config.add_section(section)
        config.set(section, option, value)
        read = True

    fo=open(configPath, "w+")
    config.write(fo) # Write update config

    return read
开发者ID:FaaduVineet,项目名称:hello-world,代码行数:29,代码来源:test_utils.py

示例11: start_config

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
def start_config(config_file_name):
    config = ConfigParser()
    config.add_section("global")

    value = raw_input("Enter the JSON root folder to write the json files too : ")
    if len(value) == 0:
        value = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/www/JSON'
    elif value[-1] != "/":
        value += "/"
    config.set("global", "json_root", value)

    modules_config = []

    module_list = os.listdir(os.path.dirname(os.path.abspath(__file__)))
    for module in module_list:
        if module == "__init__.py" or module[-3:] != ".py" or module[:4] == 'main':
            continue
        loaded_module = __import__("pygamescanner." + module[:-3], fromlist=["*"])
        module_config = loaded_module.start_config(config)
        modules_config.append(module_config)

    modules_config_dict = dict()
    modules_config_dict["module_list"] = modules_config
    config_string = json.dumps(modules_config_dict)
    modules_file = open(config.get("global", "json_root") + "modules.json", "w")
    modules_file.write(config_string)
    modules_file.close()

    config_file = open(config_file_name, "w")
    config.write(config_file)
    config_file.close()
开发者ID:Mause,项目名称:pyGameScanner,代码行数:33,代码来源:main.py

示例12: CreateConfig

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
 def CreateConfig(self, ):
     config=ConfigParser()
     config.add_section('SMTP')
     config.add_section('SEND')
     config.add_section('MAIL')
     config.set('SMTP','Server','smtp.163.com')
     config.set('SMTP','Port','25')
     config.set('SMTP','SSL','0')
     config.set('SEND','Thread','1')
     config.set('SEND','Per_Sender','4')
     config.set('SEND','per_email_sleep','10')
     config.set('SEND','fail_times','4')
     config.set('SEND','Sender','Sender.txt')
     config.set('SEND','Receiver','Receiver.txt')
     config.set('MAIL','PlainOrHtml','html')
     config.set('MAIL','Subject','Join My Network On Linkedin')
     config.set('MAIL','DisplayName','Rich Park{%MAILFROM%}')
     config.set('MAIL','ForgeSource','false')
     config.set('MAIL','Content','mail.html')
     config.set('MAIL','Attachment','None')
     
     
     config.write(open(gConfigFileStr,'w'))
     #config.write(codecs.open(gConfigFileStr,'w'))
     if not exists('Sender.txt'):open('Sender.txt','a')
     if not exists('Receiver.txt'):open('Receiver.txt','a')
     self.__init__()
开发者ID:Zx7ffa4512-Python,项目名称:Project-SendEmail,代码行数:29,代码来源:SendEmail+-+中文.py

示例13: build_config

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
def build_config():
    config = ConfigParser()
    config.add_section('Modbus Tcp')
    config.add_section('Modbus Protocol')
    config.add_section('Modbus Serial')
    config.set('Modbus Tcp', "ip", '127.0.0.1')
    config.set('Modbus Protocol', "block start", "0")
    config.set('Modbus Protocol', "block size", "100")
    config.set('Modbus Protocol', "bin min", "0")
    config.set('Modbus Protocol', "bin max", "1")
    config.set('Modbus Protocol', "reg min", "0")
    config.set('Modbus Protocol', "reg max", "65535")
    config.set('Modbus Serial', "baudrate", "9600")
    config.set('Modbus Serial', "bytesize", "8")
    config.set('Modbus Serial', "parity", 'N')
    config.set('Modbus Serial', "stopbits", "1")
    config.set('Modbus Serial', "xonxoff", "0")
    config.set('Modbus Serial', "rtscts", "0")
    config.set('Modbus Serial', "dsrdtr", "0")
    config.set('Modbus Serial', "writetimeout", "2")
    config.set('Modbus Serial', "timeout", "2")

    config.add_section('Logging')
    # config.set('Logging', "log file", os.path.join(self.user_data_dir,
    #                                                'modbus.log'))

    config.set('Logging', "logging", "1")
    config.set('Logging', "console logging", "1")
    config.set('Logging', "console log level", "DEBUG")
    config.set('Logging', "file log level", "DEBUG")
    config.set('Logging', "file logging", "1")

    config.add_section('Simulation')
    config.set('Simulation', 'time interval', "1")
    return config
开发者ID:dhoomakethu,项目名称:modbus_sim_cli,代码行数:37,代码来源:config_parser.py

示例14: Playlist

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
class Playlist(object):
  def __init__(self, location):
    dir = os.path.expanduser(os.path.dirname(location))
    if not os.path.exists(dir):
      os.makedirs(dir)

    self._config = ConfigParser()
    self._config.optionxform = str

    self._file = os.path.expanduser(location)
    if os.path.exists(self._file):
      self._config.read(self._file)
    else:
      self._config.add_section('Playlist')
      self.save()

  def save(self):
    self._config.write(open(self._file, 'wb'))

  def append(self, item):
    self._config.set('Playlist', *item)
    self.save()

  def remove(self, option):
    self._config.remove_option('Playlist', option)
    self.save()

  def __getitem__(self, item):
    return self._config.items('Playlist')[item]

  def __iter__(self):
    return iter(self._config.items('Playlist'))
开发者ID:iamFIREcracker,项目名称:gstream,代码行数:34,代码来源:playlist.py

示例15: save_action_to_file

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import add_section [as 别名]
 def save_action_to_file(action, f):
     parser = ConfigParser()
     parser.add_section('action')
     for action_k, action_v in action.items():
         parser.set('action', action_k, action_v)
     parser.write(f)
     f.seek(0)
开发者ID:frescof,项目名称:freezer,代码行数:9,代码来源:scheduler_job.py


注:本文中的ConfigParser.ConfigParser.add_section方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。