コード例 #1
0
    def setUp(self):
        super().setUp()

        tmpdirObject = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdirObject.cleanup)
        tmpdir = tmpdirObject.name

        part1 = pluginhandler.load_plugin('part1', 'nil')
        part1.code.installdir = tmpdir + '/install1'
        os.makedirs(part1.installdir + '/a')
        open(part1.installdir + '/a/1', mode='w').close()

        part2 = pluginhandler.load_plugin('part2', 'nil')
        part2.code.installdir = tmpdir + '/install2'
        os.makedirs(part2.installdir + '/a')
        with open(part2.installdir + '/1', mode='w') as f:
            f.write('1')
        open(part2.installdir + '/2', mode='w').close()
        with open(part2.installdir + '/a/2', mode='w') as f:
            f.write('a/2')

        part3 = pluginhandler.load_plugin('part3', 'nil')
        part3.code.installdir = tmpdir + '/install3'
        os.makedirs(part3.installdir + '/a')
        os.makedirs(part3.installdir + '/b')
        with open(part3.installdir + '/1', mode='w') as f:
            f.write('2')
        with open(part2.installdir + '/2', mode='w') as f:
            f.write('1')
        open(part3.installdir + '/a/2', mode='w').close()

        self.part1 = part1
        self.part2 = part2
        self.part3 = part3
コード例 #2
0
    def setUp(self):
        super().setUp()

        tmpdirObject = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdirObject.cleanup)
        tmpdir = tmpdirObject.name

        part1 = pluginhandler.load_plugin('part1', 'nil')
        part1.code.installdir = tmpdir + '/install1'
        os.makedirs(part1.installdir + '/a')
        open(part1.installdir + '/a/1', mode='w').close()

        part2 = pluginhandler.load_plugin('part2', 'nil')
        part2.code.installdir = tmpdir + '/install2'
        os.makedirs(part2.installdir + '/a')
        with open(part2.installdir + '/1', mode='w') as f:
            f.write('1')
        open(part2.installdir + '/2', mode='w').close()
        with open(part2.installdir + '/a/2', mode='w') as f:
            f.write('a/2')

        part3 = pluginhandler.load_plugin('part3', 'nil')
        part3.code.installdir = tmpdir + '/install3'
        os.makedirs(part3.installdir + '/a')
        os.makedirs(part3.installdir + '/b')
        with open(part3.installdir + '/1', mode='w') as f:
            f.write('2')
        with open(part2.installdir + '/2', mode='w') as f:
            f.write('1')
        open(part3.installdir + '/a/2', mode='w').close()

        self.part1 = part1
        self.part2 = part2
        self.part3 = part3
コード例 #3
0
    def test_init_unknown_plugin_must_raise_exception(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)

        with self.assertRaises(pluginhandler.PluginError) as raised:
            pluginhandler.load_plugin('fake-part', 'test_unexisting')

        self.assertEqual(raised.exception.__str__(),
                         'unknown plugin: test_unexisting')
コード例 #4
0
    def test_init_unknown_plugin_must_raise_exception(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)

        with self.assertRaises(pluginhandler.PluginError) as raised:
            pluginhandler.load_plugin('fake-part', 'test_unexisting')

        self.assertEqual(raised.exception.__str__(),
                         'unknown plugin: test_unexisting')
コード例 #5
0
    def test_clean_strip_multiple_independent_parts(self):
        # Create part1 and get it through the "build" step.
        handler1 = pluginhandler.load_plugin('part1', 'nil')
        handler1.makedirs()

        bindir = os.path.join(handler1.code.installdir, 'bin')
        os.makedirs(bindir)
        open(os.path.join(bindir, '1'), 'w').close()

        handler1.mark_done('build')

        # Now create part2 and get it through the "build" step.
        handler2 = pluginhandler.load_plugin('part2', 'nil')
        handler2.makedirs()

        bindir = os.path.join(handler2.code.installdir, 'bin')
        os.makedirs(bindir)
        open(os.path.join(bindir, '2'), 'w').close()

        handler2.mark_done('build')

        # Now stage both parts
        handler1.stage()
        handler2.stage()

        # And strip both parts
        handler1.strip()
        handler2.strip()

        # Verify that part1's file has been stripped
        self.assertTrue(
            os.path.exists(os.path.join(common.get_snapdir(), 'bin', '1')))

        # Verify that part2's file has been stripped
        self.assertTrue(
            os.path.exists(os.path.join(common.get_snapdir(), 'bin', '2')))

        # Now clean the strip step for part1
        handler1.clean_strip({})

        # Verify that part1's file is no longer stripped
        self.assertFalse(
            os.path.exists(os.path.join(common.get_snapdir(), 'bin', '1')),
            "Expected part1's stripped files to be cleaned")

        # Verify that part2's file is still there
        self.assertTrue(
            os.path.exists(os.path.join(common.get_snapdir(), 'bin', '2')),
            "Expected part2's stripped files to be untouched")
コード例 #6
0
    def test_clean_stage_after_fileset_change(self):
        # Create part1 and get it through the "build" step.
        handler = pluginhandler.load_plugin('part1', 'nil')
        handler.makedirs()

        bindir = os.path.join(handler.code.installdir, 'bin')
        os.makedirs(bindir)
        open(os.path.join(bindir, '1'), 'w').close()
        open(os.path.join(bindir, '2'), 'w').close()

        handler.mark_done('build')
        handler.stage()

        # Verify that both files have been staged
        self.assertTrue(
            os.path.exists(os.path.join(common.get_stagedir(), 'bin', '1')))
        self.assertTrue(
            os.path.exists(os.path.join(common.get_stagedir(), 'bin', '2')))

        # Now update the `stage` fileset to only snap one of these files
        handler.code.options.stage = ['bin/1']

        # Now clean the strip step for part1
        handler.clean_stage({})

        # Verify that part1's file is no longer staged
        self.assertFalse(
            os.path.exists(os.path.join(common.get_stagedir(), 'bin', '1')),
            'Expected bin/1 to be cleaned')
        self.assertFalse(
            os.path.exists(os.path.join(common.get_stagedir(), 'bin', '2')),
            'Expected bin/2 to be cleaned as well, even though the filesets '
            'changed since it was staged.')
コード例 #7
0
    def make_snapcraft_yaml(self, n=1, create=True):
        parts = '\n'.join([self.yaml_part.format(i) for i in range(n)])
        super().make_snapcraft_yaml(self.yaml_template.format(parts=parts))
        open('icon.png', 'w').close()

        parts = []
        for i in range(n):
            part_name = 'clean{}'.format(i)
            handler = pluginhandler.load_plugin(part_name, 'nil')
            parts.append({
                'part_dir': handler.code.partdir,
            })

            if create:
                handler.makedirs()
                open(os.path.join(
                    handler.code.installdir, part_name), 'w').close()

                handler.mark_done('pull')
                handler.mark_done('build')

                handler.stage()
                handler.strip()

        return parts
コード例 #8
0
ファイル: yaml.py プロジェクト: asac/snapcraft
    def load_plugin(self, part_name, plugin_name, properties):
        part = pluginhandler.load_plugin(
            part_name, plugin_name, properties)

        self.build_tools += part.code.build_packages
        self.all_parts.append(part)
        return part
コード例 #9
0
ファイル: yaml.py プロジェクト: dplanella/snapcraft
    def load_plugin(self, part_name, plugin_name, properties):
        part = pluginhandler.load_plugin(
            part_name, plugin_name, properties)

        self.build_tools += part.code.build_packages
        self.build_tools += sources.get_required_packages(part.code.options)
        self.all_parts.append(part)
        return part
コード例 #10
0
    def load_plugin(self, part_name, plugin_name, properties):
        part = pluginhandler.load_plugin(
            part_name, plugin_name, properties)

        self.build_tools += part.code.build_packages
        self.build_tools += sources.get_required_packages(part.code.options)
        self.all_parts.append(part)
        return part
コード例 #11
0
    def test_clean_strip_order(self):
        handler = pluginhandler.load_plugin('test_part', 'nil')
        handler.clean(step='strip')

        # Verify the step cleaning order
        self.assertEqual(1, len(self.manager_mock.mock_calls))
        self.manager_mock.assert_has_calls([
            call.clean_strip({}),
        ])
コード例 #12
0
    def test_clean_part_already_clean(self, mock_exists, mock_rmtree):
        mock_exists.return_value = False

        part_name = 'test_part'
        p = pluginhandler.load_plugin(part_name, 'nil')
        p.clean()

        partdir = os.path.join(os.path.abspath(os.curdir), 'parts', part_name)
        mock_exists.assert_called_once_with(partdir)
        self.assertFalse(mock_rmtree.called)
コード例 #13
0
    def test_clean_part_already_clean(self, mock_exists, mock_rmtree):
        mock_exists.return_value = False

        part_name = 'test_part'
        p = pluginhandler.load_plugin(part_name, 'nil')
        p.clean()

        partdir = os.path.join(
            os.path.abspath(os.curdir), 'parts', part_name)
        mock_exists.assert_called_once_with(partdir)
        self.assertFalse(mock_rmtree.called)
コード例 #14
0
    def test_makedirs_with_existing_dirs(self):
        part_name = 'test_part'
        dirs = self.get_plugin_dirs(part_name)
        if self.make_dirs:
            os.makedirs(os.path.join('parts', part_name))
            for d in dirs:
                os.mkdir(d)

        p = pluginhandler.load_plugin(part_name, 'nil')
        p.makedirs()
        for d in dirs:
            self.assertTrue(os.path.exists(d), '{} does not exist'.format(d))
コード例 #15
0
    def test_makedirs_with_existing_dirs(self):
        part_name = 'test_part'
        dirs = self.get_plugin_dirs(part_name)
        if self.make_dirs:
            os.makedirs(os.path.join('parts', part_name))
            for d in dirs:
                os.mkdir(d)

        p = pluginhandler.load_plugin(part_name, 'nil')
        p.makedirs()
        for d in dirs:
            self.assertTrue(os.path.exists(d), '{} does not exist'.format(d))
コード例 #16
0
    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())
コード例 #17
0
    def test_clean_old_stage_state(self):
        handler = pluginhandler.load_plugin('part1', 'nil')
        handler.makedirs()

        open(os.path.join(common.get_stagedir(), '1'), 'w').close()

        handler.mark_done('stage', None)

        self.assertTrue(os.path.exists(handler.code.partdir))

        handler.clean()

        self.assertFalse(os.path.exists(handler.code.partdir))
コード例 #18
0
    def test_clean_strip(self):
        filesets = {
            'all': {
                'fileset': ['*'],
            },
            'no1': {
                'fileset': ['-1'],
            },
            'onlya': {
                'fileset': ['a'],
            },
            'onlybase': {
                'fileset': ['*', '-*/*'],
            },
            'nostara': {
                'fileset': ['-*/a'],
            },
        }

        for key, value in filesets.items():
            with self.subTest(key=key):
                self.clear_common_directories()

                handler = pluginhandler.load_plugin('test_part', 'nil', {
                    'snap': value['fileset']
                })
                handler.makedirs()

                installdir = handler.code.installdir
                os.makedirs(installdir + '/1/1a/1b')
                os.makedirs(installdir + '/2/2a')
                os.makedirs(installdir + '/3')
                open(installdir + '/a', mode='w').close()
                open(installdir + '/b', mode='w').close()
                open(installdir + '/1/a', mode='w').close()
                open(installdir + '/3/a', mode='w').close()

                handler.mark_done('build')

                # Stage the installed files
                handler.stage()

                # Now strip them
                handler.strip()

                self.assertTrue(os.listdir(common.get_snapdir()))

                handler.clean_strip({})

                self.assertFalse(os.listdir(common.get_snapdir()),
                                 'Expected snapdir to be completely cleaned')
コード例 #19
0
    def test_clean_part_remaining_parts(self, mock_exists, mock_listdir,
                                        mock_rmdir):
        mock_exists.return_value = True
        mock_listdir.return_value = True

        part_name = 'test_part'
        p = pluginhandler.load_plugin(part_name, 'nil')
        p.clean()

        partdir = os.path.join(
            os.path.abspath(os.curdir), 'parts', part_name)
        mock_exists.assert_called_once_with(partdir)
        mock_listdir.assert_called_once_with(partdir)
        self.assertFalse(mock_rmdir.called)
コード例 #20
0
    def test_mark_done_clears_later_steps(self):
        for index, step in enumerate(common.COMMAND_ORDER):
            shutil.rmtree(common.get_partsdir())
            with self.subTest('{} step'.format(step)):
                handler = pluginhandler.load_plugin('foo', 'nil')
                handler.makedirs()

                for later_step in common.COMMAND_ORDER[index+1:]:
                    open(handler._step_state_file(later_step), 'w').close()

                handler.mark_done(step)

                for later_step in common.COMMAND_ORDER[index+1:]:
                    self.assertFalse(
                        os.path.exists(handler._step_state_file(later_step)),
                        'Expected later step states to be cleared')
コード例 #21
0
    def test_clean_stage_old_stage_state(self):
        handler = pluginhandler.load_plugin('part1', 'nil')
        handler.makedirs()

        staged_file = os.path.join(common.get_stagedir(), '1')
        open(staged_file, 'w').close()

        handler.mark_done('stage', None)

        with self.assertRaises(pluginhandler.MissingState) as raised:
            handler.clean(step='stage')

        self.assertEqual(
            str(raised.exception),
            "Failed to clean step 'stage': Missing necessary state. "
            "This won't work until a complete clean has occurred.")

        self.assertTrue(os.path.isfile(staged_file))
コード例 #22
0
    def test_clean_strip_old_strip_state(self):
        handler = pluginhandler.load_plugin('part1', 'nil')
        handler.makedirs()

        stripped_file = os.path.join(common.get_snapdir(), '1')
        open(stripped_file, 'w').close()

        handler.mark_done('strip', None)

        with self.assertRaises(pluginhandler.MissingState) as raised:
            handler.clean(step='strip')

        self.assertEqual(
            str(raised.exception),
            "Failed to clean step 'strip': Missing necessary state. Please "
            "run strip again.")

        self.assertTrue(os.path.isfile(stripped_file))
コード例 #23
0
    def make_snapcraft_yaml(self, n=1, create=True):
        parts = "\n".join([self.yaml_part.format(i) for i in range(n)])
        super().make_snapcraft_yaml(self.yaml_template.format(parts=parts))
        open("icon.png", "w").close()

        parts = []
        for i in range(n):
            part_name = "clean{}".format(i)
            handler = pluginhandler.load_plugin(part_name, "nil")
            parts.append({"part_dir": handler.code.partdir})

            if create:
                handler.makedirs()
                open(os.path.join(handler.code.installdir, part_name), "w").close()

                handler.mark_done("pull")
                handler.mark_done("build")

                handler.stage()
                handler.strip()

        return parts
コード例 #24
0
    def setUp(self):
        super().setUp()

        part_name = 'test_part'
        self.handler = pluginhandler.load_plugin(part_name, 'nil')
        self.handler.makedirs()