python类dump()的实例源码

hookenv.py 文件源码 项目:charm-plumgrid-gateway 作者: openstack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def yaml(self):
        """Serialize the object to yaml"""
        return yaml.dump(self.data)
hookenv.py 文件源码 项目:charm-plumgrid-gateway 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def save(self):
        """Save this config to disk.

        If the charm is using the :mod:`Services Framework <services.base>`
        or :meth:'@hook <Hooks.hook>' decorator, this
        is called automatically at the end of successful hook execution.
        Otherwise, it should be called directly by user code.

        To disable automatic saves, set ``implicit_save=False`` on this
        instance.

        """
        with open(self.path, 'w') as f:
            json.dump(self, f)
helpers.py 文件源码 项目:charm-plumgrid-gateway 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def store_context(self, file_name, config_data):
        if not os.path.isabs(file_name):
            file_name = os.path.join(hookenv.charm_dir(), file_name)
        with open(file_name, 'w') as file_stream:
            os.fchmod(file_stream.fileno(), 0o600)
            yaml.dump(config_data, file_stream)
postprocess_toc_yml.py 文件源码 项目:azure-docs-sdk-python 作者: MicrosoftDocs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def rewrite_yml(data):
    with io.open('toc.yml', 'w', encoding='utf8') as outfile:
        yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True)
travis_pypi_setup.py 文件源码 项目:rust_pypi_example 作者: mckaymatt 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def save_yaml_config(filepath, config):
    with open(filepath, 'w') as f:
        yaml.dump(config, f, default_flow_style=False)
NNTPSettings.py 文件源码 项目:newsreap 作者: caronc 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def save(self, cfg_file=None):
        """
        Save's configuration back to disk.

        """
        if cfg_file is None:
            cfg_file = self.cfg_file

        else:
            # acquire new configuration path
            cfg_file = abspath(expanduser(cfg_file))

        try:
            with open(cfg_file, 'w') as fp:
                yaml.dump(self.cfg_data, fp, default_flow_style=False)

        except IOError, e:
            logger.debug('%s' % (str(e)))
            logger.error('Failed to write configuration file %s' % (
                cfg_file,
            ))
            return False

        # Update central configuration
        self.cfg_file = cfg_file

        if hasattr(self, '__mask_re'):
            # Presumably something has changed if the user called save so we
            # destroy our cached mask to be safe
            del self.__mask_re

        return True
ymlr.py 文件源码 项目:botterlord 作者: Marchearth 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def insert(data, filename):
    with open(filename, 'w') as yaml_file:
        yaml.dump(data, yaml_file)
ymlr.py 文件源码 项目:botterlord 作者: Marchearth 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def enter_data(cont, valinput, filename): #Cont for container#profile.yml
    stream = open(filename, 'r')
    prof = yaml.load(stream) # Player information is stored here.
    prof[cont] = valinput
    with open(filename, 'w') as yaml_file:
        yaml_file.write(yaml.dump(prof, default_flow_style = False))
ymlr.py 文件源码 项目:botterlord 作者: Marchearth 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_data(cont, filename):
    stream = open(filename, 'r')
    profile = yaml.load(stream) # Player information is stored here.
    data = yaml.dump(profile, default_flow_style = False, encoding=('utf-8'))
    return profile[cont]
travis_pypi_setup.py 文件源码 项目:calendary 作者: DavidHickman 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def save_yaml_config(filepath, config):
    with open(filepath, 'w') as f:
        yaml.dump(config, f, default_flow_style=False)
config.py 文件源码 项目:dnfdragora 作者: manatools 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def saveUserPreferences(self) :
        '''
        write user preferences into the related configuration file
        '''
        with open(self._userPrfesPathName, 'w') as outfile:
            yaml.dump(self._userPrefs, outfile, default_flow_style=False)
config.py 文件源码 项目:Odysseus 作者: OdysseusDev 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def write(data):
        with open(path, 'w') as file:
            yaml.dump(data, file, default_flow_style=True)
import_sources.py 文件源码 项目:quizbot-2017 作者: pycontw 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def load_source(in_f, out_f):
    reader = csv.reader(in_f)
    entries = [make_entry(row) for row in reader]
    yaml.dump(entries, out_f, allow_unicode=True, default_flow_style=False)
usermanager.py 文件源码 项目:ownbot 作者: michaelimfeld 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __save_config(self):
        """Saves the configuration.

            Saves the config attribute to the configuration
            file.
        """
        with open(self.USERS_CONF_PATH, "w+") as config_file:
            config_file.write(yaml.dump(self.__config))
hugepage.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def hugepage_support(user, group='hugetlb', nr_hugepages=256,
                     max_map_count=65536, mnt_point='/run/hugepages/kvm',
                     pagesize='2MB', mount=True, set_shmmax=False):
    """Enable hugepages on system.

    Args:
    user (str)  -- Username to allow access to hugepages to
    group (str) -- Group name to own hugepages
    nr_hugepages (int) -- Number of pages to reserve
    max_map_count (int) -- Number of Virtual Memory Areas a process can own
    mnt_point (str) -- Directory to mount hugepages on
    pagesize (str) -- Size of hugepages
    mount (bool) -- Whether to Mount hugepages
    """
    group_info = add_group(group)
    gid = group_info.gr_gid
    add_user_to_group(user, group)
    if max_map_count < 2 * nr_hugepages:
        max_map_count = 2 * nr_hugepages
    sysctl_settings = {
        'vm.nr_hugepages': nr_hugepages,
        'vm.max_map_count': max_map_count,
        'vm.hugetlb_shm_group': gid,
    }
    if set_shmmax:
        shmmax_current = int(check_output(['sysctl', '-n', 'kernel.shmmax']))
        shmmax_minsize = bytes_from_string(pagesize) * nr_hugepages
        if shmmax_minsize > shmmax_current:
            sysctl_settings['kernel.shmmax'] = shmmax_minsize
    sysctl.create(yaml.dump(sysctl_settings), '/etc/sysctl.d/10-hugepage.conf')
    mkdir(mnt_point, owner='root', group='root', perms=0o755, force=False)
    lfstab = fstab.Fstab()
    fstab_entry = lfstab.get_entry_by_attr('mountpoint', mnt_point)
    if fstab_entry:
        lfstab.remove_entry(fstab_entry)
    entry = lfstab.Entry('nodev', mnt_point, 'hugetlbfs',
                         'mode=1770,gid={},pagesize={}'.format(gid, pagesize), 0, 0)
    lfstab.add_entry(entry)
    if mount:
        fstab_mount(mnt_point)
hookenv.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def yaml(self):
        """Serialize the object to yaml"""
        return yaml.dump(self.data)
hookenv.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def save(self):
        """Save this config to disk.

        If the charm is using the :mod:`Services Framework <services.base>`
        or :meth:'@hook <Hooks.hook>' decorator, this
        is called automatically at the end of successful hook execution.
        Otherwise, it should be called directly by user code.

        To disable automatic saves, set ``implicit_save=False`` on this
        instance.

        """
        with open(self.path, 'w') as f:
            json.dump(self, f)
helpers.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def store_context(self, file_name, config_data):
        if not os.path.isabs(file_name):
            file_name = os.path.join(hookenv.charm_dir(), file_name)
        with open(file_name, 'w') as file_stream:
            os.fchmod(file_stream.fileno(), 0o600)
            yaml.dump(config_data, file_stream)


问题


面经


文章

微信
公众号

扫码关注公众号