本文整理汇总了Python中snapcraft.pluginhandler.load_plugin函数的典型用法代码示例。如果您正苦于以下问题:Python load_plugin函数的具体用法?Python load_plugin怎么用?Python load_plugin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_plugin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
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: test_init_unknown_plugin_must_raise_exception
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')
示例3: test_clean_strip_multiple_independent_parts
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")
示例4: make_snapcraft_yaml
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
示例5: load_plugin
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
示例6: test_clean_stage_after_fileset_change
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: load_plugin
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
示例8: test_clean_strip_order
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({}),
])
示例9: test_clean_part_already_clean
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)
示例10: test_makedirs_with_existing_dirs
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))
示例11: 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())
示例12: test_clean_old_stage_state
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))
示例13: test_clean_strip
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')
示例14: test_clean_part_remaining_parts
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)
示例15: test_mark_done_clears_later_steps
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')