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


Python ConfigParser.write方法代码示例

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


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

示例1: hour_set

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
 def hour_set(arg, hour):
     cp = ConfigParser()
     cp.read("conf.txt")
     cp.set("pills_must_be_taken", "hour", hour)
     hd = open("conf.txt", "w")
     cp.write(hd)
     hd.close()
开发者ID:unibz-makerspace,项目名称:osp-007-pills,代码行数:9,代码来源:functions.py

示例2: auth_springpad_client

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
def auth_springpad_client(config_file=None):
    """
    Auth the application to make to be allowed to access to user's springpad
    account. If not a valid config file is provided it will prompt the user to
    visit an url in order to allow the application to access to its account
    and it will store authentication details in `config_file`.
    args:
        config_file: the configuration file path to be used. If it is not
            provided, '~/.springpad' will be used instead.
    returns: SpringpadClient instance to interact with the authenticated
        account.
    """
    config_file = config_file or os.path.expanduser("~/.springpad")
    config = ConfigParser()
    config.read([config_file])
    token = config.get("access", "token") if config.has_option("access", "token") else None
    if token:
        token = oauth.OAuthToken.from_string(token)

    client = SpringpadClient(SPRINGPAD_CONSUMER_KEY, SPRINGPAD_CONSUMER_PRIVATE, token)

    if not client.access_token:
        req_token = client.get_request_token()
        print "Please grant access to your springpad account in the following url:\n"
        print "http://springpad.com/api/oauth-authorize?{0}\n".format(req_token)
        print "Once authorized, press intro to continue:",
        raw_input()
        client.access_token = client.get_access_token(req_token)
        config.add_section("access")
        config.set("access", "token", str(client.access_token))
        with open(os.path.expanduser(config_file), "w") as cf:
            config.write(cf)
    return client
开发者ID:sigilioso,项目名称:svimpad,代码行数:35,代码来源:springpad_client.py

示例3: __init__

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [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: write_ini_config_file

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
    def write_ini_config_file(self, command, data, client):
        """\
        Write the new command configuration in the plugin configuration file
        """
        try:

            # read the config file
            config = ConfigParser()
            config.read(command.plugin.config.fileName)

            # if there is no commands section
            if not config.has_section('commands'):
                raise NoSectionError('could not find <commands> section in '
                                     'plugin <%s> config file' % data['plugin_name'])

            # remove the old entry
            found = False
            for temp in config.options('commands'):
                search = temp.split('-')[0]
                if search == command.command:
                    config.remove_option('commands', temp)
                    found = True

            # set the new command option value
            config.set('commands', data['command_name'], data['command_level'])
            self.debug('%s command <%s> in plugin <%s> config file' % ('updated' if found else 'created new entry for',
                                                                       command.command, data['plugin_name']))

            # write the updated configuration file
            with open(command.plugin.config.fileName, 'wb') as configfile:
                config.write(configfile)

        except (IOError, NoSectionError), e:
            self.warning('could not change plugin <%s> config file: %s' % (data['plugin_name'], e))
            client.message('^7could not change plugin ^1%s ^7config file' % data['plugin_name'])
开发者ID:danielepantaleone,项目名称:b3-plugin-cmdmanager,代码行数:37,代码来源:cmdmanager.py

示例5: initConfig

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [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 write [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 write [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: __init__

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
class RedirectConfig:
    def __init__(self, filename):
        self.parser = ConfigParser()
        self.parser.read(filename)
        self.filename = filename
        self.logger = logger.get_logger('insider.RedirectConfig')

    def update(self, domain, api_url):
        self.logger.info('settig domain={0}, api_url={1}'.format(domain, api_url))
        if not self.parser.has_section('redirect'):
            self.parser.add_section('redirect')

        self.parser.set('redirect', 'domain', domain)
        self.parser.set('redirect', 'api_url', api_url)
        self._save()

    def get_domain(self):
        return self.parser.get('redirect', 'domain')

    def get_api_url(self):
        return self.parser.get('redirect', 'api_url')

    def _save(self):
        self.logger.info('saving config={0}'.format(self.filename))
        with open(self.filename, 'wb') as file:
            self.parser.write(file)
开发者ID:syncloud-old,项目名称:insider,代码行数:28,代码来源:config.py

示例9: SetupConfig

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
class SetupConfig(object):
    """Wrapper around the setup.cfg file if available.

    Mostly, this is here to cleanup setup.cfg from these settings:

    [egg_info]
    tag_build = dev
    tag_svn_revision = true
    """

    config_filename = SETUP_CONFIG_FILE

    def __init__(self):
        """Grab the configuration (overridable for test purposes)"""
        # If there is a setup.cfg in the package, parse it
        if not os.path.exists(self.config_filename):
            self.config = None
            return
        self.config = ConfigParser()
        self.config.read(self.config_filename)

    def has_bad_commands(self):
        if self.config is None:
            return False
        if not self.config.has_section('egg_info'):
            # bail out early as the main section is not there
            return False
        bad = False
        # Check 1.
        if self.config.has_option('egg_info', 'tag_build'):
            # Might still be empty.
            value = self.config.get('egg_info', 'tag_build')
            if value:
                logger.warn("%s has [egg_info] tag_build set to %r",
                            self.config_filename, value)
                bad = True
        # Check 2.
        if self.config.has_option('egg_info', 'tag_svn_revision'):
            if self.config.getboolean('egg_info', 'tag_svn_revision'):
                value = self.config.get('egg_info', 'tag_svn_revision')
                logger.warn("%s has [egg_info] tag_svn_revision set to %r",
                            self.config_filename, value)
                bad = True
        return bad

    def fix_config(self):
        if not self.has_bad_commands():
            logger.warn("Cannot fix already fine %s.", self.config_filename)
            return
        if self.config.has_option('egg_info', 'tag_build'):
            self.config.set('egg_info', 'tag_build', '')
        if self.config.has_option('egg_info', 'tag_svn_revision'):
            self.config.set('egg_info', 'tag_svn_revision', 'false')
        new_setup = open(self.config_filename, 'wb')
        try:
            self.config.write(new_setup)
        finally:
            new_setup.close()
        logger.info("New setup.cfg contents:")
        print ''.join(open(self.config_filename).readlines())
开发者ID:AlexisHuet,项目名称:zest.releaser,代码行数:62,代码来源:pypi.py

示例10: configure_manager

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
def configure_manager(manager_config_path,
                      manager_config):
    '''Sets config defaults and creates the config file'''
    _, temp_config = tempfile.mkstemp()
    config = ConfigParser()

    config.add_section('Credentials')
    config.set('Credentials', 'subscription_id',
               manager_config['subscription_id'])
    config.set('Credentials', 'tenant_id',
               manager_config['tenant_id'])
    config.set('Credentials', 'client_id',
               manager_config['client_id'])
    config.set('Credentials', 'client_secret',
               manager_config['client_secret'])

    config.add_section('Azure')
    config.set('Azure', 'location',
               manager_config['location'])

    with open(temp_config, 'w') as temp_config_file:
        config.write(temp_config_file)

    fabric.api.sudo('mkdir -p {0}'.
                    format(os.path.dirname(manager_config_path)))
    fabric.api.put(temp_config,
                   manager_config_path,
                   use_sudo=True)
开发者ID:lexleogryfon,项目名称:cloudify-manager-blueprints,代码行数:30,代码来源:configure.py

示例11: _load_config

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
    def _load_config(self):
        config_file = os.path.expanduser(self.filename)
        self.log.debug("Enter _load_config(%s)" % config_file)

        config = ConfigParser()
        Configuration.changed_settings = False  # track changes

        config.read(config_file)
        if config.has_section('settings'):
            if config.has_option('settings', 'destination'):
                self.set_destination(config.get('settings', 'destination'))
            if config.has_option('settings', 'date_pattern'):
                self.date_pattern = config.get('settings', 'date_pattern', True)
            if config.has_option('settings', 'tempdir'):
                self.tempdir = os.path.abspath(os.path.expanduser(config.get('settings', 'tempdir')))
                if not os.path.exists(self.tempdir):
                    os.makedirs(self.tempdir)
            if config.has_option('settings', 'comment_pattern'):
                pattern = config.get('settings', 'comment_pattern', True)
                pattern = re.sub(r'%([a-z_][a-z_]+)', r'%(\1)s', pattern)
                self.comment_pattern = pattern
        self._read_feed_settings(config)
        self._add_stations(config)
        if Configuration.changed_settings:
            import shutil
            shutil.copy(config_file, config_file + '.bak')
            with open(config_file, 'w') as file:
                config.write(file)
            print("WARNING: Saved the old version of config file as '%s.bak' and updated configuration." % (config_file))
开发者ID:pimpmypixel,项目名称:capturadio,代码行数:31,代码来源:__init__.py

示例12: run_gui

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
def run_gui(input_start_page, end_page, strict):
    """ Batch cleans the pages in text/clean."""
    config = ConfigParser()
    config.read('book.cnf')
    if strict and \
        config.has_option('process', 'last_strict_page'):
        hold_page = config.getint('process', 'last_strict_page')
    elif not strict and \
        config.has_option('process', 'last_checked_page'):
        hold_page = config.getint('process', 'last_checked_page')
    else:
        hold_page = input_start_page
    print hold_page
    if input_start_page == 0:
        start_page = hold_page
    else:
        start_page = input_start_page
    lang = get_lang()
    lm = line_manager.LineManager(
        spell_checker.AspellSpellChecker(lang, './dict.{}.pws'.format(lang)),
        start_page,
        end_page
        )
    lm.load('text/clean')
    app = gui.main(lm, strict)
    lm.write_pages('text/clean', False)

    if strict and int(app.last_page) >= hold_page:
        config.set('process', 'last_strict_page', app.last_page)
    elif not strict and int(app.last_page) >= hold_page:
        config.set('process', 'last_checked_page', app.last_page)
    with open('book.cnf', 'wb') as f:
        config.write(f)
开发者ID:porcpine1967,项目名称:ocr-proofreader,代码行数:35,代码来源:ocr.py

示例13: minutes_set

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
 def minutes_set(arg, mins):
     cp = ConfigParser()
     cp.read("conf.txt")
     cp.set("pills_must_be_taken", "minutes", mins)
     hd = open("conf.txt", "w")
     cp.write(hd)
     hd.close()
开发者ID:unibz-makerspace,项目名称:osp-007-pills,代码行数:9,代码来源:functions.py

示例14: save_action_to_file

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [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

示例15: buttonExportSensors_clicked_cb

# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import write [as 别名]
	def buttonExportSensors_clicked_cb(self, widget):
		treemodel, treeiter = self.treeviewSensors.get_selection().get_selected()
		if treeiter:
			sensorNumber = int(treemodel.get_path(treeiter)[0])
			
			dialog = gtk.FileChooserDialog("Salvar..", None, gtk.FILE_CHOOSER_ACTION_SAVE,
			(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK))		
			dialog.set_default_response(gtk.RESPONSE_OK)
			dialog.set_current_folder(dialog.get_current_folder() + "/sensors/")
			dialog.set_current_name(self.sensorTypes[sensorNumber].name + ".sensor")
			response = dialog.run()
			if response == gtk.RESPONSE_OK:
				filename = dialog.get_filename()
				FILE = open(filename, "w")
			
				c = ConfigParser()
				
				
				for i in  range(len(self.sensorTypes[sensorNumber].points) - 1, -1, -1):
					c.add_section("POINT " + str(i))
					c.set("POINT " + str(i), "x", self.sensorTypes[sensorNumber].points[i][0])
					c.set("POINT " + str(i), "y", self.sensorTypes[sensorNumber].points[i][1])
					
					
				c.add_section("SENSOR")
				c.set("SENSOR", "name", self.sensorTypes[sensorNumber].name)
				c.set("SENSOR", "unit", self.sensorTypes[sensorNumber].unit)
				c.set("SENSOR", "description", self.sensorTypes[sensorNumber].description)
				
				c.write(FILE)
				FILE.close()
			dialog.destroy()
开发者ID:lucastanure,项目名称:GoGo-Real-GTk,代码行数:34,代码来源:SensorsTab.py


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