예제 #1
0
    def initialize(self):
        """
        Initialize the UpdateInfo file and set the method used to process the unit to the
        one that is built into the UpdateinfoXMLFileContext
        """
        repo_id = self.get_repo().id
        nevra_fields = ('name', 'epoch', 'version', 'release', 'arch')
        querysets = repo_controller.get_unit_model_querysets(
            repo_id, models.RPM)
        nevra_scalars = itertools.chain(
            *[q.scalar(*nevra_fields) for q in querysets])
        nevra_in_repo = set()
        for scalar in nevra_scalars:
            nevra_in_repo.add(models.NEVRA(*scalar))

        checksum_type = self.parent.get_checksum_type()
        updateinfo_checksum_type = self.get_config().get(
            'updateinfo_checksum_type')
        self.context = UpdateinfoXMLFileContext(self.get_working_dir(),
                                                nevra_in_repo, checksum_type,
                                                self.get_conduit(),
                                                updateinfo_checksum_type)
        self.context.initialize()

        # set the self.process_unit method to the corresponding method on the
        # UpdateInfoXMLFileContext as there is no other processing to be done for each unit.
        self.process_main = self.context.add_unit_metadata
예제 #2
0
    def packages_in_repo(self, repo_id):
        """
        Query for all Python packages in a repository.

        :param repo_id: Identifies the repository from which to retrieve packages
        :type  repo_id: basestring
        :return: QuerySet containing each package in the repo
        :rtype:  mongoengine.queryset.QuerySet
        """
        unit_qs = repo_controller.get_unit_model_querysets(repo_id, self._document)
        return itertools.chain(*unit_qs)
예제 #3
0
    def import_units(self,
                     source_repo,
                     dest_repo,
                     import_conduit,
                     config,
                     units=None):
        """
        Import content units into the given repository. This method will be
        called in a number of different situations:
         * A user is attempting to copy a content unit from one repository
           into the repository that uses this importer
         * A user is attempting to add an orphaned unit into a repository.

        This call has two options for handling the requested units:
         * Associate the given units with the destination repository. This will
           link the repository with the existing unit directly; changes to the
           unit will be reflected in all repositories that reference it.
         * Create a new unit and save it to the repository. This would act as
           a deep copy of sorts, creating a unique unit in the database. Keep
           in mind that the unit key must change in order for the unit to
           be considered different than the supplied one.

        The APIs for both approaches are similar to those in the sync conduit.
        In the case of a simple association, the init_unit step can be skipped
        and save_unit simply called on each specified unit.

        The units argument is optional. If None, all units in the source
        repository should be imported. The conduit is used to query for those
        units. If specified, only the units indicated should be imported (this
        is the case where the caller passed a filter to Pulp).

        :param source_repo:    metadata describing the repository containing the units to import
        :type  source_repo:    pulp.plugins.model.Repository
        :param dest_repo:      metadata describing the repository to import units into
        :type  dest_repo:      pulp.plugins.model.Repository
        :param import_conduit: provides access to relevant Pulp functionality
        :type  import_conduit: pulp.plugins.conduits.unit_import.ImportUnitConduit
        :param config:         plugin configuration
        :type  config:         pulp.plugins.config.PluginCallConfiguration
        :param units:          optional list of pre-filtered units to import
        :type  units:          list of pulp.plugins.model.Unit
        :return:               list of Unit instances that were saved to the destination repository
        :rtype:                list
        """
        if units is None:
            units = chain(*repo_controller.get_unit_model_querysets(
                source_repo.repo_obj.repo_id, models.Package))

        units = list(units)
        for u in units:
            repo_controller.associate_single_unit(dest_repo.repo_obj, u)

        return units
예제 #4
0
 def _get_units(self):
     """
     Get the collection of units to be published.
     The collection contains only the newest unit for each branch.
     :return: An iterable of units to publish.
     :rtype: iterable
     """
     units_by_branch = {}
     units = itertools.chain(*get_unit_model_querysets(self.get_repo().id, Branch))
     for unit in sorted(units, key=lambda u: u.created):
         units_by_branch[unit.branch] = unit
     return units_by_branch.values()
예제 #5
0
 def _get_units(self):
     """
     Get the collection of units to be published.
     The collection contains only the newest unit for each branch.
     :return: An iterable of units to publish.
     :rtype: iterable
     """
     units_by_branch = {}
     units = itertools.chain(*get_unit_model_querysets(self.get_repo().id, Branch))
     for unit in sorted(units, key=lambda u: u.created):
         units_by_branch[unit.branch] = unit
     return units_by_branch.values()
예제 #6
0
 def unit_querysets(self):
     """
     :return: list of QuerySetNoCache objects that correspond to ContentUnit searches for the
              classes passed in to this step. The return value is cached, so multiple accesses of
              this property will return the same list containing the same objects.
     :rtype:  list
     """
     if self._unit_querysets is None:
         self._unit_querysets = []
         for model_class in self.model_classes:
             queries = repo_controller.get_unit_model_querysets(
                 self.get_repo().id, model_class, self._repo_content_unit_q)
             self._unit_querysets.extend(queries)
     return self._unit_querysets
예제 #7
0
 def unit_querysets(self):
     """
     :return: list of QuerySetNoCache objects that correspond to ContentUnit searches for the
              classes passed in to this step. The return value is cached, so multiple accesses of
              this property will return the same list containing the same objects.
     :rtype:  list
     """
     if self._unit_querysets is None:
         self._unit_querysets = []
         for model_class in self.model_classes:
             queries = repo_controller.get_unit_model_querysets(self.get_repo().id,
                                                                model_class,
                                                                self._repo_content_unit_q)
             self._unit_querysets.extend(queries)
     return self._unit_querysets
예제 #8
0
    def import_units(self, source_repo, dest_repo, import_conduit, config, units=None):
        """
        Import content units into the given repository. This method will be
        called in a number of different situations:
         * A user is attempting to copy a content unit from one repository
           into the repository that uses this importer
         * A user is attempting to add an orphaned unit into a repository.

        This call has two options for handling the requested units:
         * Associate the given units with the destination repository. This will
           link the repository with the existing unit directly; changes to the
           unit will be reflected in all repositories that reference it.
         * Create a new unit and save it to the repository. This would act as
           a deep copy of sorts, creating a unique unit in the database. Keep
           in mind that the unit key must change in order for the unit to
           be considered different than the supplied one.

        The APIs for both approaches are similar to those in the sync conduit.
        In the case of a simple association, the init_unit step can be skipped
        and save_unit simply called on each specified unit.

        The units argument is optional. If None, all units in the source
        repository should be imported. The conduit is used to query for those
        units. If specified, only the units indicated should be imported (this
        is the case where the caller passed a filter to Pulp).

        :param source_repo:    metadata describing the repository containing the units to import
        :type  source_repo:    pulp.plugins.model.Repository
        :param dest_repo:      metadata describing the repository to import units into
        :type  dest_repo:      pulp.plugins.model.Repository
        :param import_conduit: provides access to relevant Pulp functionality
        :type  import_conduit: pulp.plugins.conduits.unit_import.ImportUnitConduit
        :param config:         plugin configuration
        :type  config:         pulp.plugins.config.PluginCallConfiguration
        :param units:          optional list of pre-filtered units to import
        :type  units:          list of pulp.plugins.model.Unit
        :return:               list of Unit instances that were saved to the destination repository
        :rtype:                list
        """
        if units is None:
            units = chain(*repo_controller.get_unit_model_querysets(source_repo.repo_obj.repo_id,
                                                                    models.Package))

        units = list(units)
        for u in units:
            repo_controller.associate_single_unit(dest_repo.repo_obj, u)

        return units
예제 #9
0
    def initialize(self):
        """
        Initialize the UpdateInfo file and set the method used to process the unit to the
        one that is built into the UpdateinfoXMLFileContext
        """
        repo_id = self.get_repo().id
        nevra_fields = ('name', 'epoch', 'version', 'release', 'arch')
        querysets = repo_controller.get_unit_model_querysets(repo_id, models.RPM)
        nevra_scalars = itertools.chain(*[q.scalar(*nevra_fields) for q in querysets])
        nevra_in_repo = set()
        for scalar in nevra_scalars:
            nevra_in_repo.add(models.NEVRA(*scalar))

        checksum_type = self.parent.get_checksum_type()
        updateinfo_checksum_type = self.get_config().get('updateinfo_checksum_type')
        self.context = UpdateinfoXMLFileContext(self.get_working_dir(), nevra_in_repo,
                                                checksum_type, self.get_conduit(),
                                                updateinfo_checksum_type)
        self.context.initialize()

        # set the self.process_unit method to the corresponding method on the
        # UpdateInfoXMLFileContext as there is no other processing to be done for each unit.
        self.process_main = self.context.add_unit_metadata
예제 #10
0
def _get_packages(repo_id):
    """
    Build and return a data structure of the available packages. The keys each index a list of
    dictionaries. The inner dictionaries are of the form
    {'version': VERSION, 'filename': FILENAME, 'checksum': MD5SUM, 'checksum_type': TYPE,
     'storage_path': PATH}

    :param repo_id: ID of the repo being published.
    :type  repo_id: basestring
    :return:        A dictionary of all the packages in the repo to be published
    :rtype:         dict
    """
    packages = {}
    fields = ('version', '_filename', '_checksum', '_checksum_type', 'name', '_storage_path')
    unit_querysets = repo_controller.get_unit_model_querysets(repo_id, models.Package)
    unit_querysets = (q.only(*fields) for q in unit_querysets)
    for p in itertools.chain(*unit_querysets):
        packages.setdefault(p.name, []).append(
            {'version': p.version,
             'filename': p._filename,
             'checksum': p._checksum,
             'checksum_type': p._checksum_type,
             'storage_path': p.storage_path})
    return packages