本文整理汇总了Python中shub.config.load_shub_config函数的典型用法代码示例。如果您正苦于以下问题:Python load_shub_config函数的具体用法?Python load_shub_config怎么用?Python load_shub_config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_shub_config函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(), "")
示例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
示例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)
示例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)
示例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))
示例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)
示例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()
示例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)
示例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']
示例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']
示例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')
示例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)
示例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')
示例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'),
)
示例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)