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

Python common.get_partsdir函数代码示例

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

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



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

示例1: test_partial_clean

    def test_partial_clean(self):
        parts = self.make_snapcraft_yaml(n=3)

        main(["clean", "clean0", "clean2"])

        for i in [0, 2]:
            self.assertFalse(
                os.path.exists(parts[i]["part_dir"]), "Expected for {!r} to be wiped".format(parts[i]["part_dir"])
            )

        self.assertTrue(os.path.exists(parts[1]["part_dir"]), "Expected a part directory for the clean1 part")

        self.assertTrue(os.path.exists(common.get_partsdir()))
        self.assertTrue(os.path.exists(common.get_stagedir()))
        self.assertTrue(os.path.exists(common.get_snapdir()))

        # Now clean it the rest of the way
        main(["clean", "clean1"])

        for i in range(0, 3):
            self.assertFalse(
                os.path.exists(parts[i]["part_dir"]), "Expected for {!r} to be wiped".format(parts[i]["part_dir"])
            )

        self.assertFalse(os.path.exists(common.get_partsdir()))
        self.assertFalse(os.path.exists(common.get_stagedir()))
        self.assertFalse(os.path.exists(common.get_snapdir()))
开发者ID:fallen,项目名称:snapcraft,代码行数:27,代码来源:test_commands_clean.py


示例2: test_clean_all

    def test_clean_all(self):
        cmds.clean({})

        self.mock_exists.assert_has_calls([
            mock.call('partdir1'),
            mock.call().__bool__(),
            mock.call('partdir2'),
            mock.call().__bool__(),
            mock.call('partdir3'),
            mock.call().__bool__(),
            mock.call(common.get_partsdir()),
            mock.call().__bool__(),
            mock.call(common.get_stagedir()),
            mock.call().__bool__(),
            mock.call(common.get_snapdir()),
            mock.call().__bool__(),
        ])

        self.mock_rmtree.assert_has_calls([
            mock.call('partdir1'),
            mock.call('partdir2'),
            mock.call('partdir3'),
            mock.call(common.get_stagedir()),
            mock.call(common.get_snapdir()),
        ])

        self.mock_rmdir.assert_called_once_with(common.get_partsdir())
开发者ID:svijee,项目名称:snapcraft,代码行数:27,代码来源:test_cmds.py


示例3: _cleanup_common_directories

def _cleanup_common_directories(config):
    _remove_directory_if_empty(common.get_partsdir())
    _remove_directory_if_empty(common.get_stagedir())
    _remove_directory_if_empty(common.get_snapdir())

    max_index = -1
    for part in config.all_parts:
        step = part.last_step()
        if step:
            index = common.COMMAND_ORDER.index(step)
            if index > max_index:
                max_index = index

    # If no parts have been pulled, remove the parts directory. In most cases
    # this directory should have already been cleaned, but this handles the
    # case of a failed pull.
    should_remove_partsdir = max_index < common.COMMAND_ORDER.index('pull')
    if should_remove_partsdir and os.path.exists(common.get_partsdir()):
        logger.info('Cleaning up parts directory')
        shutil.rmtree(common.get_partsdir())

    # If no parts have been staged, remove staging area.
    should_remove_stagedir = max_index < common.COMMAND_ORDER.index('stage')
    if should_remove_stagedir and os.path.exists(common.get_stagedir()):
        logger.info('Cleaning up staging area')
        shutil.rmtree(common.get_stagedir())

    # If no parts have been stripped, remove snapping area.
    should_remove_snapdir = max_index < common.COMMAND_ORDER.index('strip')
    if should_remove_snapdir and os.path.exists(common.get_snapdir()):
        logger.info('Cleaning up snapping area')
        shutil.rmtree(common.get_snapdir())
开发者ID:dplanella,项目名称:snapcraft,代码行数:32,代码来源:clean.py


示例4: clean

def clean(args):
    config = _load_config()

    part_names = {part.name for part in config.all_parts}
    for part_name in args.parts:
        if part_name not in part_names:
            logger.error('The part named {!r} is not defined in '
                         '\'snapcraft.yaml\''.format(part_name))
            sys.exit(1)

    for part in config.all_parts:
        if not args.parts or part.name in args.parts:
            part.clean()

    # parts dir does not contain only generated code.
    if (os.path.exists(common.get_partsdir()) and
            not os.listdir(common.get_partsdir())):
        os.rmdir(common.get_partsdir())

    clean_stage = not args.parts or part_names == set(args.parts)
    if clean_stage and os.path.exists(common.get_stagedir()):
        logger.info('Cleaning up staging area')
        shutil.rmtree(common.get_stagedir())

    if os.path.exists(common.get_snapdir()):
        logger.info('Cleaning up snapping area')
        shutil.rmtree(common.get_snapdir())
开发者ID:kightlygeorge,项目名称:snapcraft,代码行数:27,代码来源:cmds.py


示例5: test_partial_clean

    def test_partial_clean(self):
        parts = self.make_snapcraft_yaml(n=3)

        clean.main(['clean0', 'clean2'])

        for i in [0, 2]:
            self.assertFalse(
                os.path.exists(parts[i]['part_dir']),
                'Expected for {!r} to be wiped'.format(parts[i]['part_dir']))

        self.assertTrue(os.path.exists(parts[1]['part_dir']),
                        'Expected a part directory for the clean1 part')

        self.assertTrue(os.path.exists(common.get_partsdir()))
        self.assertTrue(os.path.exists(common.get_stagedir()))
        self.assertTrue(os.path.exists(common.get_snapdir()))

        # Now clean it the rest of the way
        clean.main(['clean1'])

        for i in range(0, 3):
            self.assertFalse(
                os.path.exists(parts[i]['part_dir']),
                'Expected for {!r} to be wiped'.format(parts[i]['part_dir']))

        self.assertFalse(os.path.exists(common.get_partsdir()))
        self.assertFalse(os.path.exists(common.get_stagedir()))
        self.assertFalse(os.path.exists(common.get_snapdir()))
开发者ID:dplanella,项目名称:snapcraft,代码行数:28,代码来源:test_commands_clean.py


示例6: main

def main(argv=None):
    argv = argv if argv else []
    args = docopt(__doc__, argv=argv)

    config = snapcraft.yaml.load_config()

    if args['PART']:
        config.validate_parts(args['PART'])

    for part in config.all_parts:
        if not args['PART'] or part.name in args['PART']:
            part.clean()

    # parts dir does not contain only generated code.
    if (os.path.exists(common.get_partsdir()) and
            not os.listdir(common.get_partsdir())):
        os.rmdir(common.get_partsdir())

    parts_match = set(config.part_names) == set(args['PART'])
    # Only clean stage if all the parts were cleaned up.
    clean_stage = not args['PART'] or parts_match
    if clean_stage and os.path.exists(common.get_stagedir()):
        logger.info('Cleaning up staging area')
        shutil.rmtree(common.get_stagedir())

    if os.path.exists(common.get_snapdir()):
        logger.info('Cleaning up snapping area')
        shutil.rmtree(common.get_snapdir())
开发者ID:asac,项目名称:snapcraft,代码行数:28,代码来源:clean.py


示例7: clear_common_directories

    def clear_common_directories(self):
        if os.path.exists(common.get_partsdir()):
            shutil.rmtree(common.get_partsdir())

        if os.path.exists(common.get_stagedir()):
            shutil.rmtree(common.get_stagedir())

        if os.path.exists(common.get_snapdir()):
            shutil.rmtree(common.get_snapdir())
开发者ID:fallen,项目名称:snapcraft,代码行数:9,代码来源:test_pluginhandler.py


示例8: test_state_file_migration

    def test_state_file_migration(self):
        part_name = 'foo'
        for step in common.COMMAND_ORDER:
            shutil.rmtree(common.get_partsdir())
            with self.subTest('{} step'.format(step)):
                part_dir = os.path.join(common.get_partsdir(), part_name)
                os.makedirs(part_dir)
                with open(os.path.join(part_dir, 'state'), 'w') as f:
                    f.write(step)

                handler = pluginhandler.load_plugin(part_name, 'nil')
                self.assertEqual(step, handler.last_step())
开发者ID:fallen,项目名称:snapcraft,代码行数:12,代码来源:test_pluginhandler.py


示例9: test_clean_nested_dependent_parts

    def test_clean_nested_dependent_parts(self):
        yaml = """name: clean-test
version: 1.0
summary: test clean
description: test clean

parts:
  main:
    plugin: nil
    source: .

  dependent:
    plugin: nil
    source: .
    after: [main]

  dependent-dependent:
    plugin: nil
    source: .
    after: [dependent]"""

        super().make_snapcraft_yaml(yaml)

        part_dirs = {}
        for part in ['main', 'dependent', 'dependent-dependent']:
            part_dirs[part] = os.path.join(common.get_partsdir(), part)
            os.makedirs(part_dirs[part])

        os.makedirs(common.get_stagedir())
        os.makedirs(common.get_snapdir())

        # Cleaning only `main`. Since `dependent` depends upon main, we expect
        # that it will be cleaned as well. Otherwise it won't be using the new
        # `main` when it is built.
        clean.main(['main'])

        self.assertFalse(os.path.exists(part_dirs['main']),
                         'Expected part directory for main to be cleaned')
        self.assertFalse(
            os.path.exists(part_dirs['dependent']),
            'Expected part directory for dependent to be cleaned as it '
            'depends upon main')

        self.assertFalse(
            os.path.exists(part_dirs['dependent-dependent']),
            'Expected part directory for dependent-dependent to be cleaned as '
            'it depends upon dependent, which depends upon main')

        self.assertFalse(os.path.exists(common.get_partsdir()))
        self.assertFalse(os.path.exists(common.get_stagedir()))
        self.assertFalse(os.path.exists(common.get_snapdir()))
开发者ID:dplanella,项目名称:snapcraft,代码行数:51,代码来源:test_commands_clean.py


示例10: test_cleanbuild

    def test_cleanbuild(self, mock_installed, mock_call):
        mock_installed.return_value = True

        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        self.make_snapcraft_yaml()
        # simulate build artifacts

        dirs = [
            os.path.join(common.get_partsdir(), 'part1', 'src'),
            common.get_stagedir(),
            common.get_snapdir(),
            os.path.join(common.get_partsdir(), 'plugins'),
        ]
        files_tar = [
            os.path.join(common.get_partsdir(), 'plugins', 'x-plugin.py'),
            'main.c',
        ]
        files_no_tar = [
            os.path.join(common.get_stagedir(), 'binary'),
            os.path.join(common.get_snapdir(), 'binary'),
            'snap-test.snap',
            'snap-test_1.0_source.tar.bz2',
        ]
        for d in dirs:
            os.makedirs(d)
        for f in files_tar + files_no_tar:
            open(f, 'w').close()

        cleanbuild.main()

        self.assertEqual(
            'Setting up container with project assets\n'
            'Waiting for a network connection...\n'
            'Network connection established\n'
            'Retrieved snap-test_1.0_amd64.snap\n',
            fake_logger.output)

        with tarfile.open('snap-test_1.0_source.tar.bz2') as tar:
            tar_members = tar.getnames()

        for f in files_no_tar:
            f = os.path.relpath(f)
            self.assertFalse('./{}'.format(f) in tar_members,
                             '{} should not be in {}'.format(f, tar_members))
        for f in files_tar:
            f = os.path.relpath(f)
            self.assertTrue('./{}'.format(f) in tar_members,
                            '{} should be in {}'.format(f, tar_members))
开发者ID:dplanella,项目名称:snapcraft,代码行数:50,代码来源:test_commands_cleanbuild.py


示例11: test_strip_defaults

    def test_strip_defaults(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)
        parts = self.make_snapcraft_yaml()

        strip.main()

        self.assertTrue(os.path.exists(common.get_snapdir()),
                        'Expected a snap directory')
        self.assertTrue(
            os.path.exists(
                os.path.join(common.get_snapdir(), 'meta', 'snap.yaml')),
            'Expected a snap.yaml')
        self.assertTrue(os.path.exists(common.get_stagedir()),
                        'Expected a stage directory')
        self.assertTrue(os.path.exists(common.get_partsdir()),
                        'Expected a parts directory')
        self.assertTrue(os.path.exists(parts[0]['part_dir']),
                        'Expected a part directory for the build0 part')
        self.assertTrue(os.path.exists(parts[0]['state_file']),
                        'Expected a state file for the build0 part')

        with open(parts[0]['state_file']) as sf:
            state = sf.readlines()
        self.assertEqual(len(state), 1, 'Expected only one line in the state '
                         'file for the build0 part')
        self.assertEqual(state[0], 'strip', "Expected the state file for "
                         "build0 to be 'strip'")
开发者ID:LefterisJP,项目名称:snapcraft,代码行数:28,代码来源:test_commands_strip.py


示例12: test_wrap_exe_writes_wrapper_with_basename

    def test_wrap_exe_writes_wrapper_with_basename(self, mock_assemble_env):
        mock_assemble_env.return_value = """\
PATH={0}/part1/install/usr/bin:{0}/part1/install/bin
""".format(common.get_partsdir())

        snapdir = common.get_snapdir()
        os.mkdir(snapdir)

        relative_exe_path = 'test_relexepath'
        open(os.path.join(snapdir, relative_exe_path), 'w').close()

        relative_wrapper_path = meta._wrap_exe(
            relative_exe_path, basename='new-name')
        wrapper_path = os.path.join(snapdir, relative_wrapper_path)

        self.assertEqual(relative_wrapper_path, 'new-name.wrapper')

        expected = ('#!/bin/sh\n'
                    'PATH=$SNAP/usr/bin:$SNAP/bin\n'
                    '\n\n'
                    'exec "$SNAP/test_relexepath" $*\n')
        with open(wrapper_path) as wrapper_file:
            wrapper_contents = wrapper_file.read()

        self.assertEqual(expected, wrapper_contents)
开发者ID:sergiusens,项目名称:snapcraft,代码行数:25,代码来源:test_meta.py


示例13: test_build_one_part_only_from_3

    def test_build_one_part_only_from_3(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)
        parts = self.make_snapcraft_yaml(n=3)

        build.main(['build1', ])

        self.assertTrue(os.path.exists(common.get_partsdir()),
                        'Expected a parts directory')
        self.assertTrue(os.path.exists(parts[1]['part_dir']),
                        'Expected a part directory for the build1 part')
        self.assertTrue(os.path.exists(parts[1]['state_file']),
                        'Expected a state file for the build1 part')

        with open(parts[1]['state_file']) as sf:
            state = sf.readlines()
        self.assertEqual(len(state), 1, 'Expected only one line in the state '
                         'file for the build1 part')
        self.assertEqual(state[0], 'build', "Expected the state file for "
                         " build1 to be 'build'")

        for i in [0, 2]:
            self.assertFalse(os.path.exists(parts[i]['part_dir']),
                             'Pulled wrong part')
            self.assertFalse(os.path.exists(parts[i]['state_file']),
                             'Expected for only to be a state file for build1')
开发者ID:lool,项目名称:snapcraft,代码行数:26,代码来源:test_commands_build.py


示例14: test_stage_ran_twice_is_a_noop

    def test_stage_ran_twice_is_a_noop(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)
        parts = self.make_snapcraft_yaml()

        stage.main()

        self.assertEqual(
            'Pulling stage0 \n'
            'Building stage0 \n'
            'Staging stage0 \n',
            fake_logger.output)

        self.assertTrue(os.path.exists(common.get_stagedir()),
                        'Expected a stage directory')
        self.assertTrue(os.path.exists(common.get_partsdir()),
                        'Expected a parts directory')
        self.assertTrue(os.path.exists(parts[0]['part_dir']),
                        'Expected a part directory for the build0 part')

        self.verify_state('build0', parts[0]['state_dir'], 'stage')

        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        stage.main()

        self.assertEqual(
            'Skipping pull stage0  (already ran)\n'
            'Skipping build stage0  (already ran)\n'
            'Skipping stage stage0  (already ran)\n',
            fake_logger.output)
开发者ID:dplanella,项目名称:snapcraft,代码行数:32,代码来源:test_commands_stage.py


示例15: _write_wrap_exe

def _write_wrap_exe(wrapexec, wrappath, shebang=None, args=None, cwd=None):
    args = ' '.join(args) + ' $*' if args else '$*'
    cwd = 'cd {}'.format(cwd) if cwd else ''

    snap_dir = common.get_snapdir()
    assembled_env = common.assemble_env().replace(snap_dir, '$SNAP')
    replace_path = r'{}/[a-z0-9][a-z0-9+-]*/install'.format(
        common.get_partsdir())
    assembled_env = re.sub(replace_path, '$SNAP', assembled_env)
    executable = '"{}"'.format(wrapexec)
    if shebang is not None:
        new_shebang = re.sub(replace_path, '$SNAP', shebang)
        if new_shebang != shebang:
            # If the shebang was pointing to and executable within the
            # local 'parts' dir, have the wrapper script execute it
            # directly, since we can't use $SNAP in the shebang itself.
            executable = '"{}" "{}"'.format(new_shebang, wrapexec)
    script = ('#!/bin/sh\n' +
              '{}\n'.format(assembled_env) +
              '{}\n'.format(cwd) +
              'exec {} {}\n'.format(executable, args))

    with open(wrappath, 'w+') as f:
        f.write(script)

    os.chmod(wrappath, 0o755)
开发者ID:dplanella,项目名称:snapcraft,代码行数:26,代码来源:meta.py


示例16: test_wrap_exe_must_write_wrapper

    def test_wrap_exe_must_write_wrapper(self, mock_assemble_env):
        mock_assemble_env.return_value = """\
PATH={0}/part1/install/usr/bin:{0}/part1/install/bin
""".format(common.get_partsdir())

        snapdir = common.get_snapdir()
        os.mkdir(snapdir)

        relative_exe_path = 'test_relexepath'
        open(os.path.join(snapdir, relative_exe_path), 'w').close()

        # Check that the wrapper is created even if there is already a file
        # with the same name.
        open(os.path.join('snap', 'test_relexepath.wrapper'), 'w').close()

        relative_wrapper_path = meta._wrap_exe(relative_exe_path)
        wrapper_path = os.path.join(snapdir, relative_wrapper_path)

        expected = ('#!/bin/sh\n'
                    'PATH=$SNAP/usr/bin:$SNAP/bin\n'
                    '\n\n'
                    'exec "$SNAP/test_relexepath" $*\n')

        with open(wrapper_path) as wrapper_file:
            wrapper_contents = wrapper_file.read()

        self.assertEqual(expected, wrapper_contents)
开发者ID:sergiusens,项目名称:snapcraft,代码行数:27,代码来源:test_meta.py


示例17: __init__

    def __init__(self, plugin_name, part_name, properties,
                 project_options, part_schema):
        self.valid = False
        self.code = None
        self.config = {}
        self._name = part_name
        self._ubuntu = None
        self._project_options = project_options
        self.deps = []

        self.stagedir = os.path.join(os.getcwd(), 'stage')
        self.snapdir = os.path.join(os.getcwd(), 'snap')

        parts_dir = common.get_partsdir()
        self.bindir = os.path.join(parts_dir, part_name, 'bin')
        self.ubuntudir = os.path.join(parts_dir, part_name, 'ubuntu')
        self.statedir = os.path.join(parts_dir, part_name, 'state')

        self._migrate_state_file()

        try:
            self._load_code(plugin_name, properties, part_schema)
        except jsonschema.ValidationError as e:
            raise PluginError('properties failed to load for {}: {}'.format(
                part_name, e.message))
开发者ID:fallen,项目名称:snapcraft,代码行数:25,代码来源:pluginhandler.py


示例18: test_strip_one_part_only_from_3

    def test_strip_one_part_only_from_3(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)
        parts = self.make_snapcraft_yaml(n=3)

        main(['strip', 'strip1'])

        self.assertFalse(
            os.path.exists(
                os.path.join(common.get_snapdir(), 'meta', 'snap.yaml')),
            'There should not be a snap.yaml')
        self.assertTrue(os.path.exists(common.get_snapdir()),
                        'Expected a snap directory')
        self.assertTrue(os.path.exists(common.get_stagedir()),
                        'Expected a stage directory')
        self.assertTrue(os.path.exists(common.get_partsdir()),
                        'Expected a parts directory')
        self.assertTrue(os.path.exists(parts[1]['part_dir']),
                        'Expected a part directory for the strip1 part')

        self.verify_state('strip1', parts[1]['state_dir'], 'strip')

        for i in [0, 2]:
            self.assertFalse(os.path.exists(parts[i]['part_dir']),
                             'Pulled wrong part')
            self.assertFalse(os.path.exists(parts[i]['state_dir']),
                             'Expected for only to be a state file for build1')
开发者ID:fallen,项目名称:snapcraft,代码行数:27,代码来源:test_commands_strip.py


示例19: test_clean_all

    def test_clean_all(self):
        self.make_snapcraft_yaml(n=3)

        clean.main()

        self.assertFalse(os.path.exists(common.get_partsdir()))
        self.assertFalse(os.path.exists(common.get_stagedir()))
        self.assertFalse(os.path.exists(common.get_snapdir()))
开发者ID:dplanella,项目名称:snapcraft,代码行数:8,代码来源:test_commands_clean.py


示例20: test_clean_all_when_all_parts_specified

    def test_clean_all_when_all_parts_specified(self):
        self.make_snapcraft_yaml(n=3)

        clean.main(['clean0', 'clean1', 'clean2'])

        self.assertFalse(os.path.exists(common.get_partsdir()))
        self.assertFalse(os.path.exists(common.get_stagedir()))
        self.assertFalse(os.path.exists(common.get_snapdir()))
开发者ID:dplanella,项目名称:snapcraft,代码行数:8,代码来源:test_commands_clean.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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