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

Python config.load_shub_config函数代码示例

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

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



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

示例1: test_autocreate_empty_global_scrapinghub_yml

 def test_autocreate_empty_global_scrapinghub_yml(self):
     os.remove(self.globalpath)
     os.remove(self.globalscrapycfgpath)
     os.remove(self.netrcpath)
     load_shub_config()
     self.assertTrue(os.path.isfile(self.globalpath))
     with open(self.globalpath, 'r') as f:
         self.assertEqual(f.read(), "")
开发者ID:carlosp420,项目名称:shub,代码行数:8,代码来源:test_config.py


示例2: cli

def cli():
    global_conf = load_shub_config(load_local=False, load_env=False)
    if 'default' in global_conf.apikeys:
        raise AlreadyLoggedInException

    conf = load_shub_config()
    key = _get_apikey(
        suggestion=conf.apikeys.get('default'),
        endpoint=global_conf.endpoints.get('default'),
    )
    with update_yaml_dict(GLOBAL_SCRAPINGHUB_YML_PATH) as conf:
        conf.setdefault('apikeys', {})
        conf['apikeys']['default'] = key
开发者ID:scrapinghub,项目名称:shub,代码行数:13,代码来源:login.py


示例3: test_remove_key

 def test_remove_key(self):
     GLOBAL_SH_YML = textwrap.dedent("""
         apikeys:
             default: LOGGED_IN_KEY
     """)
     with self.runner.isolated_filesystem():
         with open('.scrapinghub.yml', 'w') as f:
             f.write(GLOBAL_SH_YML)
         conf = config.load_shub_config()
         self.assertIn('default', conf.apikeys)
         self.runner.invoke(logout.cli)
         conf = config.load_shub_config()
         self.assertNotIn('default', conf.apikeys)
开发者ID:bbotella,项目名称:shub,代码行数:13,代码来源:test_logout.py


示例4: build_cmd

def build_cmd(target, version, skip_tests, no_cache, filename='Dockerfile'):
    config = load_shub_config()
    create_scrapinghub_yml_wizard(config, target=target, image=True)
    client = utils.get_docker_client()
    project_dir = utils.get_project_dir()
    image = config.get_image(target)
    image_name = utils.format_image_name(image, version)
    if not os.path.exists(os.path.join(project_dir, filename)):
        raise shub_exceptions.NotFoundException(
            "Dockerfile is not found and it is required because project '{}' is configured "
            "to deploy Docker images. Please add a Dockerfile that will be used to build "
            "the image and retry this command. If you want to migrate an existing Scrapy project "
            "you can use `shub image init` command to create a Dockerfile.".format(target))
    if utils.is_verbose():
        build_progress_cls = _LoggedBuildProgress
    else:
        build_progress_cls = _BuildProgress
    click.echo("Building {}.".format(image_name))
    events = client.build(
        path=project_dir,
        tag=image_name,
        decode=True,
        dockerfile=filename,
        nocache=no_cache
    )
    build_progress = build_progress_cls(events)
    build_progress.show()
    click.echo("The image {} build is completed.".format(image_name))
    # Test the image content after building it
    if not skip_tests:
        test_cmd(target, version)
开发者ID:scrapinghub,项目名称:shub,代码行数:31,代码来源:build.py


示例5: push_cmd

def push_cmd(target, version, username, password, email, apikey, insecure, skip_tests):
    # Test the image content after building it
    if not skip_tests:
        test_cmd(target, version)

    client = utils.get_docker_client()
    config = load_shub_config()
    image = config.get_image(target)
    username, password = utils.get_credentials(
        username=username, password=password, insecure=insecure,
        apikey=apikey, target_apikey=config.get_apikey(target))

    if username:
        _execute_push_login(client, image, username, password, email)
    image_name = utils.format_image_name(image, version)
    click.echo("Pushing {} to the registry.".format(image_name))
    events = client.push(image_name, stream=True, decode=True,
                         insecure_registry=not bool(username))
    if utils.is_verbose():
        push_progress_cls = _LoggedPushProgress
    else:
        push_progress_cls = _PushProgress
    push_progress = push_progress_cls(events)
    push_progress.show()
    click.echo("The image {} pushed successfully.".format(image_name))
开发者ID:scrapinghub,项目名称:shub,代码行数:25,代码来源:push.py


示例6: deploy_cmd

def deploy_cmd(target, version, debug, egg, build_egg, verbose, keep_log,
               conf=None):
    tmpdir = None
    try:
        if build_egg:
            egg, tmpdir = _build_egg()
            click.echo("Writing egg to %s" % build_egg)
            shutil.copyfile(egg, build_egg)
        else:
            conf = conf or load_shub_config()
            targetconf = conf.get_target_conf(target)
            version = version or targetconf.version
            auth = (targetconf.apikey, '')

            if egg:
                click.echo("Using egg: %s" % egg)
                egg = egg
            else:
                click.echo("Packing version %s" % version)
                egg, tmpdir = _build_egg()

            _upload_egg(targetconf.endpoint, egg, targetconf.project_id,
                        version, auth, verbose, keep_log, targetconf.stack,
                        targetconf.requirements_file, targetconf.eggs)
            click.echo("Run your spiders at: "
                       "https://app.scrapinghub.com/p/%s/"
                       "" % targetconf.project_id)
    finally:
        if tmpdir:
            if debug:
                click.echo("Output dir not removed: %s" % tmpdir)
            else:
                shutil.rmtree(tmpdir, ignore_errors=True)
开发者ID:scrapinghub,项目名称:shub,代码行数:33,代码来源:deploy.py


示例7: list_targets

def list_targets(ctx, param, value):
    if not value:
        return
    conf = load_shub_config()
    for name in conf.projects:
        click.echo(name)
    ctx.exit()
开发者ID:pawelmhm,项目名称:shub,代码行数:7,代码来源:deploy.py


示例8: test_envvar_precedence

 def test_envvar_precedence(self):
     _old_environ = dict(os.environ)
     os.environ['SHUB_APIKEY'] = 'key_env'
     conf = load_shub_config()
     self.assertEqual(conf.get_apikey('shproj'), 'key_env')
     os.environ.clear()
     os.environ.update(_old_environ)
开发者ID:carlosp420,项目名称:shub,代码行数:7,代码来源:test_config.py


示例9: cli

def cli():
    global_conf = load_shub_config(load_local=False, load_env=False)
    if 'default' not in global_conf.apikeys:
        click.echo("You are not logged in.")
        return 0

    with update_config() as conf:
        del conf['apikeys']['default']
开发者ID:jsargiot,项目名称:shub,代码行数:8,代码来源:logout.py


示例10: cli

def cli():
    global_conf = load_shub_config(load_local=False, load_env=False)
    if 'default' not in global_conf.apikeys:
        click.echo("You are not logged in.")
        return 0

    with update_yaml_dict(GLOBAL_SCRAPINGHUB_YML_PATH) as conf:
        del conf['apikeys']['default']
开发者ID:scrapinghub,项目名称:shub,代码行数:8,代码来源:logout.py


示例11: test_scrapinghub_ymls_read

 def test_scrapinghub_ymls_read(self):
     conf = load_shub_config()
     self.assertEqual(conf.get_apikey('shproj'), 'key')
     self.assertEqual(
         conf.get_endpoint('externalproj'),
         'local_ext_endpoint',
     )
     self.assertEqual(conf.get_apikey('externalproj'), 'key_ext')
     with self.assertRaises(BadParameterException):
         conf.get_project_id('ext2')
开发者ID:carlosp420,项目名称:shub,代码行数:10,代码来源:test_config.py


示例12: test_cmd

def test_cmd(target, version):
    config = load_shub_config()
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    docker_client = utils.get_docker_client()
    for check in [_check_image_size,
                  _check_start_crawl_entry,
                  _check_shub_image_info_entry]:
        check(image_name, docker_client)
开发者ID:scrapinghub,项目名称:shub,代码行数:10,代码来源:test.py


示例13: _check_conf

 def _check_conf():
     conf = load_shub_config()
     self.assertEqual(
         conf.get_target('default'),
         (222, 'scrapycfg_endpoint', 'key'),
     )
     self.assertEqual(
         conf.get_target('ext2'),
         (333, 'ext2_endpoint', 'ext2_key'),
     )
     self.assertEqual(conf.get_version(), 'ext2_ver')
开发者ID:jsargiot,项目名称:shub,代码行数:11,代码来源:test_config.py


示例14: _check_conf

 def _check_conf():
     conf = load_shub_config()
     self.assertEqual(
         conf.get_target('123'),
         (123, 'dotsc_endpoint', 'netrc_key'),
     )
     self.assertEqual(conf.projects['ext2'], 'ext2/333')
     self.assertEqual(
         conf.get_target('ext2'),
         (333, 'ext2_endpoint', 'ext2_key'),
     )
开发者ID:carlosp420,项目名称:shub,代码行数:11,代码来源:test_config.py


示例15: list_cmd_full

def list_cmd_full(target, silent, version):
    config = load_shub_config()
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    target_conf = config.get_target_conf(target)
    metadata = list_cmd(image_name,
                        target_conf.project_id,
                        target_conf.endpoint,
                        target_conf.apikey)
    for spider in metadata.get('spiders', []):
        click.echo(spider)
开发者ID:scrapinghub,项目名称:shub,代码行数:12,代码来源:list.py


示例16: format_image_name

def format_image_name(image_name, image_tag):
    """Format image name using image tag"""
    parts = image_name.rsplit('/', 1)
    # check if tag is already here
    if ':' in parts[-1]:
        # change name to shorter version w/o existing tag
        click.echo('Please use --version param to specify tag')
        image_name = image_name.rsplit(':', 1)[0]
    if not image_tag:
        config = shub_config.load_shub_config()
        image_tag = config.get_version()
    return '{}:{}'.format(image_name, image_tag)
开发者ID:scrapinghub,项目名称:shub,代码行数:12,代码来源:utils.py


示例17: test_automigrate_project_scrapy_cfg

    def test_automigrate_project_scrapy_cfg(self):
        def _check_conf():
            conf = load_shub_config()
            self.assertEqual(
                conf.get_target('default'),
                (222, 'scrapycfg_endpoint/', 'key'),
            )
            self.assertEqual(
                conf.get_target('ext2'),
                (333, 'ext2_endpoint/', 'ext2_key'),
            )
            self.assertEqual(
                conf.get_target('ext3'),
                (333, 'scrapycfg_endpoint/', 'key'),
            )
            self.assertEqual(
                conf.get_target('ext4'),
                (444, 'scrapycfg_endpoint/', 'ext4_key'),
            )
            self.assertEqual(conf.get_version(), 'ext2_ver')
        scrapycfg = """
            [deploy]
            project = 222
            url = scrapycfg_endpoint/scrapyd/

            [deploy:ext2]
            url = ext2_endpoint/scrapyd/
            project = 333
            username = ext2_key
            version = ext2_ver

            [deploy:ext3]
            project = 333

            [deploy:ext4]
            project = 444
            username = ext4_key
        """
        with open(self.localscrapycfgpath, 'w') as f:
            f.write(textwrap.dedent(scrapycfg))
        os.mkdir('project')
        os.chdir('project')
        conf = load_shub_config()
        with self.assertRaises(BadParameterException):
            conf.get_target('ext2')
        os.remove(self.localpath)
        # Loaded from scrapy.cfg
        _check_conf()
        # Same config should now be loaded from scrapinghub.yml
        self.assertTrue(os.path.isfile(self.localpath))
        _check_conf()
开发者ID:carlosp420,项目名称:shub,代码行数:51,代码来源:test_config.py


示例18: run_cmd

def run_cmd(spider, args, settings, environment, version, keep_volume):
    try:
        target, spider = spider.rsplit('/', 1)
    except ValueError:
        target = 'default'

    config = load_shub_config()
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    docker_client = utils.get_docker_client()

    env = _format_environment(spider, args, settings, environment)
    _run_with_docker(docker_client, image_name, env, keep_volume)
开发者ID:scrapinghub,项目名称:shub,代码行数:14,代码来源:__init__.py


示例19: cli

def cli(target, version, debug, egg, build_egg, verbose, keep_log,
        ignore_size):
    conf, image = load_shub_config(), None
    if not build_egg:
        create_scrapinghub_yml_wizard(conf, target=target)
    image = conf.get_target_conf(target).image
    if not image:
        deploy_cmd(target, version, debug, egg, build_egg, verbose, keep_log,
                   conf=conf)
    elif image.startswith(SH_IMAGES_REGISTRY):
        upload_cmd(target, version)
    else:
        raise BadParameterException(
            "Please use `shub image` commands to work with Docker registries "
            "other than Scrapinghub default registry.")
开发者ID:scrapinghub,项目名称:shub,代码行数:15,代码来源:deploy.py


示例20: deploy_cmd

def deploy_cmd(target, version, username, password, email,
               apikey, insecure, async_):
    config = load_shub_config()
    target_conf = config.get_target_conf(target)
    endpoint, target_apikey = target_conf.endpoint, target_conf.apikey
    image = config.get_image(target)
    version = version or config.get_version()
    image_name = utils.format_image_name(image, version)
    username, password = utils.get_credentials(
        username=username, password=password, insecure=insecure,
        apikey=apikey, target_apikey=target_apikey)

    apikey = apikey or target_apikey
    params = _prepare_deploy_params(
        target_conf.project_id, version, image_name, endpoint, apikey,
        username, password, email)

    click.echo("Deploying {}".format(image_name))
    utils.debug_log('Deploy parameters: {}'.format(params))
    req = requests.post(
        urljoin(endpoint, '/api/releases/deploy.json'),
        data=params,
        auth=(apikey, ''),
        timeout=300,
        allow_redirects=False
    )
    if req.status_code == 400:
        reason = req.json().get('non_field_errors')
        raise ShubException('\n'.join(reason) if reason else req.text)
    req.raise_for_status()
    status_url = req.headers['location']
    status_id = utils.store_status_url(
        status_url, limit=STORE_N_LAST_STATUS_URLS)
    click.echo(
        "You can check deploy results later with "
        "'shub image check --id {}'.".format(status_id))
    if async_:
        return
    if utils.is_verbose():
        deploy_progress_cls = _LoggedDeployProgress
    else:
        deploy_progress_cls = _DeployProgress
    events = _convert_status_requests_to_events(status_url)
    deploy_progress = deploy_progress_cls(events)
    deploy_progress.show()
开发者ID:scrapinghub,项目名称:shub,代码行数:45,代码来源:deploy.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python shutil._destinsrc函数代码示例发布时间:2022-05-27
下一篇:
Python show_message.show_message函数代码示例发布时间: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