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


Python ConfigParser.delete方法代碼示例

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


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

示例1: Config

# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import delete [as 別名]

#.........這裏部分代碼省略.........
                        self.deprecatediDevices.remove(key.lower())

        # Load the "user" section
        if self.configParser.has_section('user'):
            if self.configParser.user.has_option('editorMode'):
                self.editorMode = self.configParser.user.editorMode
            if self.configParser.user.has_option('docType'):
                self.docType = self.configParser.user.docType
                common.setExportDocType(self.configParser.user.docType)
            if self.configParser.user.has_option('defaultStyle'):
                self.defaultStyle= self.configParser.user.defaultStyle
            if self.configParser.user.has_option('styleSecureMode'):
                self.styleSecureMode= self.configParser.user.styleSecureMode
            if self.configParser.user.has_option('internalAnchors'):
                self.internalAnchors = self.configParser.user.internalAnchors
            if self.configParser.user.has_option('lastDir'):
                self.lastDir = self.configParser.user.lastDir
            if self.configParser.user.has_option('showPreferencesOnStart'):
                self.showPreferencesOnStart = self.configParser.user.showPreferencesOnStart
            if self.configParser.user.has_option('showIdevicesGrouped'):
                self.showIdevicesGrouped = self.configParser.user.showIdevicesGrouped
            if self.configParser.user.has_option('locale'):
                self.locale = self.configParser.user.locale
                return
        self.locale = chooseDefaultLocale(self.localeDir)

    def onWrite(self, configParser):
        """
        Called just before the config file is written.
        We use it to fill out any settings that are stored here and 
        not in the config parser itself
        """
        # Recent projects
        self.configParser.delete('recent_projects')
        recentProjectsSection = self.configParser.addSection('recent_projects')
        for num, path in enumerate(self.recentProjects):
            recentProjectsSection[str(num)] = path

    def setupLogging(self):
        """
        setup logging file
        """
        try:
            hdlr = RotatingFileHandler(self.configDir/'exe.log', 'a', 
                                       500000, 10)
            hdlr.doRollover()
        except OSError:
            # ignore the error we get if the log file is logged
            hdlr = logging.FileHandler(self.configDir/'exe.log')

        format = "%(asctime)s %(name)s %(levelname)s %(message)s"
        log    = logging.getLogger()
        hdlr.setFormatter(logging.Formatter(format))
        log.addHandler(hdlr)

        loggingLevels = {"DEBUG"    : logging.DEBUG,
                         "INFO"     : logging.INFO,
                         "WARNING"  : logging.WARNING,
                         "ERROR"    : logging.ERROR,
                         "CRITICAL" : logging.CRITICAL }

    
        if self.configParser.has_section('logging'):
            for logger, level in self.configParser._sections["logging"].items():
                if logger == "root":
                    logging.getLogger().setLevel(loggingLevels[level])
開發者ID:kohnle-lernmodule,項目名稱:exe201based,代碼行數:70,代碼來源:config.py

示例2: __init__

# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import delete [as 別名]

#.........這裏部分代碼省略.........
                value = value.strip().lower()
                if value == "0" or value == "no" or value == "false" or \
                        value == "off":
                    self.hiddeniDevices.append(key.lower())

        #self.deprecatediDevices = [ "flash with text", "flash movie", ...]
        # and UN-Load from the list of "deprecated" iDevices
        if self.configParser.has_section('deprecated'):
            deprecatedSection = self.configParser.deprecated
            for key,value in deprecatedSection.items():
                # emulate standard library's getboolean()
                value = value.strip().lower()
                if value == "1" or value == "yes" or value == "true" or \
                        value == "on":
                    if key.lower() in self.deprecatediDevices:
                        self.deprecatediDevices.remove(key.lower())

        # Load the "user" section
        if self.configParser.has_section('user'):
            if self.configParser.user.has_option('internalAnchors'):
                self.internalAnchors = self.configParser.user.internalAnchors
            if self.configParser.user.has_option('locale'):
                self.locale = self.configParser.user.locale
                return
        self.locale = chooseDefaultLocale(self.localeDir)

    def onWrite(self, configParser):
        """
        Called just before the config file is written.
        We use it to fill out any settings that are stored here and 
        not in the config parser itself
        """
        # Recent projects
        self.configParser.delete('recent_projects')
        recentProjectsSection = self.configParser.addSection('recent_projects')
        for num, path in enumerate(self.recentProjects):
            recentProjectsSection[str(num)] = path

    def setupLogging(self):
        """
        setup logging file
        """
        try:
            hdlr = RotatingFileHandler(self.configDir/'exe.log', 'a', 
                                       500000, 10)
            hdlr.doRollover()
        except OSError:
            # ignore the error we get if the log file is logged
            hdlr = logging.FileHandler(self.configDir/'exe.log')

        format = "%(asctime)s %(name)s %(levelname)s %(message)s"
        log    = logging.getLogger()
        hdlr.setFormatter(logging.Formatter(format))
        log.addHandler(hdlr)

        loggingLevels = {"DEBUG"    : logging.DEBUG,
                         "INFO"     : logging.INFO,
                         "WARNING"  : logging.WARNING,
                         "ERROR"    : logging.ERROR,
                         "CRITICAL" : logging.CRITICAL }

    
        if self.configParser.has_section('logging'):
            for logger, level in self.configParser._sections["logging"].items():
                if logger == "root":
                    logging.getLogger().setLevel(loggingLevels[level])
開發者ID:KatiaBorges,項目名稱:exeLearning,代碼行數:70,代碼來源:config.py

示例3: __init__

# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import delete [as 別名]

#.........這裏部分代碼省略.........
            self.configDir.mkdir()
        self.recentProjects = []
        if self.configParser.has_section('recent_projects'):
            recentProjectsSection = self.configParser.recent_projects
            for key, path in recentProjectsSection.items():
                self.recentProjects.append(path)
        self.hiddeniDevices = []
        if self.configParser.has_section('idevices'):
            idevicesSection = self.configParser.idevices
            for key,value in idevicesSection.items():
                value = value.strip().lower()
                if value == "0" or value == "no" or value == "false" or \
                        value == "off":
                    self.hiddeniDevices.append(key.lower())
        if self.configParser.has_section('deprecated'):
            deprecatedSection = self.configParser.deprecated
            for key,value in deprecatedSection.items():
                value = value.strip().lower()
                if value == "1" or value == "yes" or value == "true" or \
                        value == "on":
                    if key.lower() in self.deprecatediDevices:
                        self.deprecatediDevices.remove(key.lower())
        if self.configParser.has_section('user'):
            if self.configParser.user.has_option('locale'):
                self.locale = self.configParser.user.locale
                return
        self.locale = chooseDefaultLocale(self.localeDir)
    def onWrite(self, configParser):
        """
        Called just before the config file is written.
        We use it to fill out any settings that are stored here and 
        not in the config parser itself
        """
        self.configParser.delete('recent_projects')
        recentProjectsSection = self.configParser.addSection('recent_projects')
        for num, path in enumerate(self.recentProjects):
            recentProjectsSection[str(num)] = path
    def setupLogging(self):
        """
        setup logging file
        """
        try:
            hdlr = RotatingFileHandler(self.configDir/'exe.log', 'a', 
                                       500000, 10)
            hdlr.doRollover()
        except OSError:
            hdlr = logging.FileHandler(self.configDir/'exe.log')
        format = "%(asctime)s %(name)s %(levelname)s %(message)s"
        log    = logging.getLogger()
        hdlr.setFormatter(logging.Formatter(format))
        log.addHandler(hdlr)
        loggingLevels = {"DEBUG"    : logging.DEBUG,
                         "INFO"     : logging.INFO,
                         "WARNING"  : logging.WARNING,
                         "ERROR"    : logging.ERROR,
                         "CRITICAL" : logging.CRITICAL }
        if self.configParser.has_section('logging'):
            for logger, level in self.configParser._sections["logging"].items():
                if logger == "root":
                    logging.getLogger().setLevel(loggingLevels[level])
                else:
                    logging.getLogger(logger).setLevel(loggingLevels[level])
        log.info("************** eXe logging started **************")
        log.info("configPath  = %s" % self.configPath)
        log.info("exePath     = %s" % self.exePath)
        log.info("browserPath = %s" % self.browserPath)
開發者ID:,項目名稱:,代碼行數:70,代碼來源:

示例4: TestConfigParser

# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import delete [as 別名]

#.........這裏部分代碼省略.........
        self.c.set('main', 'testing', 'ok')
        self.c.write('temp.ini')
        file_ = open('temp.ini')
        try:
            data = file_.read()
            assert data == '[main]\ntesting = ok', data
        finally:
            file_.close()
            os.remove('temp.ini')

    def testGet(self):
        """Tests the get method"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c.get('main', 'testing') == 'false'
        assert self.c.get('main', 'not exists', 'default') == 'default'
        self.failUnlessRaises(ValueError, self.c.get, 'main', 'not exists')

    def testSet(self):
        """Test the set method"""
        file_ = testFile()
        self.c.read(file_)
        # An existing option
        self.c.set('main', 'testing', 'perhaps')
        assert self.c._sections['main']['testing'] == 'perhaps'
        # A new and numeric option
        self.c.set('main', 'new option', 4.1)
        self.assertEquals(self.c._sections['main']['new option'], '4.1')
        # A new option in a new section
        self.c.set('new section', 'new option', 4.1)
        assert self.c._sections['new section']['new option'] == '4.1'

    def testDel(self):
        """Should be able to delete a section and/or a value in a section"""
        file_ = testFile()
        self.c.read(file_)
        assert self.c._sections['main']['level'] == '5'
        self.c.delete('main', 'level')
        assert not self.c._sections['main'].has_key('level')
        self.c.delete('main')
        assert not self.c._sections.has_key('main')

    def testShortening(self):
        """There was a bug (Issue 66) where when a longer name was read
        and a shorter name was written, the extra characters of the 
        longer name would remain in the entry"""
        file_ = open('temp.ini', 'w')
        file_.write(TEST_TEXT)
        file_.close()
        self.c.read('temp.ini')
        self.c.set('second', 'available', 'abcdefghijklmnop')
        self.c.write('temp.ini')
        c2 = ConfigParser()
        c2.read('temp.ini')
        c2.set('second', 'available', 'short')
        c2.write('temp.ini')
        self.c.read('temp.ini')
        assert self.c.get('second', 'available', '') == 'short', \
            self.c.get('second', 'available', '')

    def testUnicodeSet(self):
        """
        Should be able to set unicode option values
        with both python internal unicode strings
        or raw string containing utf8 encoded data
        """
開發者ID:,項目名稱:,代碼行數:70,代碼來源:


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