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


Python ConfigParser.remove_section方法代码示例

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


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

示例1: parse_config

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
def parse_config(configs):
    """
    :type configs list
    :rtype: ConfigParser
    """
    conf = ConfigParser()

    all_configs = []
    while len(configs) > 0:
        all_configs += configs
        files = []
        for mask in configs:
            for f in glob.glob(mask):
                if os.path.isfile(f):
                    files.append(f)
        conf.read(files)
        configs = []
        if conf.has_option(DEFAULT_SECTION, "include"):
            configs = list(set(re.split(r'\s+', conf.get(DEFAULT_SECTION, "include"))) - set(all_configs))

    for section in conf.sections():
        for k, v in conf.items(DEFAULT_SECTION):
            if not conf.has_option(section, k):
                conf.set(section, k, v)
        for k, v in conf.items(section):
            v = re.sub(r'^\s*"|"\s*$', '', v) # remove quotes
            conf.set(section, k, v)

    conf.remove_section(DEFAULT_SECTION)

    if not conf.sections():
        usage("No sections found in config files " + ", ".join(all_configs))
    return conf
开发者ID:DmitryKoterov,项目名称:cachelrud,代码行数:35,代码来源:main.py

示例2: rm

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
def rm(args):
    p = ConfigParser()
    vm_cfg = args.name + '.conf'
    p.read(vm_cfg)

    for section in p.sections():
        if section.startswith('disk'):
            LOG.debug('Delete VM %s', args.name)
            try:
                f = p.get(section, 'file')
                LOG.info('Delete VM disk %s', f)
                os.unlink(f)
            except OSError as e:
                raise RuntimeError(e)

    LOG.debug('Delete VM config %s', vm_cfg)
    try:
        os.unlink(vm_cfg)
    except OSError:
        LOG.warn('%s is not exist' %  vm_cfg)

    LOG.debug('Delete VM item from config file')
    p = ConfigParser()
    p.read(vman_config)
    p.remove_section(args.name)
    p.write(open(vman_config, 'w'))
开发者ID:mathslinux,项目名称:vman,代码行数:28,代码来源:rm.py

示例3: remove_section

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
	def remove_section(self,section):
        if self.has_section(section):
            ConfigParser.remove_section(self, section)
    
	def clear_all(self):
        for section in self.sections():
            self.remove_section(section)
开发者ID:tziadi,项目名称:featurehouse-withDeepMethods,代码行数:9,代码来源:configmanager.py

示例4: __init__

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
class AntiLogoConfig:
	configfile = "/etc/enigma2/AntiLogo.conf"

	def __init__(self):
		self.configparser = ConfigParser()
		self.configparser.read(self.configfile)

	def setLastPreset(self,name):
		self.configparser.set(DEFAULTSECT, "lastpreset",name)
		self.writeConfig()

	def getLastPreset(self):
		last = self.configparser.get(DEFAULTSECT, "lastpreset")
		return self.getPreset(last)

	def getPresets(self):
		presets = []
		sections = self.configparser.sections()
		for section in sections:
			presets.append(section)
		return presets

	def getPreset(self,name):
		if self.configparser.has_section(name) is True:
			print "loading preset ",name
			l = {}
			l["x"] = int(self.configparser.get(name, "x"))
			l["y"] = int(self.configparser.get(name, "y"))
			l["width"] = int(self.configparser.get(name, "width"))
			l["height"] = int(self.configparser.get(name, "height"))
			self.setLastPreset(name)
			return l
		else:
			print "couldn't find preset", name
			return False

	def setPreset(self,name,size,position):
		try:
			self.configparser.add_section(name)
			self.configparser.set(name, "x", position[0])
			self.configparser.set(name, "y", position[1])
			self.configparser.set(name, "width", size[0])
			self.configparser.set(name, "height", size[1])
			self.configparser.set(DEFAULTSECT, "lastpreset",name)
			self.writeConfig()
			return True
		except DuplicateSectionError:
			self.deletePreset(name)
			self.setPreset(name, size, position)

	def deletePreset(self,name):
		self.configparser.remove_section(name)
		self.writeConfig()

	def writeConfig(self):
		fp = open(self.configfile, "w")
		self.configparser.write(fp)
		fp.close()
开发者ID:23devillson,项目名称:E2-OpenPlugins,代码行数:60,代码来源:plugin.py

示例5: delMachine

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
 def delMachine(self, mac):
     c = Cfg()
     c.read( self.__configLTSPFile )
     try:
         c.remove_section(mac)
         c.write( open(self.__configLTSPFile,'w') )
         return True
     except:
         return False
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:11,代码来源:ltsp.py

示例6: delRange

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
 def delRange(self):
     section = 'range'
     c = Cfg()
     c.read(self.__configLTSPFile)
     ret = False
     if c.has_section( section ):
         c.remove_section( section )
         c.write( open(self.__configLTSPFile,'w')  )
         ret = True
     del c
     
     return ret
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:14,代码来源:ltsp.py

示例7: Database

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
class Database(object):

    def __init__(self, passphrase):
        self.dirty = False
        self.passphrase = passphrase

    def __enter__(self):
        if not os.path.exists(DATABASE) and not os.path.exists(DATABASE_UNENC):
            print "Database does not exist. Creating it..."
            fh = open(DATABASE_UNENC, 'w+')
            fh.close()
            self.dirty = True
        elif os.path.exists(DATABASE_UNENC):
            print "Database seems unencrypted. Attempting to encrypt..."
            call(['gpg', '-q', '--no-mdc-warning', '--passphrase', self.passphrase, '-c', DATABASE_UNENC])
        else:
            if not call(['gpg', '-q', '--no-mdc-warning', '--passphrase', self.passphrase, DATABASE]) == 0:
                sys.exit(1)
        self.cp = ConfigParser()
        self.cp.read(DATABASE_UNENC)
        return self

    def __exit__(self, *args):
        if self.dirty:
            self.cp.write(open(DATABASE_UNENC, 'w'))
            if os.path.exists(DATABASE):
                os.unlink(DATABASE)
            call(['gpg', '-q', '--no-mdc-warning', '--passphrase', self.passphrase, '-c', DATABASE_UNENC])
        if os.path.exists(DATABASE_UNENC):
            os.unlink(DATABASE_UNENC)

    def set(self, section, key, value):
        if not self.cp.has_section(section):
            self.cp.add_section(section)
        self.cp.set(section, key, value)
        self.dirty = True

    def get(self, section):
        try:
            return self.cp.items(section)
        except NoSectionError:
            return []

    def sections(self):
        return self.cp.sections()

    def delete(self, section, key):
        self.cp.remove_option(section, key)
        if not self.cp.items(section):
            self.cp.remove_section(section)
        self.dirty = True
开发者ID:tueabra,项目名称:fort,代码行数:53,代码来源:fort.py

示例8: dump_config

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
 def dump_config(self):
     config = conf.possible_configs('client.ini').next()
     parser = ConfigParser()
     parser.read(config)
     
     for section in parser.sections():
         if section not in ['client', 'servers']:
             parser.remove_section(section)
     
     for server in self.serverinfos:
         server.dump(parser)
     
     with open(config, 'w') as fp:
         parser.write(fp)
开发者ID:segfaulthunter,项目名称:pypentago,代码行数:16,代码来源:server.py

示例9: delFiltroFile

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
	def delFiltroFile(self,ip,ALL = False):
		if ALL:
			open('/etc/netcontrol/controle_banda/filtros','w').write('')
			return True
		arquivo = ConfigParser()
		arquivo.read('/etc/netcontrol/controle_banda/filtros')
		if arquivo.has_section(ip):
			arquivo.remove_section(ip)
			arquivo.write( open('/etc/netcontrol/controle_banda/filtros','w') )
			del arquivo
			return True
		else:
			del arquivo
			return False
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:16,代码来源:ControleBanda.py

示例10: delConfig

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
	def delConfig(self, nome, ip,tipo =None):
		#self.decrementaRegras()
		ret  = True
		idem = "%s%s"%( ip.replace('.','_').replace('/','_'), nome.replace( ' ','_' ) )
		open('/tmp/teste','w').write( idem )
		self.gerShaper.delRegra( idem )
		self.arqCnf = tipo == "m" and self.arqMaquina  or self.arqRede
		arquivo = ConfigParser()
		arquivo.read( self.arqCnf )
		if arquivo.has_section(nome):
			arquivo.remove_section(nome)
			arquivo.write( open(self.arqCnf,'w') )
			del arquivo
		ret =  False
		#self.gerShaper.compilaRegras()
		return ret
开发者ID:GabrielDiniz,项目名称:FluxNetControl,代码行数:18,代码来源:GerenciaEtc.py

示例11: remove_watch

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
 def remove_watch(self, name):
     """ Remove a watch from the configuration file. """
     try:
         cfgpr = ConfigParser()
         cfgpr.read(self.file_name)
         cfgpr.remove_section(name)
     except:
         self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__)
         
     try:
         f = open(self.file_name, "w")
         cfgpr.write(f)
     except IOError:
         self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__)
     finally:
         f.close()
开发者ID:nekohayo,项目名称:specto,代码行数:18,代码来源:watch.py

示例12: Profile

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
class Profile(object):
    def __init__(self):
        self.__config = ConfigParser()
        self.__fileName = join(dirname(__file__.split('rexploit')[0]), join("rexploit", "data", "config", "profiles.ini"))

    def getAll(self):
        profiles = {}
        for section in self.__config.sections():
            for (key, value) in self.__config.items(section):
                profiles[section] = value

        return profiles

    def getCommand(self, name):
        try:
            return self.__config.get(str(name), "command")
        except Error:
            return None

    def read(self):
        try:
            self.__config.read(self.__fileName)
            return True, None
        except Exception as e:
            return False, e

    def removeProfile(self, name):
        try:
            self.__config.remove_section(name)
            with open(self.__fileName, "w") as configfile:
                self.__config.write(configfile)
            return True
        except Error:
            return None

    def setProfile(self, name, command):
        if not self.__config.has_section(name):
            self.__config.add_section(name)
            self.__config.set(name, "command", command)
            with open(self.__fileName, "w") as configfile:
                self.__config.write(configfile)
            return True
        else:
            return None
开发者ID:DaniLabs,项目名称:rexploit,代码行数:46,代码来源:profile.py

示例13: __init__

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
class ChirpConfig:
    def __init__(self, basepath, name="chirp.config"):
        self.__basepath = basepath
        self.__name = name

        self._default_section = "global"

        self.__config = ConfigParser()

        cfg = os.path.join(basepath, name)
        if os.path.exists(cfg):
            self.__config.read(cfg)

    def save(self):
        cfg = os.path.join(self.__basepath, self.__name)
        cfg_file = file(cfg, "w")
        self.__config.write(cfg_file)
        cfg_file.close()

    def get(self, key, section, raw=False):
        if not self.__config.has_section(section):
            return None

        if not self.__config.has_option(section, key):
            return None

        return self.__config.get(section, key, raw=raw)

    def set(self, key, value, section):
        if not self.__config.has_section(section):
            self.__config.add_section(section)

        self.__config.set(section, key, value)

    def is_defined(self, key, section):
        return self.__config.has_option(section, key)

    def remove_option(self, section, key):
        self.__config.remove_option(section, key)

        if not self.__config.items(section):
            self.__config.remove_section(section)
开发者ID:gitter-badger,项目名称:chirp_fork,代码行数:44,代码来源:config.py

示例14: createConf

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
def createConf(fpath, ftemplate, remove=[], keep=[], notify=False):
    "Create config file in fpath following the template in ftemplate"
    # Remove from the template the sections in "remove", and if "keep"
    # is used only keep those sections.

    # Create directory and backup if necessary.
    dname = os.path.dirname(fpath)
    if not exists(dname):
        os.makedirs(dname)
    elif exists(fpath):
        if not exists(join(dname, 'backups')):
            os.makedirs(join(dname, 'backups'))
        backup = join(dname, 'backups',
                      '%s.%d' % (basename(fpath), int(time.time())))
        print(yellow("* Creating backup: %s" % backup))
        os.rename(fpath, backup)

    # Read the template configuration file.
    print(yellow("* Creating configuration file: %s" % fpath))
    print("Please edit it to reflect the configuration of your system.\n")
    cf = ConfigParser()
    cf.optionxform = str  # keep case (stackoverflow.com/questions/1611799)
    assert cf.read(ftemplate) != [], 'Missing file: %s' % ftemplate
    for section in set(remove) - set(keep):
        cf.remove_section(section)
    if keep:
        for section in set(cf.sections()) - set(keep):
            cf.remove_section(section)


    # Update with our guesses.
    if 'BUILD' in cf.sections():
        for options in [guessJava(), guessMPI()]:
            for key in options:
                if key in cf.options('BUILD'):
                    cf.set('BUILD', key, options[key])
    # Collecting Protocol Usage Statistics 
    elif 'VARIABLES' in cf.sections():
        checkNotify(cf,notify)

    # Create the actual configuration file.
    cf.write(open(fpath, 'w'))
开发者ID:I2PC,项目名称:scipion,代码行数:44,代码来源:pw_config.py

示例15: execute

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import remove_section [as 别名]
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) != 1:
            self.usage()
            return False

        repoid = non_option_args[0]
        repopath = self.find_repo_file(repoid)
        if repopath == None:
            rucktalk.error("Repository '%s' does not exist" % repoid)
            return False

        parser = ConfigParser()
        parser.read(repopath)
        parser.remove_section(repoid)
        if len(parser.sections()) == 0:
            os.unlink(repopath)
        else:
            parser.write(file(repopath, 'w+'))

        rucktalk.message("--- Successfully removed '%s' ---" % repoid)
开发者ID:zodman,项目名称:PackageKit,代码行数:22,代码来源:ruckcachecmds.py


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