コード例 #1
0
def record_details(paragraph, package, branch):
    """
    Queries the database for the details of a given package.
    If there are no details then they are recorded.

    :param paragraph: contains information about a binary package.

    :param package: a `Package` object to which the details are related.

    :param branch: codename of the Canaima's version that will be recorded.

    :return: a `Details` object.

    :rtype: ``Details``

    .. versionadded:: 0.1
    """

    try:
        return Details.objects.get(package=package,
                                   Architecture=paragraph['Architecture'],
                                   Distribution=branch)
    except Details.DoesNotExist:
        details = Details(Distribution=branch)
        for field, db_field in DETAIL_FIELDS.items():
            setattr(details, db_field, paragraph.get(field))
        details.save()
        package.Details.add(details)
        return details
コード例 #2
0
    def create_auto(self, paragraph, package, branch, comp):
        """
        Queries the database for the details of a given package.
        If there are no details then they are recorded.
    
        :param paragraph: contains information about a binary package.
    
        :param package: a `Package` object to which the details are related.
    
        :param branch: codename of the Canaima's version that will be recorded.
        
        :param comp: component to which the paragraph belongs.
    
        :return: a `Details` object.
    
        :rtype: ``Details``
    
        .. versionadded:: 0.2
        """

        try:
            return self.get(package=package,
                            Architecture=paragraph['Architecture'],
                            Distribution=branch,
                            Component=comp)
        except Details.DoesNotExist:
            details = self.create(Distribution=branch, Component=comp)
            for field, db_field in DETAIL_FIELDS.items():
                setattr(details, db_field, paragraph.get(field))
            details.save()
            details.add_relations(paragraph.relations.items())
            package.Details.add(details)
            return details
コード例 #3
0
    def test_update_paragraph(self):

        from tribus.common.recorder import update_paragraph
        from tribus.config.pkgrecorder import PACKAGE_FIELDS, DETAIL_FIELDS

        old_paragraph = deb822.Packages(open(get_path([SMPLDIR, 'Blender'])))
        new_paragraph = deb822.Packages(open(get_path([SMPLDIR,
                                                       'BlenderNew'])))

        Package.objects.create_auto(old_paragraph, test_dist, 'main')
        update_paragraph(new_paragraph, test_dist, 'main')

        p = Package.objects.get(Name='blender')
        d = Details.objects.get(package=p)
        name, mail = email.Utils.parseaddr(new_paragraph.get('Maintainer'))
        total_relations = 0
        total_labels = 0

        self.assertEqual(p.Maintainer.Name, name)
        self.assertEqual(p.Maintainer.Email, mail)
        self.assertEqual(d.Distribution, test_dist)

        tag_list = new_paragraph['Tag'].replace('\n', '').split(', ')
        clean_list = [tuple(tag.split('::')) for tag in tag_list]

        for label in p.Labels.all():
            total_labels += 1
            self.assertIn((label.Name, label.Tags.Value), clean_list)

        self.assertEqual(total_labels, len(clean_list))

        for field, field_db in PACKAGE_FIELDS.items():
            if new_paragraph.get(field):
                self.assertEqual(str(getattr(p, field_db)),
                                 new_paragraph[field])

        for field, field_db in DETAIL_FIELDS.items():
            if new_paragraph.get(field):
                self.assertEqual(str(getattr(d, field_db)),
                                 new_paragraph[field])

        for _, relations in new_paragraph.relations.items():
            if relations:
                for relation in relations:
                    if len(relation) > 1:
                        for _ in relation:
                            total_relations += 1
                    else:
                        total_relations += 1

        self.assertEqual(d.Relations.all().count(), total_relations)
コード例 #4
0
    def test_details_create(self):
        '''
        El objetivo de este test es verificar que los campos de detalles
        sean registrados correctamente.
        '''

        from tribus.config.pkgrecorder import DETAIL_FIELDS
        paragraph = deb822.Packages(open(os.path.join(SAMPLESDIR, "Blender")))
        package, _ = Package.objects.get_or_create(Name='blender')
        details = Details.objects.create_auto(paragraph, package, test_dist,
                                              "main")
        self.assertEqual(details.Distribution, test_dist)
        for field, field_db in DETAIL_FIELDS.items():
            self.assertEqual(getattr(details, field_db), paragraph[field])
コード例 #5
0
    def test_package_create_auto(self):
        """
        El objetivo de este test es verificar que los campos basicos
        de un paquete sean registrados correctamente.
        """

        from tribus.config.pkgrecorder import PACKAGE_FIELDS, DETAIL_FIELDS
        paragraph = deb822.Packages(open(os.path.join(SAMPLESDIR, 'Blender')))
        p = Package.objects.create_auto(paragraph, test_dist, 'main')
        d = Details.objects.get(package=p)
        total_relations = 0

        name, mail = parseaddr(paragraph.get('Maintainer'))

        self.assertEqual(d.Distribution, test_dist)
        self.assertEqual(p.Maintainer.Name, name)
        self.assertEqual(p.Maintainer.Email, mail)

        tag_list = paragraph['Tag'].replace('\n', '').split(', ')
        clean_list = [tuple(tag.split('::')) for tag in tag_list]

        for label in p.Labels.all():
            self.assertIn((label.Name, label.Tags.Value), clean_list)

        for field, field_db in PACKAGE_FIELDS.items():
            if paragraph.get(field):
                self.assertEqual(str(getattr(p, field_db)), paragraph[field])

        for field, field_db in DETAIL_FIELDS.items():
            if paragraph.get(field):
                self.assertEqual(str(getattr(d, field_db)), paragraph[field])

        for _, relations in paragraph.relations.items():
            if relations:
                for relation in relations:
                    if len(relation) > 1:
                        for _ in relation:
                            total_relations += 1
                    else:
                        total_relations += 1

        self.assertEqual(d.Relations.all().count(), total_relations)
コード例 #6
0
ファイル: models.py プロジェクト: wyanez/tribus
 def add_details(self, paragraph, branch, comp):
     '''
     Creates a new Details objects and relates it to the package.
     
     :param paragraph: contains information about a binary package.
     
     :param branch: codename of the Canaima's version that will be updated.
     
     :param comp: component to which the paragraph belongs.
     
     .. versionadded:: 0.2
     '''
     
     details = Details.objects.create(Distribution=branch, Component = comp)
     for field, db_field in DETAIL_FIELDS.items():
         setattr(details, db_field, paragraph.get(field))
     details.save()
     details.add_relations(paragraph.relations.items())
     self.Details.add(details)
     logger.info('Adding new details to \'%s\' package in \'%s\' branch...'  % (paragraph['package'], branch))
     return details
コード例 #7
0
    def update(self, paragraph):
        """
        Updates the details of a Package in the database.
    
        :param paragraph: contains information about a binary package.
    
        :return: a `Details` object.
    
        :rtype: ``Details``
    
        .. versionadded:: 0.1
        """

        for field, db_field in DETAIL_FIELDS.items():
            setattr(self, db_field, paragraph.get(field))
        self.save()

        for relation in self.Relations.all():
            self.Relations.remove(relation)
            exists = Details.objects.filter(Relations=relation)
            if not exists:
                relation.delete()
        self.add_relations(paragraph.relations.items())
コード例 #8
0
def update_details(package, paragraph, branch):
    """
    Updates the details of a Package in the database.

    :param package: a `Package` object to which the details are related.

    :param paragraph: contains information about a binary package.

    :param branch: codename of the Canaima's version that will be updated.

    :return: a `Details` object.

    :rtype: ``Details``

    .. versionadded:: 0.1
    """

    details = Details.objects.get(package=package,
                                  Architecture=paragraph['Architecture'],
                                  Distribution=branch)
    for field, db_field in DETAIL_FIELDS.items():
        setattr(details, db_field, paragraph.get(field))
    details.save()
    return details