コード例 #1
0
    def _load_code(self, plugin_name, properties, part_schema,
                   definitions_schema):
        module_name = plugin_name.replace('-', '_')
        module = None

        with contextlib.suppress(ImportError):
            module = _load_local('x-{}'.format(plugin_name),
                                 self._project_options.local_plugins_dir)
            logger.info('Loaded local plugin for %s', plugin_name)

        if not module:
            with contextlib.suppress(ImportError):
                module = importlib.import_module(
                    'snapcraft.plugins.{}'.format(module_name))

        if not module:
            logger.info('Searching for local plugin for %s', plugin_name)
            with contextlib.suppress(ImportError):
                module = _load_local(module_name,
                                     self._project_options.local_plugins_dir)
            if not module:
                raise PluginError('unknown plugin: {}'.format(plugin_name))

        plugin = _get_plugin(module)
        _validate_pull_and_build_properties(plugin_name, plugin, part_schema,
                                            definitions_schema)
        options = _make_options(part_schema, definitions_schema, properties,
                                plugin.schema())
        # For backwards compatibility we add the project to the plugin
        try:
            self.code = plugin(self.name, options, self._project_options)
        except TypeError:
            logger.warning(
                'DEPRECATED: the plugin used by part {!r} needs to be updated '
                'to accept project options in its initializer. See '
                'https://github.com/snapcore/snapcraft/blob/master/docs/'
                'plugins.md#initializing-a-plugin for more information'.format(
                    self.name))
            self.code = plugin(self.name, options)
            # This is for plugins that don't inherit from BasePlugin
            if not hasattr(self.code, 'project'):
                setattr(self.code, 'project', self._project_options)
            # This is for plugins that inherit from BasePlugin but don't have
            # project in init.
            if not self.code.project:
                self.code.project = self._project_options

        if self._project_options.is_cross_compiling:
            logger.debug(
                'Setting {!r} as the compilation target for {!r}'.format(
                    self._project_options.deb_arch, plugin_name))
            self.code.enable_cross_compilation()
コード例 #2
0
    def __init__(self, *, plugin_name, part_name, part_properties,
                 project_options, part_schema, definitions_schema):
        self.valid = False
        self.code = None
        self.config = {}
        self._name = part_name
        self._part_properties = _expand_part_properties(
            part_properties, part_schema)
        self.stage_packages = []
        self.build_packages = []

        # Some legacy parts can have a '/' in them to separate the main project
        # part with the subparts. This is rather unfortunate as it affects the
        # the layout of parts inside the parts directory causing collisions
        # between the main project part and its subparts.
        part_name = part_name.replace('/', '\N{BIG SOLIDUS}')
        self._project_options = project_options
        self.deps = []

        self.stagedir = project_options.stage_dir
        self.primedir = project_options.prime_dir

        parts_dir = project_options.parts_dir
        self.ubuntudir = os.path.join(parts_dir, part_name, 'ubuntu')
        self.statedir = os.path.join(parts_dir, part_name, 'state')
        self.sourcedir = os.path.join(parts_dir, part_name, 'src')

        self.source_handler = self._get_source_handler(self._part_properties)

        self._build_attributes = BuildAttributes(
            self._part_properties['build-attributes'])

        self._migrate_state_file()

        try:
            self._load_code(plugin_name, self._part_properties, part_schema,
                            definitions_schema)
        except jsonschema.ValidationError as e:
            error = SnapcraftSchemaError.from_validation_error(e)
            raise PluginError('properties failed to load for {}: {}'.format(
                part_name, error.message))

        stage_packages = getattr(self.code, 'stage_packages', [])
        sources = getattr(self.code, 'PLUGIN_STAGE_SOURCES', None)
        self._stage_package_handler = StagePackageHandler(
            stage_packages,
            self.ubuntudir,
            sources=sources,
            project_options=self._project_options)
コード例 #3
0
    def __init__(self, *, plugin_name, part_name, part_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 = project_options.stage_dir
        self.snapdir = project_options.snap_dir

        parts_dir = project_options.parts_dir
        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, part_properties, part_schema)
        except jsonschema.ValidationError as e:
            raise PluginError('properties failed to load for {}: {}'.format(
                part_name, e.message))
コード例 #4
0
ファイル: __init__.py プロジェクト: teknoraver/snapcraft
def _validate_relative_paths(files):
    for d in files:
        if os.path.isabs(d):
            raise PluginError('path "{}" must be relative'.format(d))