本文整理汇总了Python中snapcraft.internal.lifecycle.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dirty_stage_reprimes
def test_dirty_stage_reprimes(self):
self.make_snapcraft_yaml(
textwrap.dedent("""\
parts:
part1:
plugin: nil
"""))
# Strip it.
lifecycle.execute('prime', self.project_options)
# Reset logging since we only care about the following
self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(self.fake_logger)
def _fake_dirty_report(self, step):
if step == 'stage':
return pluginhandler.DirtyReport({'foo'}, {'bar'})
return None
# Should automatically clean and re-stage if that step is dirty
# for the part.
with mock.patch.object(pluginhandler.PluginHandler, 'get_dirty_report',
_fake_dirty_report):
lifecycle.execute('prime', self.project_options)
self.assertThat(
self.fake_logger.output, Equals(
'Skipping pull part1 (already ran)\n'
'Skipping build part1 (already ran)\n'
'Cleaning priming area for part1 (out of date)\n'
'Cleaning staging area for part1 (out of date)\n'
'Staging part1 \n'
'Priming part1 \n'))
示例2: run
def run(args, project_options): # noqa
lifecycle_command = _get_lifecycle_command(args)
argless_command = _get_command_from_arg(args)
if lifecycle_command:
lifecycle.execute(
lifecycle_command, project_options, args['<part>'])
elif argless_command:
argless_command()
elif args['clean']:
_run_clean(args, project_options)
elif args['cleanbuild']:
lifecycle.cleanbuild(project_options),
elif _is_store_command(args):
_run_store_command(args)
elif args['tour']:
_scaffold_examples(args['<directory>'] or _SNAPCRAFT_TOUR_DIR)
elif args['help']:
snapcraft.topic_help(args['<topic>'] or args['<plugin>'],
args['--devel'], args['topics'])
elif args['update']:
parts.update()
elif args['define']:
parts.define(args['<part-name>'])
elif args['search']:
parts.search(' '.join(args['<query>']))
else: # snap by default:
lifecycle.snap(project_options, args['<directory>'], args['--output'])
return project_options
示例3: run
def run(args, project_options):
lifecycle_command = _get_lifecycle_command(args)
argless_command = _get_command_from_arg(args)
if lifecycle_command:
lifecycle.execute(
lifecycle_command, project_options, args['<part>'])
elif argless_command:
argless_command()
elif args['clean']:
step = args['--step']
if step == 'strip':
logger.warning('DEPRECATED: Use `prime` instead of `strip` '
'as the step to clean')
step = 'prime'
lifecycle.clean(project_options, args['<part>'], step)
elif args['upload']:
snapcraft.upload(args['<snap-file>'])
elif args['cleanbuild']:
lifecycle.cleanbuild(project_options),
# disable until the tour command is activated
# elif args['tour']:
# _scaffold_examples(args['<directory>'] or _SNAPCRAFT_TOUR_DIR)
elif args['help']:
snapcraft.topic_help(args['<topic>'] or args['<plugin>'],
args['--devel'], args['topics'])
else: # snap by default:
lifecycle.snap(project_options, args['<directory>'], args['--output'])
return project_options
示例4: test_prime_with_build_info_records_manifest
def test_prime_with_build_info_records_manifest(self):
self.useFixture(fixtures.EnvironmentVariable(
'SNAPCRAFT_BUILD_INFO', '1'))
self.make_snapcraft_yaml(
textwrap.dedent("""\
parts:
test-part:
plugin: nil
"""))
lifecycle.execute('prime', self.project_options)
expected = textwrap.dedent("""\
name: test
version: 0
summary: test
description: test
confinement: strict
grade: stable
parts:
test-part:
build-packages: []
installed-packages: []
installed-snaps: []
plugin: nil
prime: []
stage: []
stage-packages: []
uname: Linux test uname 4.10 x86_64
architectures: [{}]
build-packages: []
build-snaps: []
""".format(self.project_options.deb_arch))
self.assertThat(
os.path.join('prime', 'snap', 'manifest.yaml'),
FileContains(expected))
示例5: test_dirty_stage_part_with_unbuilt_dependent
def test_dirty_stage_part_with_unbuilt_dependent(self):
self.make_snapcraft_yaml("""parts:
part1:
plugin: nil
part2:
plugin: nil
after: [part1]
""")
# Stage dependency (dependent is unbuilt)
lifecycle.execute('stage', self.project_options, part_names=['part1'])
# Reset logging since we only care about the following
self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(self.fake_logger)
def _fake_is_dirty(self, step):
return step == 'stage'
# Should automatically clean and re-stage if that step is dirty
# for the part.
with mock.patch.object(pluginhandler.PluginHandler, 'is_dirty',
_fake_is_dirty):
lifecycle.execute('stage', self.project_options,
part_names=['part1'])
self.assertEqual(
'Skipping pull part1 (already ran)\n'
'Skipping build part1 (already ran)\n'
'Skipping cleaning priming area for part1 (out of date) '
'(already clean)\n'
'Cleaning staging area for part1 (out of date)\n'
'Staging part1 \n',
self.fake_logger.output)
示例6: test_prime_with_build_info_records_snapcraft_yaml
def test_prime_with_build_info_records_snapcraft_yaml(self):
self.useFixture(fixtures.EnvironmentVariable(
'SNAPCRAFT_BUILD_INFO', '1'))
self.make_snapcraft_yaml(
textwrap.dedent("""\
parts:
test-part:
plugin: nil
"""),
snap_type='type: app')
lifecycle.execute('prime', self.project_options)
expected = textwrap.dedent("""\
name: test
version: 0
summary: test
description: test
confinement: strict
grade: stable
type: app
parts:
test-part:
plugin: nil
""")
self.assertThat(
os.path.join('prime', 'snap', 'snapcraft.yaml'),
FileContains(expected))
示例7: test_pull_is_dirty_if_target_arch_changes
def test_pull_is_dirty_if_target_arch_changes(
self, mock_install_build_packages, mock_enable_cross_compilation):
self.make_snapcraft_yaml("""parts:
part1:
plugin: nil
""")
# Pull it with amd64
lifecycle.execute('pull', snapcraft.ProjectOptions(
target_deb_arch='amd64'))
# Reset logging since we only care about the following
self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(self.fake_logger)
# Pull it again with armhf. Should catch that the part needs to be
# re-pulled due to the change in target architecture and raise an
# error.
raised = self.assertRaises(
RuntimeError,
lifecycle.execute,
'pull', snapcraft.ProjectOptions(
target_deb_arch='armhf'))
self.assertEqual("Setting target machine to 'armhf'\n",
self.fake_logger.output)
self.assertEqual(
"The 'pull' step of 'part1' is out of date:\n\n"
"The 'deb_arch' project option appears to have changed.\n\n"
"In order to continue, please clean that part's 'pull' step "
"by running: snapcraft clean part1 -s pull\n",
str(raised))
示例8: test_core_setup_if_docker_env
def test_core_setup_if_docker_env(self, dockerenv_fake, download_mock):
dockerenv_file = os.path.join(self.tempdir, "dockerenv")
os.makedirs(self.tempdir)
open(dockerenv_file, "w").close()
dockerenv_fake.return_value = dockerenv_file
project_config = self.make_snapcraft_project(confinement="classic")
core_snap = self.create_core_snap(project_config.project.deb_arch)
core_snap_hash = calculate_sha3_384(core_snap)
download_mock.return_value = core_snap_hash
self.tempdir_mock.side_effect = self._setup_tempdir_side_effect(core_snap)
lifecycle.execute(steps.PULL, project_config)
regex = (".*mkdir -p {}\nunsquashfs -d {} .*{}\n").format(
os.path.dirname(self.core_path), self.core_path, core_snap_hash
)
self.assertThat(
self.witness_path,
FileContains(matcher=MatchesRegex(regex, flags=re.DOTALL)),
)
download_mock.assert_called_once_with(
"core",
"stable",
os.path.join(self.tempdir, "core.snap"),
project_config.project.deb_arch,
"",
)
示例9: test_core_setup_with_env_var
def test_core_setup_with_env_var(self, download_mock):
self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_SETUP_CORE", "1"))
project_config = self.make_snapcraft_project(confinement="classic")
core_snap = self.create_core_snap(project_config.project.deb_arch)
core_snap_hash = calculate_sha3_384(core_snap)
download_mock.return_value = core_snap_hash
self.tempdir_mock.side_effect = self._setup_tempdir_side_effect(core_snap)
lifecycle.execute(steps.PULL, project_config)
regex = (".*mkdir -p {}\nunsquashfs -d {} .*{}\n").format(
os.path.dirname(self.core_path), self.core_path, core_snap_hash
)
self.assertThat(
self.witness_path,
FileContains(matcher=MatchesRegex(regex, flags=re.DOTALL)),
)
download_mock.assert_called_once_with(
"core",
"stable",
os.path.join(self.tempdir, "core.snap"),
project_config.project.deb_arch,
"",
)
示例10: test_dirty_stage_restrips
def test_dirty_stage_restrips(self):
self.make_snapcraft_yaml("""parts:
part1:
plugin: nil
""")
# Strip it.
lifecycle.execute('strip', self.project_options)
# Reset logging since we only care about the following
self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(self.fake_logger)
def _fake_is_dirty(self, step):
return step == 'stage'
# Should automatically clean and re-stage if that step is dirty
# for the part.
with mock.patch.object(pluginhandler.PluginHandler, 'is_dirty',
_fake_is_dirty):
lifecycle.execute('strip', self.project_options)
self.assertEqual(
'Skipping pull part1 (already ran)\n'
'Skipping build part1 (already ran)\n'
'Cleaning snapping area for part1 (out of date)\n'
'Cleaning staging area for part1 (out of date)\n'
'Staging part1 \n'
'Stripping part1 \n',
self.fake_logger.output)
示例11: test_dirty_pull_raises
def test_dirty_pull_raises(self):
self.make_snapcraft_yaml("""parts:
part1:
plugin: nil
""")
# Pull it.
lifecycle.execute('pull', self.project_options)
# Reset logging since we only care about the following
self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(self.fake_logger)
def _fake_is_dirty(self, step):
return step == 'pull'
# Should catch that the part needs to be re-pulled and raise an error.
with mock.patch.object(pluginhandler.PluginHandler, 'is_dirty',
_fake_is_dirty):
with self.assertRaises(RuntimeError) as raised:
lifecycle.execute('pull', self.project_options)
self.assertEqual('', self.fake_logger.output)
self.assertEqual(
"The 'pull' step of 'part1' is out of date. Please clean that "
"part's 'pull' step in order to rebuild", str(raised.exception))
示例12: test_dependency_is_staged_when_required
def test_dependency_is_staged_when_required(self):
project_config = self.make_snapcraft_project(
textwrap.dedent(
"""\
parts:
part1:
plugin: nil
part2:
plugin: nil
after:
- part1
"""
)
)
lifecycle.execute(steps.PULL, project_config, part_names=["part2"])
self.assertThat(
self.fake_logger.output,
Equals(
"'part2' has dependencies that need to be staged: part1\n"
"Pulling part1 \n"
"Building part1 \n"
"Staging part1 \n"
"Pulling part2 \n"
),
)
示例13: test_prime_with_build_info_records_snapcraft_yaml
def test_prime_with_build_info_records_snapcraft_yaml(self):
self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO", "1"))
project_config = self.make_snapcraft_project(
textwrap.dedent(
"""\
parts:
test-part:
plugin: nil
"""
),
snap_type="type: app",
)
lifecycle.execute(steps.PRIME, project_config)
expected = textwrap.dedent(
"""\
name: test
version: 0
summary: test
description: test
confinement: strict
grade: stable
type: app
parts:
test-part:
plugin: nil
"""
)
self.assertThat(
os.path.join(steps.PRIME.name, "snap", "snapcraft.yaml"),
FileContains(expected),
)
示例14: test_core_setup_skipped_if_not_classic
def test_core_setup_skipped_if_not_classic(self):
self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_SETUP_CORE", "1"))
project_config = self.make_snapcraft_project(confinement="strict")
lifecycle.execute(steps.PULL, project_config)
self.assertThat(self.witness_path, Not(FileExists()))
示例15: test_dirty_pull_raises
def test_dirty_pull_raises(self):
self.make_snapcraft_yaml("""parts:
part1:
plugin: nil
""")
# Pull it.
lifecycle.execute('pull', self.project_options)
# Reset logging since we only care about the following
self.fake_logger = fixtures.FakeLogger(level=logging.INFO)
self.useFixture(self.fake_logger)
def _fake_dirty_report(self, step):
if step == 'pull':
return pluginhandler.DirtyReport(set(), {'foo', 'bar'})
return None
# Should catch that the part needs to be re-pulled and raise an error.
with mock.patch.object(pluginhandler.PluginHandler, 'get_dirty_report',
_fake_dirty_report):
raised = self.assertRaises(
RuntimeError,
lifecycle.execute,
'pull', self.project_options)
self.assertEqual('', self.fake_logger.output)
self.assertEqual(
"The 'pull' step of 'part1' is out of date:\n\n"
"The 'bar' and 'foo' project options appear to have changed.\n\n"
"In order to continue, please clean that part's 'pull' step "
"by running: snapcraft clean part1 -s pull\n",
str(raised))