• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python toml.load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中toml.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: read_cargo_toml

def read_cargo_toml(key, manifest=None):
    """Read a value from Cargo.toml manifest.

    :param key: Key to read from [package], or entire path to a key.
                It may contain dots.
    :param manifest: Optional path to the manifest,
                     or a file-like object with it opened

    :return: The value
    """
    if not isinstance(key, (list, tuple)):
        key = (key,) if key.startswith('package.') else ('package', key)
    key = list(chain.from_iterable(k.split('.') for k in key))
    if not key:
        raise ValueError("key must not be empty")

    # Read the content of Cargo.toml.
    manifest = manifest or Path.cwd() / 'Cargo.toml'
    if hasattr(manifest, 'read'):
        content = toml.load(manifest)
    else:
        manifest = Path(manifest)
        with manifest.open() as f:
            content = toml.load(f)

    # Get the value.
    value = content
    for k in key:
        value = value[k]
    return value
开发者ID:Xion,项目名称:gisht,代码行数:30,代码来源:util.py


示例2: _load_sim_file

 def _load_sim_file(self, sim_file):
     '''Load, parse and expand the simulation file.'''
     sim_fname = os.path.realpath(sim_file)
     # Load the master file
     path, _ = os.path.split(sim_fname)
     with open(sim_fname) as file_:
         sim = toml.load(file_)
     # Expand the building
     building_fname = '{}.toml'.format(sim['building']['model'])
     with open(os.path.join(path, 'buildings', building_fname)) as file_:
         sim['building'] = toml.load(file_)['floor']
     # Expand the lifts
     processed_lifts = []
     for lift in sim['lifts']:
         fname = '{}.toml'.format(lift['model'])
         with open(os.path.join(path, 'lifts', fname)) as file_:
             exp = toml.load(file_)
         exp['bottom_floor_number'], exp['top_floor_number'] = lift['range']
         exp['location'] = lift['location']
         exp['open_doors'] = lift['open_doors']
         processed_lifts.append(exp)
     sim['lifts'] = processed_lifts
     # If provided, initialise the random seed
     try:
         seed(sim['people']['seed'])
     except KeyError:
         print('no seed')
         pass
     self.description = sim
开发者ID:quasipedia,项目名称:lifts,代码行数:29,代码来源:simulation.py


示例3: test_test_mode

def test_test_mode() -> None:
    '''
    Tests server and client by starting the server in a thread, then
    requesting meta and sensor data. Asserts that this data is in the
    correct format and returns None on success.
    '''
    print('Finding default configs...')
    if os.path.isdir('docs'):
        server_config_file = 'docs/sensed-config.sample.toml'
        client_config_file = 'docs/senselog-config.sample.toml'
    elif os.path.isdir('../docs'):
        server_config_file = '../docs/sensed-config.sample.toml'
        client_config_file = '../docs/senselog-config.sample.toml'

    print('Running sensed test mode test...')

    with open(server_config_file) as f:
        server_config = DotMap(toml.load(f))
    dt_sensor = datetime.Sensor(server_config)
    ni_sensor = netifaces.Sensor(server_config)
    cam_sensor = camera.Sensor(server_config)
    hat_sensor = hat.Sensor(server_config)
    server_config.sensors = DotMap({'datetime': dt_sensor,
                                    'netifaces': ni_sensor,
                                    'camera': cam_sensor,
                                    'hat': hat_sensor})
    server = socketserver.UDPServer((server_config.sensed.host,
                                    server_config.sensed.port),
                                    SensedServer)
    server.sensors = server_config.sensors
    server.config = server_config

    server_thread = threading.Thread(target=server.serve_forever)
    server_thread.daemon = True
    server_thread.start()

    with open(client_config_file) as f:
        client_config = DotMap(toml.load(f))
    client = SensedClient(client_config)

    meta = client.get_all_meta()
    sensors = client.get_all_sensors()

    assert isinstance(meta, list)
    assert isinstance(meta[0], dict)
    assert isinstance(sensors, list)
    assert isinstance(sensors[0], dict)

    print('Packet test passed. Shutting down...')

    server.shutdown()

    print('Test complete.')
开发者ID:sli,项目名称:sensed,代码行数:53,代码来源:sensed_tests.py


示例4: read_user_state

async def read_user_state(path):
    global prev
    global manual
    book_files = utility.find_files(path, ('brf', 'pef'))
    main_toml = os.path.join(path, 'sd-card', USER_STATE_FILE)
    current_book = manual_filename
    if os.path.exists(main_toml):
        main_state = toml.load(main_toml)
        if 'current_book' in main_state:
            current_book = main_state['current_book']
            if not current_book == manual_filename:
                current_book = os.path.join(path, current_book)
        if 'current_language' in main_state:
            current_language = main_state['current_language']
        else:
            current_language = 'en_GB:en'
    else:
        current_language = 'en_GB:en'

    manual_toml = os.path.join(path, to_state_file(manual_filename))
    if os.path.exists(manual_toml):
        t = toml.load(manual_toml)
        if 'current_page' in t:
            manual = manual._replace(page_number=t['current_page'] - 1)
        if 'bookmarks' in t:
            manual = manual._replace(bookmarks=tuple(sorted(manual.bookmarks + tuple(
                bm - 1 for bm in t['bookmarks']))))
    else:
        manual = Manual.create(current_language)

    books = OrderedDict({manual_filename: manual})
    for book_file in book_files:
        toml_file = to_state_file(book_file)
        book = BookFile(filename=book_file, width=40, height=9)
        if os.path.exists(toml_file):
            t = toml.load(toml_file)
            if 'current_page' in t:
                book = book._replace(page_number=t['current_page'] - 1)
            if 'bookmarks' in t:
                book = book._replace(bookmarks=tuple(sorted(book.bookmarks + tuple(
                    bm - 1 for bm in t['bookmarks']))))
        books[book_file] = book
    books[cleaning_filename] = CleaningAndTesting.create()

    if current_book not in books:
        current_book = manual_filename

    user_state = frozendict(books=FrozenOrderedDict(
        books), current_book=current_book, current_language=current_language)
    prev = user_state
    return user_state.copy(books=user_state['books'])
开发者ID:Bristol-Braille,项目名称:canute-ui,代码行数:51,代码来源:initial_state.py


示例5: loadconfig

def loadconfig(filename):
    try:
        config=toml.load(filename)
    except IOError:
        with open(filename,"w") as f: pass
        config={}
    return config
开发者ID:KSFT,项目名称:KCraft,代码行数:7,代码来源:configloader.py


示例6: read_config

 def read_config(self):
     try:
         config_data = toml.load(self.config_file)
     except Exception as e:
         raise ConfigError(self.config_file, e)
     self._validate_config(config_data)
     self._config_data = config_data
开发者ID:HubbeKing,项目名称:Hubbot_Twisted,代码行数:7,代码来源:config.py


示例7: load

    def load(cls, fp: TextIO, args: Optional[Namespace] = None):
        """
        :param fp: .toml file's file pointer
        :param args: command line arguments
        :return: Config instance
        """
        config_dic = toml.load(fp)

        code_style_config_dic = config_dic.get('codestyle', {})
        postprocess_config_dic = config_dic.get('postprocess', {})
        etc_config_dic = config_dic.get('etc', {})

        if args:
            code_style_config_dic = _update_config_dict(code_style_config_dic,
                                                        dict(
                                                            template_file=args.template,
                                                            workspace_dir=args.workspace,
                                                            lang=args.lang))
            etc_config_dic = _update_config_dict(etc_config_dic,
                                                 dict(
                                                     download_without_login=args.without_login,
                                                     parallel_download=args.parallel,
                                                     save_no_session_cache=args.save_no_session_cache))

        return Config(
            code_style_config=CodeStyleConfig(**code_style_config_dic),
            postprocess_config=PostprocessConfig(**postprocess_config_dic),
            etc_config=EtcConfig(**etc_config_dic)
        )
开发者ID:kyuridenamida,项目名称:ToolsForAtCoder,代码行数:29,代码来源:config.py


示例8: __init__

    def __init__(self, parent=None):
        """Initiate the abstract widget that is displayed in the preferences dialog."""
        super(Playback, self).__init__(parent)
        self.user_config_file = os.path.join(AppDirs('mosaic', 'Mandeep').user_config_dir,
                                             'settings.toml')

        with open(self.user_config_file) as conffile:
            config = toml.load(conffile)

        playback_config = QGroupBox('Playback Configuration')
        playback_config_layout = QVBoxLayout()
        playback_config_layout.setAlignment(Qt.AlignTop)

        self.cover_art_playback = QCheckBox('Cover Art Playback')
        self.playlist_save_checkbox = QCheckBox('Save Playlist on Close')

        playback_config_layout.addWidget(self.cover_art_playback)
        playback_config_layout.addWidget(self.playlist_save_checkbox)

        playback_config.setLayout(playback_config_layout)

        main_layout = QVBoxLayout()
        main_layout.addWidget(playback_config)

        self.setLayout(main_layout)

        self.check_playback_setting(config)
        self.check_playlist_save(config)
        self.cover_art_playback.clicked.connect(lambda: self.cover_art_playback_setting(config))
        self.playlist_save_checkbox.clicked.connect(lambda: self.playlist_save_setting(config))
开发者ID:mandeepbhutani,项目名称:Mosaic,代码行数:30,代码来源:configuration.py


示例9: layout

  def layout(self, client, userdata):
    fixtures = os.path.join(ROOT, 'test/fixtures')
    profile = webdriver.FirefoxProfile(os.path.join(fixtures, 'profile', client))

    for xpi in glob.glob(os.path.join(ROOT, 'xpi/*.xpi')):
      profile.add_extension(xpi)

    profile.set_preference('extensions.zotero.translators.better-bibtex.testing', True)

    with open(os.path.join(os.path.dirname(__file__), 'preferences.toml')) as f:
      preferences = toml.load(f)
      for p, v in nested_dict_iter(preferences['general']):
        profile.set_preference(p, v)

      if userdata.get('locale', '') == 'fr':
        for p, v in nested_dict_iter(preferences['fr']):
          profile.firefox.set_preference(p, v)

    if userdata.get('first-run', 'false') == 'false':
      profile.set_preference('extensions.zotero.translators.better-bibtex.citekeyFormat', '[auth][shorttitle][year]')

    if client == 'jurism':
      print('\n\n** WORKAROUNDS FOR JURIS-M IN PLACE -- SEE https://github.com/Juris-M/zotero/issues/34 **\n\n')
      #profile.set_preference('extensions.zotero.dataDir', os.path.join(self.path, 'jurism'))
      #profile.set_preference('extensions.zotero.useDataDir', True)
      #profile.set_preference('extensions.zotero.translators.better-bibtex.removeStock', False)

    profile.update_preferences()

    shutil.rmtree(self.path, ignore_errors=True)
    shutil.move(profile.path, self.path)
开发者ID:retorquere,项目名称:zotero-better-bibtex,代码行数:31,代码来源:zotero.py


示例10: set_database_path

def set_database_path(dbfolder):
    """Use to write the database path into the config.

    Parameters
    ----------
    dbfolder : str or pathlib.Path
        Path to where planetpy will store data it downloads..
    """
    # First check if there's a config file, so that we don't overwrite
    # anything:
    try:
        config = toml.load(str(configpath))
    except IOError:  # config file doesn't exist
        config = {}  # create new config dictionary

    # check if there's an `data_archive` sub-dic
    try:
        archive_config = config["data_archive"]
    except KeyError:
        config["data_archive"] = {"path": dbfolder}
    else:
        archive_config["path"] = dbfolder

    with open(configpath, "w") as f:
        ret = toml.dump(config, f)
    print(f"Saved database path {ret} into {configpath}.")
开发者ID:michaelaye,项目名称:planetpy,代码行数:26,代码来源:io.py


示例11: main

def main() -> None:
    data = toml.load(sys.stdin)

    assert list(data.keys()) == ["source"]

    # this value is non deterministic
    data["source"]["vendored-sources"]["directory"] = "@[email protected]"

    lines = []
    inner = data["source"]
    for source, attrs in sorted(inner.items()):
        lines.append("[source.{}]".format(quote(source)))
        if source == "vendored-sources":
            lines.append('"directory" = "@[email protected]"\n')
        else:
            for key, value in sorted(attrs.items()):
                attr = "{} = {}".format(quote(key), quote(value))
                lines.append(attr)
        lines.append("")

    result = "\n".join(lines)
    real = toml.loads(result)
    assert real == data, "output = {} while input = {}".format(real, data)

    print(result)
开发者ID:AndersonTorres,项目名称:nixpkgs,代码行数:25,代码来源:cargo-vendor-normalise.py


示例12: __init__

    def __init__(self, overrides=None, valgrind=False):
        self.pid = None
        with open(os.path.join(constants.ASSETS_DIR, "test.toml")) as fp:
            self.cf = toml.load(fp)
        if overrides:
            update_nested_dict(self.cf, overrides)
        self.cf["core"].pop("admin_host", None)
        # extract some field from cf
        self.data_store = self.cf["zone_source"]["type"].lower()
        self.pidfile = self.cf["core"]["pidfile"]
        self.admin_host = self.cf["core"].get("admin_host", None)
        self.admin_port = self.cf["core"].get("admin_port", None)
        self.dns_port = self.cf["core"]["port"]
        self.dns_host = self.cf["core"]["bind"]

        # override mongo host and mongo port
        mongo_conf = self.cf["zone_source"]["mongo"]
        if self.data_store == "mongo":
            self.zm = ZoneMongo(constants.MONGO_HOST,
                                constants.MONGO_PORT,
                                mongo_conf["dbname"])
        self.valgrind = valgrind

        self.cf_str = toml.dumps(self.cf)
        self.fp = tempfile.NamedTemporaryFile()
        self.fp.write(self.cf_str.encode("utf8"))
        self.fp.flush()
        fname = self.fp.name

        if self.valgrind:
            # TODO find the bug of possible lost and still reachable memory
            self.cmd = "valgrind --leak-check=full --show-reachable=no --show-possibly-lost=no %s -c %s" % (DNS_BIN, fname)
        else:
            self.cmd = "%s -c %s" % (DNS_BIN, fname)
        self.vagrant = vagrant.Vagrant(root=os.path.join(constants.REPO_ROOT, "vagrant"))
开发者ID:liweiwei05,项目名称:shuke,代码行数:35,代码来源:server.py


示例13: main

def main():
    host = sys.argv[1]
    print('Running certbot')
    with open('hosts.toml') as f:
        host_conf = toml.load(f)
    # get certbot domains
    print('Run certbot for %s' % host_conf)
    certbot_conf = host_conf.get('certbot', {})
    if not certbot_conf:
        raise ValueError('[certbot] configuration section of the hosts.toml file is empty!')
    webroot_path = certbot_conf.get("webroot_path", "/var/www/html/")
    domains = certbot_conf.get('domains', [])
    email = certbot_conf.get('email')
    if not domains or not type(domains) == list:
        raise ValueError('certbot conf has no list of domains entry!')

    if not os.path.isfile('/usr/bin/certbot'):
        install('software-properties-common')
        local['add-apt-repository']['-y', 'ppa:certbot/certbot'] & FG
        apt_get['update'] & FG
        install('python-certbot-nginx')
        
    cron_path = '/etc/cron.d/certbot-global-auto-renew'
    if not os.path.isfile(cron_path):
        with open(cron_path, 'w') as f:
            f.write(cron_template)
        os.chmod(cron_path, 0o600)
            

    domains = sorted(domains, key=lambda d:len(d))
    name = domains[0]
    
    conf_path = '/etc/letsencrypt/renewal/' + name + '.conf'
    matches = True
    if not os.path.isfile(conf_path):
        matches = False
    else:
        with open(conf_path, 'r') as f:
            text = f.read()
        for d in domains:
            if d + ' = ' + webroot_path.rstrip('/') not in text:
                matches = False

    if matches:
        print('letsencrypt renewal conf exists for domains %s' % domains)
        return

    
    yn = input("Is DNS for the SSL domains pointing to this server? If no, you'll have to confirm domain ownership via editing DNS entries. (y/n) ")
    if yn.lower() == 'y':
        args = ['certonly', '--webroot', '-w', webroot_path, '--cert-name', name]
        for domain in domains:
            args.extend(['-d', domain])
        local['certbot'][args] & FG
    else:
        args = ['certonly', '--manual', '--preferred-challenges=dns', '--cert-name', name]
        for domain in domains:
            args.extend(['-d', domain])
        local['certbot'][args] & FG
        print("Once DNS is pointing to this server, run certbot again to configure automatic renewal.")
开发者ID:StallionCMS,项目名称:stablehand,代码行数:60,代码来源:certbot-run.py


示例14: run

def run():
    homu_cfg = toml.load('/home/servo/homu/cfg.toml')
    homu_builders = homu_cfg['repo']['servo']['buildbot']

    # We need to invoke a new process to read the Buildbot master config
    # because Buildbot is written in python2.
    scriptpath = os.path.join(os.path.dirname(__file__), 'get_buildbot_cfg.py')
    ret = subprocess.run(
        ['/usr/bin/python2', scriptpath],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )
    if ret.returncode != 0:
        return Failure(
            'Unable to retrieve buildbot builders:', ret.stderr
        )

    buildbot_builders = json.loads(ret.stdout.decode('utf-8'))['builders']

    failure_msg = ''
    for builder_set in ['builders', 'try_builders']:
        diff = set(homu_builders[builder_set]) - set(buildbot_builders)
        if diff:
            failure_msg += 'Invalid builders for "{}": {}\n' \
                .format(builder_set, diff)

    if failure_msg:
        return Failure(
            "Homu config isn't synced with Buildbot config:",
            failure_msg
        )

    return Success('Buildbot and homu configs are synced')
开发者ID:UK992,项目名称:saltfs,代码行数:33,代码来源:valid_builders.py


示例15: read_config

def read_config():
    with open('reversion.toml') as f:
        conf = toml.load(f)

    if 'currentversion' not in conf:
        raise ConfigError("No field named currentversion")

    if not isinstance(conf['currentversion'], str):
        raise ConfigError("currentversion should be a string, not {}".format(
                                            type(conf['currentversion'])))

    places = conf.get('place', [])
    if not places:
        raise ConfigError("Need at least one replacement site ([[place]] section)")

    if not isinstance(places, list):
        raise ConfigError("place must be an array")

    if not isinstance(places[0], dict):
        raise ConfigError("place must be an array of tables")

    for place in places:
        if 'file' not in place:
            raise ConfigError("Missing file= field for place")

        if not isinstance(place['file'], str):
            raise ConfigError("file must be string")

        if ('line-regex' in place) and not isinstance(place['line-regex'], str):
            raise ConfigError("linematch must be string")

    return conf
开发者ID:takluyver,项目名称:reversion,代码行数:32,代码来源:__init__.py


示例16: load_hosts_from_hosts_toml

    def load_hosts_from_hosts_toml(self, options=None, hosts=None, hosts_file=None, ):
        if hosts_file == None and options != None:
            hosts_file = options.hosts_file
        if hosts == None and options != None:
            hosts = options.hosts
        if not os.path.isfile(hosts_file):
            org_hosts_file = hosts_file
            hosts_file = "conf/" + hosts_file
        if not os.path.isfile(hosts_file):
            raise Exception("You must have a hosts.toml in order to deploy. File '%s' does not exist." % org_hosts_file)
        with open(hosts_file) as f:
            all_hosts_conf = toml.load(f)

        if not all_hosts_conf.get('hosts'):
            raise Exception("No hosts defined in hosts.toml")
        if not len(hosts):
            if len(all_hosts_conf.get('hosts')):
                hosts = ['ALL']
        if not hosts:
            raise Exception("You must pass in a comma separated list of hosts as the first argument. Use ALL to setup all hosts")
        confs = []
        for conf in all_hosts_conf.get('hosts'):
            if not conf.get('host'):
                raise Exception("No 'host' attribute defined for a host in your hosts.toml")
            if hosts == ['ALL'] or conf.get('host') in hosts:
                confs.append(conf)
        if not confs:
            raise Exception('No host confs found matching host list: %s' % hosts)
        for conf in confs:
            conf['os'] = conf.get('os', 'ubuntu')
            if not conf['os'] in SUPPORTED_OSES:
                raise Exception('Sorry, %s is not a supported operating system.')
        return confs, hosts_file
开发者ID:StallionCMS,项目名称:stablehand,代码行数:33,代码来源:base_stablehand_action.py


示例17: _get_poetry_requirements

def _get_poetry_requirements():
    try:
        data = toml.load('poetry.lock')
    except IOError:
        raise ShubException('Please make sure the poetry lock file is present')
    # Adapted from poetry 1.0.0a2 poetry/utils/exporter.py
    lines = []
    for package in data['package']:
        source = package.get('source') or {}
        source_type = source.get('type')
        if source_type == 'git':
            line = 'git+{}@{}#egg={}'.format(
                source['url'], source['reference'], package['name']
            )
        elif source_type in ['directory', 'file']:
            line = ''
            line += source['url']
        else:
            line = '{}=={}'.format(package['name'], package['version'])

            if source_type == 'legacy' and source['url']:
                line += ' \\\n'
                line += '    --index-url {}'.format(source['url'])

        line += '\n'
        lines.append(line)
    return ''.join(lines)
开发者ID:scrapinghub,项目名称:shub,代码行数:27,代码来源:deploy.py


示例18: setUp

 def setUp(self):
     logging.disable(logging.CRITICAL)
     self.db_file, self.db_filename = tempfile.mkstemp()
     with open("fixtures/test_sac_config.toml") as f:
         config = toml.load(f)
         config['db']['connection_string'] = "sqlite:///{}".format(self.db_filename)
         self.config = config
开发者ID:BenDoan,项目名称:finance-tool,代码行数:7,代码来源:test_scrape_sac.py


示例19: __init__

 def __init__(self, conf_file):
     self.toml_file = conf_file
     self.settings: Dict = toml.load(conf_file)
     self.last_look = arrow.get(self.settings['twitter']['last_look'])
     self.multiplexing = True
     self.multi_server = self.settings['pyborg']['multi_server']
     self.pyborg = None
开发者ID:jrabbit,项目名称:pyborg-1up,代码行数:7,代码来源:mod_twitter.py


示例20: read_package_info

def read_package_info(cargo_toml=None):
    """Read the content of [package] section from Cargo.toml.
    :return: [package] section as dictionary
    """
    cargo_toml = Path(cargo_toml or Path.cwd() / 'Cargo.toml')
    with cargo_toml.open() as f:
        manifest = toml.load(f)
    return manifest['package']
开发者ID:Xion,项目名称:gisht,代码行数:8,代码来源:homebrew.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python toml.loads函数代码示例发布时间:2022-05-27
下一篇:
Python toml.dumps函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap