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


Python ConfigParser.write方法代码示例

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


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

示例1: write

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import write [as 别名]
    def write(self,
              path=None,
              dependencies = None,
              src_uri = None,
              description = None,
              install_method = None,
              src_type = None,
              url = None,
              revision = None,
              category = None,
              src_opts = None,
              src_md5 = None,
              python = None,
              scm_branch = None,
             ):
        """Store/Update the minibuild config
        """
        to_write = OrderedDict(
            [('dependencies', dependencies),
            ('src_uri', src_uri),
            ('install_method', install_method),
            ('src_type', src_type),
            ('revision', revision),
            ('category', category),
            ('description', description),
            ('src_md5', src_md5),
            ('url', url),
            ('src_opts', src_opts),
            ('python', python),
            ('scm_branch', scm_branch),]
        )

        # open config
        if not path:
            path = self.path
        shutil.copy2(path, path+'.sav')
        wconfig = WritableConfigParser()
        wconfig.read(path)

        for metadata in to_write:
            value = to_write[metadata]
            if isinstance(value, list):
                if len(value) < 1:
                    value = None
                else:
                    value =  ' '.join(value)
            if value is not None:
                wconfig.set('minibuild' , metadata, value)

        # write back cofig
        fic = open(path, 'w')
        wconfig.write(fic)
        fic.flush()
        fic.close()
        newline(path)

        # reload minibuild
        self.load()
开发者ID:minitage,项目名称:minitage,代码行数:60,代码来源:objects.py

示例2: write

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import write [as 别名]
 def write(self):
     if not self.manage_repos:
         log.debug("Skipping write due to manage_repos setting: %s" %
                 self.path)
         return
     f = open(self.path, 'w')
     tidy_writer = TidyWriter(f)
     ConfigParser.write(self, tidy_writer)
     tidy_writer.close()
     f.close()
开发者ID:splice,项目名称:subscription-manager,代码行数:12,代码来源:repolib.py

示例3: _apply

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import write [as 别名]
    def _apply():
        debug('Write ini settings to %s' % filename)
        debug(config)

        cfg = ConfigParser()
        cfg.read(filename)
        for section, values in config.items():
            if not cfg.has_section(section):
                if strict_sections:
                    raise Exception('No section %s in ini file %s' % (section, filename))
                else:
                    cfg.add_section(section)

            for key, val in values.items():
                cfg.set(section, key, val)

        with open(filename, 'w') as configfile:
            cfg.write(configfile)

        event(on_apply)
开发者ID:pywizard,项目名称:pywizard,代码行数:22,代码来源:resource_config.py

示例4: archive_inv

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import write [as 别名]
def archive_inv(gameDir, dummyPath, game='FO3', mode=True):
	'''Apply ArchiveInvalidationInvalidated.'''
	if mode:
		if game == 'NV':
			try:
				ini = ConfigParser()
				ini.read(os.environ['USERPROFILE'] + '\\My Games\\FalloutNV\\Fallout.ini')
				ini.set('Archive', 'bInvalidateOlderFiles', '1')
				ini.set('Archive', 'SArchiveList', 'Dummy.bsa,' + ini.get('Archive', 'SArchiveList'))
				
				iniFile = open(os.environ['USERPROFILE'] + '\\My Games\\FalloutNV\\Fallout.ini', 'w')
				ini.write(iniFile)
				
				bsa = open(dummyPath, 'rb').read()
				dummy = open(gameDir + '\\Data\\Dummy.bsa', 'wb')
				dummy.write(bsa)
				dummy.close()
				
				return True
			except IOError:
				return False
开发者ID:Argomirr,项目名称:The-Load-Order-Sorting-Tool,代码行数:23,代码来源:meat.py

示例5: RepoFile

# 需要导入模块: from iniparse import ConfigParser [as 别名]
# 或者: from iniparse.ConfigParser import write [as 别名]
class RepoFile(object):
    """
    Represents a .repo file, including operations to manipulate its repositories and
    CRUD operations on the file itself.
    """

    # Be careful when changing the spacing below, the parser takes issue when the comment
    # indicator isn't in the first column. The blank line at the end is fine though.
    FILE_HEADER = """#
# Pulp Repositories
# Managed by Pulp client
#

"""

    def __init__(self, filename):
        """
        @param filename: absolute path to the repo file; the repo file does not need to
                         exist at the time of instantiation, the save method will write it
                         out if it doesn't
        @type  filename: string; may not be None

        @raise ValueError: if filename is missing
        """
        if filename is None:
            raise ValueError("Filename must be specified when creating a RepoFile")

        self.filename = filename
        self.parser = ConfigParser()

    # -- file manipulation ------------------------------------------------------------

    def delete(self):
        """
        If the repo file exists, it will be deleted. If not, this method does nothing.

        @raise Exception: if there is an error during the delete
        """
        if os.path.exists(self.filename):
            os.unlink(self.filename)

    def load(self, allow_missing=True):
        """
        Loads the repo file.

        @param allow_missing: if True, this call will not throw an error if the file cannot
                              be found; defaults to True
        @type  allow_missing: bool

        @raise Exception: if there is an error during the read
        """
        if allow_missing and not os.path.exists(self.filename):
            return

        r = Reader(self.filename)
        self.parser.readfp(r)

    def save(self):
        """
        Saves the current repositories to the repo file.

        @raise Exception: if there is an error during the write
        """
        # If the file doesn't exist, initialize with Pulp header
        first_write = not os.path.exists(self.filename)

        f = open(self.filename, "w")

        if first_write:
            f.write(RepoFile.FILE_HEADER)

        # Write the contents of the parser
        self.parser.write(f)

        f.close()

    # -- contents manipulation ------------------------------------------------------------

    def add_repo(self, repo):
        """
        Adds a new repo to this object, however the file is not saved.

        This is not saved as an object reference, so future changes to the passed in
        repo will not be captured in this RepoFile instance. If changes are made to
        the original Repo object, it must be passed into the RepoFile instance through
        update_repo in order for the changes to be captured.

        @param repo: repo to add; may not be None
        @type  repo: L{Repo}
        """
        self.parser.add_section(repo.id)
        self._repo_to_parser(repo)

    def remove_repo_by_name(self, repo_name):
        """
        Removes the repo with the given name. If the repo does not exist, this
        method does nothing.

        @param repo: identifies the repo to remove
        @type  repo: string
#.........这里部分代码省略.........
开发者ID:pgustafs,项目名称:pulp_rpm,代码行数:103,代码来源:repo_file.py


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