Exemplo n.º 1
0
    def test_sqlite_other(self):
        path = os.path.join(self.tmpdir, "other.db")
        db = cr.Sqlite(path, cr.DB_FILELISTS)
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        db.add_pkg(pkg)
        db.dbinfo_update("somechecksum3")
        db.close()

        self.assertTrue(os.path.isfile(path))

        con = sqlite3.connect(path)

        # Check packages table
        self.assertEqual(
            con.execute("select * from packages").fetchall(),
            [(1,
              u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e'
              )])

        # Check filelist table
        self.assertEqual(
            set(con.execute("select * from filelist").fetchall()),
            set([(1, u'/usr/share/doc', u'Archer-3.4.5', u'd'),
                 (1, u'/usr/bin', u'complex_a', u'f'),
                 (1, u'/usr/share/doc/Archer-3.4.5', u'README', u'f')]))

        # Check db_info table
        self.assertEqual(
            con.execute("select * from db_info").fetchall(),
            [(10, u'somechecksum3')])
Exemplo n.º 2
0
def _prepare_package(artifact, filename):
    """
    Helper function for creating package.

    Copy file to a temp directory under
    the user provided filename and
    parsing it into a saveable format.

    Returns: artifact model as dict

    Args:
        artifact: inited and validated artifact to save
        filename: name of file uploaded by user
    """
    # Copy file to a temp directory under the user provided filename
    with tempfile.TemporaryDirectory() as td:
        temp_path = os.path.join(td, filename)
        shutil.copy2(artifact.file.path, temp_path)
        cr_pkginfo = createrepo_c.package_from_rpm(temp_path)

        package = Package.createrepo_to_dict(cr_pkginfo)

    package['location_href'] = filename

    # parsing it into a saveable format
    new_pkg = {}
    for key, value in package.items():
        if isinstance(value, list):
            new_pkg[key] = json.dumps(value)
        else:
            new_pkg[key] = value

    return new_pkg
Exemplo n.º 3
0
    def test_sqlite_other(self):
        path = os.path.join(self.tmpdir, "other.db")
        db = cr.Sqlite(path, cr.DB_FILELISTS)
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        db.add_pkg(pkg)
        db.dbinfo_update("somechecksum3")
        db.close()

        self.assertTrue(os.path.isfile(path))

        con = sqlite3.connect(path)

        # Check packages table
        self.assertEqual(con.execute("select * from packages").fetchall(),
            [(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e')])

        # Check filelist table
        self.assertEqual(set(con.execute("select * from filelist").fetchall()),
            set([(1, u'/usr/share/doc', u'Archer-3.4.5', u'd'),
             (1, u'/usr/bin', u'complex_a', u'f'),
             (1, u'/usr/share/doc/Archer-3.4.5', u'README', u'f')]))

        # Check db_info table
        self.assertEqual(con.execute("select * from db_info").fetchall(),
            [(10, u'somechecksum3')])
Exemplo n.º 4
0
def _prepare_package(artifact, filename):
    """
    Helper function for creating package.

    Copy file to a temp directory under
    the user provided filename.

    Returns: artifact model as dict

    Args:
        artifact: inited and validated artifact to save
        filename: name of file uploaded by user
    """
    artifact_file = storage.open(artifact.file.name)
    with tempfile.NamedTemporaryFile("wb", dir=".",
                                     suffix=filename) as temp_file:
        shutil.copyfileobj(artifact_file, temp_file)
        temp_file.flush()
        cr_pkginfo = createrepo_c.package_from_rpm(
            temp_file.name, changelog_limit=settings.KEEP_CHANGELOG_LIMIT)

    package = Package.createrepo_to_dict(cr_pkginfo)

    package["location_href"] = filename
    artifact_file.close()
    return package
Exemplo n.º 5
0
    def test_contentstat(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        pkg.time_file = 1
        pkg.time_build = 1

        cs = cr.ContentStat(cr.SHA256)
        self.assertEqual(cs.size, 0)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, None)

        path = os.path.join(self.tmpdir, "primary.xml.gz")
        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION, cs)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        f.close()

        self.assertTrue(os.path.isfile(path))

        self.assertEqual(cs.size, 2675)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, "4eff31e3ee2cb389aaee7d2891104"\
                                      "6e8679440f9c5884e02a65b59e2fb0a2dc8")
Exemplo n.º 6
0
    def test_contentstat(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        pkg.time_file = 1
        pkg.time_build = 1

        cs = cr.ContentStat(cr.SHA256)
        self.assertEqual(cs.size, 0)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, None)

        path = os.path.join(self.tmpdir, "primary.xml.gz")
        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION, cs)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        f.close()

        self.assertTrue(os.path.isfile(path))

        self.assertEqual(cs.size, 2668)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, "67bc6282915fad80dc11f3d7c3210977a0bde"\
                                      "05a762256d86083c2447d425776")
Exemplo n.º 7
0
    def test_contentstat(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        pkg.time_file = 1
        pkg.time_build = 1

        cs = cr.ContentStat(cr.SHA256)
        self.assertEqual(cs.size, 0)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, None)

        path = os.path.join(self.tmpdir, "primary.xml.gz")
        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION, cs)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        f.close()

        self.assertTrue(os.path.isfile(path))

        self.assertEqual(cs.size, 2668)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, "67bc6282915fad80dc11f3d7c3210977a0bde"\
                                      "05a762256d86083c2447d425776")
Exemplo n.º 8
0
    def test_sqlite_operations_on_closed_db(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        path = os.path.join(self.tmpdir, "primary.db")
        db = cr.Sqlite(path, cr.DB_PRIMARY)
        self.assertTrue(db)
        db.close()

        self.assertRaises(cr.CreaterepoCError, db.add_pkg, pkg)
        self.assertRaises(cr.CreaterepoCError, db.dbinfo_update, "somechecksum")

        db.close()  # No error shoud be raised
        del db      # No error shoud be raised
Exemplo n.º 9
0
    def test_pkg_id_str_03(self):
        pkg = cr.package_from_rpm(fixtures.PACKAGE_ARCHER)
        idstr = pkg_id_str(pkg)
        self.assertEqual(idstr, "4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e")

        pkg.location_href = os.path.basename(fixtures.PACKAGE_ARCHER)
        idstr = pkg_id_str(pkg)
        self.assertEqual(idstr, "4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9eArcher-3.4.5-6.x86_64.rpm")

        pkg.location_base = "https://foobar/"
        idstr = pkg_id_str(pkg)
        self.assertEqual(idstr, "4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9eArcher-3.4.5-6.x86_64.rpmhttps://foobar/")
Exemplo n.º 10
0
    def test_sqlite_operations_on_closed_db(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        path = os.path.join(self.tmpdir, "primary.db")
        db = cr.Sqlite(path, cr.DB_PRIMARY)
        self.assertTrue(db)
        db.close()

        self.assertRaises(cr.CreaterepoCError, db.add_pkg, pkg)
        self.assertRaises(cr.CreaterepoCError, db.dbinfo_update, "somechecksum")

        db.close()  # No error shoud be raised
        del db      # No error shoud be raised
Exemplo n.º 11
0
    def create(self, request):
        """
        Create a new Package from a request.
        """
        try:
            artifact = self.get_resource(request.data['_artifact'], Artifact)
        except KeyError:
            raise serializers.ValidationError(
                detail={'_artifact': _('This field is required')})

        try:
            filename = request.data['filename']
        except KeyError:
            raise serializers.ValidationError(
                detail={'filename': _('This field is required')})

        # Copy file to a temp directory under the user provided filename
        with tempfile.TemporaryDirectory() as td:
            temp_path = os.path.join(td, filename)
            shutil.copy2(artifact.file.path, temp_path)
            cr_pkginfo = createrepo_c.package_from_rpm(temp_path)
            package = Package.createrepo_to_dict(cr_pkginfo)

        package['location_href'] = filename

        # TODO: Clean this up, maybe make a new function for the purpose of parsing it into
        # a saveable format
        new_pkg = {}
        new_pkg['_artifact'] = request.data['_artifact']

        for key, value in package.items():
            if isinstance(value, list):
                new_pkg[key] = json.dumps(value)
            else:
                new_pkg[key] = value

        serializer = self.get_serializer(data=new_pkg)
        serializer.is_valid(raise_exception=True)
        serializer.validated_data.pop('_artifact')
        package = serializer.save()
        if package.pk:
            ContentArtifact.objects.create(artifact=artifact,
                                           content=package,
                                           relative_path=package.filename)

        headers = self.get_success_headers(request.data)
        return Response(serializer.data,
                        status=status.HTTP_201_CREATED,
                        headers=headers)
Exemplo n.º 12
0
    def test_xmlfile_operations_on_closed_file(self):
        # Already closed file
        path = os.path.join(self.tmpdir, "primary.xml.gz")
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.close()
        self.assertRaises(cr.CreaterepoCError, f.set_num_of_pkgs, 1)
        self.assertRaises(cr.CreaterepoCError, f.add_pkg, pkg)
        self.assertRaises(cr.CreaterepoCError, f.add_chunk, "<chunk>text</chunk>")
        f.close() # No error should be raised
        del(f)    # No error should be raised
Exemplo n.º 13
0
    def test_xmlfile_operations_on_closed_file(self):
        # Already closed file
        path = os.path.join(self.tmpdir, "primary.xml.gz")
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.close()
        self.assertRaises(cr.CreaterepoCError, f.set_num_of_pkgs, 1)
        self.assertRaises(cr.CreaterepoCError, f.add_pkg, pkg)
        self.assertRaises(cr.CreaterepoCError, f.add_chunk, "<chunk>text</chunk>")
        self.assertEqual("<createrepo_c.XmlFile Closed object>", f.__str__())
        f.close() # No error should be raised
        del(f)    # No error should be raised
Exemplo n.º 14
0
    def test_package_from_rpm(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "Archer")

        pkg = cr.package_from_rpm(PKG_BALICEK_ISO88591_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "balicek-iso88591")

        pkg = cr.package_from_rpm(PKG_BALICEK_ISO88592_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "balicek-iso88592")

        pkg = cr.package_from_rpm(PKG_BALICEK_UTF8_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "balicek-utf8")

        pkg = cr.package_from_rpm(PKG_EMPTY_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "empty")

        pkg = cr.package_from_rpm(PKG_EMPTY_SRC_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "empty")

        pkg = cr.package_from_rpm(PKG_FAKE_BASH_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "fake_bash")

        pkg = cr.package_from_rpm(PKG_SUPER_KERNEL_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "super_kernel")

        # Test error cases

        # Rpm doesn't exists
        self.assertRaises(IOError, cr.package_from_rpm,
                          "this_foo_pkg_shoud_not_exists.rpm")

        # Path is a directory, not a file
        self.assertRaises(IOError, cr.package_from_rpm, "./")

        # File is not a rpm
        self.assertRaises(IOError, cr.package_from_rpm, FILE_BINARY_PATH)
Exemplo n.º 15
0
    def test_package_from_rpm(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "Archer")

        pkg = cr.package_from_rpm(PKG_BALICEK_ISO88591_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "balicek-iso88591")

        pkg = cr.package_from_rpm(PKG_BALICEK_ISO88592_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "balicek-iso88592")

        pkg = cr.package_from_rpm(PKG_BALICEK_UTF8_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "balicek-utf8")

        pkg = cr.package_from_rpm(PKG_EMPTY_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "empty")

        pkg = cr.package_from_rpm(PKG_EMPTY_SRC_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "empty")

        pkg = cr.package_from_rpm(PKG_FAKE_BASH_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "fake_bash")

        pkg = cr.package_from_rpm(PKG_SUPER_KERNEL_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.name, "super_kernel")

        # Test error cases

        # Rpm doesn't exists
        self.assertRaises(IOError, cr.package_from_rpm, "this_foo_pkg_shoud_not_exists.rpm")

        # Path is a directory, not a file
        self.assertRaises(IOError, cr.package_from_rpm, "./")

        # File is not a rpm
        self.assertRaises(IOError, cr.package_from_rpm, FILE_BINARY_PATH)
Exemplo n.º 16
0
    def test_package_empty(self):
        pkg = cr.package_from_rpm(PKG_EMPTY_PATH)
        self.assertTrue(pkg)
        self.assertEqual(
            pkg.pkgId,
            "91afc5e3a124eedfc5bc52737940950b42a37c611dccecad4692a4eb317f9810")
        self.assertEqual(pkg.name, "empty")
        self.assertEqual(pkg.arch, "x86_64")
        self.assertEqual(pkg.version, "0")
        self.assertEqual(pkg.epoch, "0")
        self.assertEqual(pkg.release, "0")
        self.assertEqual(pkg.summary, '""')
        self.assertEqual(pkg.description, None)
        self.assertEqual(pkg.url, None)
        #self.assertEqual(pkg.time_file, 1340709886)
        self.assertEqual(pkg.time_build, 1340696582)
        self.assertEqual(pkg.rpm_license, "LGPL")
        self.assertEqual(pkg.rpm_vendor, None)
        self.assertEqual(pkg.rpm_group, "Unspecified")
        self.assertEqual(pkg.rpm_buildhost, "localhost.localdomain")
        self.assertEqual(pkg.rpm_sourcerpm, "empty-0-0.src.rpm")
        self.assertEqual(pkg.rpm_header_start, 280)
        self.assertEqual(pkg.rpm_header_end, 1285)
        self.assertEqual(pkg.rpm_packager, None)
        self.assertEqual(pkg.size_package, 1401)
        self.assertEqual(pkg.size_installed, 0)
        self.assertEqual(pkg.size_archive, 124)
        self.assertEqual(pkg.location_href, None)
        self.assertEqual(pkg.location_base, None)
        self.assertEqual(pkg.checksum_type, "sha256")
        self.assertEqual(pkg.requires, [])
        self.assertEqual(pkg.provides,
                         [('empty', 'EQ', '0', '0', '0', False),
                          ('empty(x86-64)', 'EQ', '0', '0', '0', False)])
        self.assertEqual(pkg.conflicts, [])
        self.assertEqual(pkg.obsoletes, [])
        self.assertEqual(pkg.suggests, [])
        self.assertEqual(pkg.enhances, [])
        self.assertEqual(pkg.recommends, [])
        self.assertEqual(pkg.supplements, [])
        self.assertEqual(pkg.files, [])
        self.assertEqual(pkg.changelogs, [])

        self.assertEqual(pkg.nvra(), "empty-0-0.x86_64")
        self.assertEqual(pkg.nevra(), "empty-0:0-0.x86_64")
Exemplo n.º 17
0
    def test_package_empty(self):
        pkg = cr.package_from_rpm(PKG_EMPTY_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.pkgId, "91afc5e3a124eedfc5bc52737940950b42a37c611dccecad4692a4eb317f9810")
        self.assertEqual(pkg.name, "empty")
        self.assertEqual(pkg.arch, "x86_64")
        self.assertEqual(pkg.version, "0")
        self.assertEqual(pkg.epoch, "0")
        self.assertEqual(pkg.release, "0")
        self.assertEqual(pkg.summary, '""')
        self.assertEqual(pkg.description, None)
        self.assertEqual(pkg.url, None)
        #self.assertEqual(pkg.time_file, 1340709886)
        self.assertEqual(pkg.time_build, 1340696582)
        self.assertEqual(pkg.rpm_license, "LGPL")
        self.assertEqual(pkg.rpm_vendor, None)
        self.assertEqual(pkg.rpm_group, "Unspecified")
        self.assertEqual(pkg.rpm_buildhost, "localhost.localdomain")
        self.assertEqual(pkg.rpm_sourcerpm, "empty-0-0.src.rpm")
        self.assertEqual(pkg.rpm_header_start, 280)
        self.assertEqual(pkg.rpm_header_end, 1285)
        self.assertEqual(pkg.rpm_packager, None)
        self.assertEqual(pkg.size_package, 1401)
        self.assertEqual(pkg.size_installed, 0)
        self.assertEqual(pkg.size_archive, 124)
        self.assertEqual(pkg.location_href, None)
        self.assertEqual(pkg.location_base, None)
        self.assertEqual(pkg.checksum_type, "sha256")
        self.assertEqual(pkg.requires, [])
        self.assertEqual(pkg.provides, [
            ('empty', 'EQ', '0', '0', '0', False),
            ('empty(x86-64)', 'EQ', '0', '0', '0', False)
        ])
        self.assertEqual(pkg.conflicts, [])
        self.assertEqual(pkg.obsoletes, [])
        self.assertEqual(pkg.suggests, [])
        self.assertEqual(pkg.enhances, [])
        self.assertEqual(pkg.recommends, [])
        self.assertEqual(pkg.supplements, [])
        self.assertEqual(pkg.files, [])
        self.assertEqual(pkg.changelogs, [])

        self.assertEqual(pkg.nvra(), "empty-0-0.x86_64")
        self.assertEqual(pkg.nevra(), "empty-0:0-0.x86_64")
Exemplo n.º 18
0
def createrepo(base: pathlib.Path):
    if not base.exists() or not base.is_dir():
        raise FileExistsError(f'No such directory: {base}')

    repodata = Repodata(base)

    # gather packages
    all_rpm_files = set(base.glob('**/*.rpm'))
    debug_rpm_files = set(base.glob('debug/**/*.rpm'))
    rpm_files = sorted(all_rpm_files - debug_rpm_files)

    repodata.set_num_of_pkgs(len(rpm_files))

    for rpm_file in rpm_files:
        pkg = createrepo_c.package_from_rpm(f'{rpm_file}')
        pkg.location_href = f'{rpm_file.relative_to(base)}'
        repodata.add_pkg(pkg)

    repodata.save()
Exemplo n.º 19
0
def read_crpackage_from_artifact(artifact):
    """
    Helper function for creating package.

    Copy file to a temp directory and parse it.

    Returns: package model as dict

    Args:
        artifact: inited and validated artifact to save
    """
    filename = f"{artifact.pulp_id}.rpm"
    artifact_file = storage.open(artifact.file.name)
    with tempfile.NamedTemporaryFile("wb", dir=".", suffix=filename) as temp_file:
        shutil.copyfileobj(artifact_file, temp_file)
        temp_file.flush()
        cr_pkginfo = createrepo_c.package_from_rpm(
            temp_file.name, changelog_limit=settings.KEEP_CHANGELOG_LIMIT
        )

    artifact_file.close()
    return cr_pkginfo
Exemplo n.º 20
0
    def test_contentstat_ref_in_xmlfile(self):
        """Test if reference is saved properly"""

        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        pkg.time_file = 1
        pkg.time_build = 1

        cs = cr.ContentStat(cr.SHA256)
        self.assertEqual(cs.size, 0)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, None)

        path = os.path.join(self.tmpdir, "primary.xml.gz")
        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION, cs)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        del cs
        f.add_pkg(pkg)
        f.close()

        self.assertTrue(os.path.isfile(path))
Exemplo n.º 21
0
def _prepare_package(artifact, filename):
    """
    Helper function for creating package.

    Copy file to a temp directory under
    the user provided filename.

    Returns: artifact model as dict

    Args:
        artifact: inited and validated artifact to save
        filename: name of file uploaded by user
    """
    # Copy file to a temp directory under the user provided filename
    with tempfile.TemporaryDirectory() as td:
        temp_path = os.path.join(td, filename)
        shutil.copy2(artifact.file.path, temp_path)
        cr_pkginfo = createrepo_c.package_from_rpm(temp_path)

        package = Package.createrepo_to_dict(cr_pkginfo)

    package['location_href'] = filename
    return package
Exemplo n.º 22
0
def _prepare_package(artifact, filename):
    """
    Helper function for creating package.

    Copy file to a temp directory under
    the user provided filename.

    Returns: artifact model as dict

    Args:
        artifact: inited and validated artifact to save
        filename: name of file uploaded by user
    """
    artifact_file = storage.open(artifact.file.name)
    with tempfile.NamedTemporaryFile('wb', suffix=filename) as temp_file:
        shutil.copyfileobj(artifact_file, temp_file)
        temp_file.flush()
        cr_pkginfo = createrepo_c.package_from_rpm(temp_file.name)

    package = Package.createrepo_to_dict(cr_pkginfo)

    package['location_href'] = filename
    return package
Exemplo n.º 23
0
    def test_contentstat_ref_in_xmlfile(self):
        """Test if reference is saved properly"""

        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)

        pkg.time_file = 1
        pkg.time_build = 1

        cs = cr.ContentStat(cr.SHA256)
        self.assertEqual(cs.size, 0)
        self.assertEqual(cs.checksum_type, cr.SHA256)
        self.assertEqual(cs.checksum, None)

        path = os.path.join(self.tmpdir, "primary.xml.gz")
        f = cr.PrimaryXmlFile(path, cr.GZ_COMPRESSION, cs)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        del cs
        f.add_pkg(pkg)
        f.close()

        self.assertTrue(os.path.isfile(path))
Exemplo n.º 24
0
def publish(publisher_pk, repository_version_pk):
    """
    Use provided publisher to create a Publication based on a RepositoryVersion.

    Args:
        publisher_pk (str): Use the publish settings provided by this publisher.
        repository_version_pk (str): Create a publication from this repository version.
    """
    publisher = RpmPublisher.objects.get(pk=publisher_pk)
    repository_version = RepositoryVersion.objects.get(
        pk=repository_version_pk)

    log.info(
        _('Publishing: repository={repo}, version={version}, publisher={publisher}'
          ).format(
              repo=repository_version.repository.name,
              version=repository_version.number,
              publisher=publisher.name,
          ))

    with WorkingDirectory():
        with Publication.create(repository_version, publisher) as publication:
            populate(publication)

            # Prepare metadata files
            repomd_path = os.path.join(os.getcwd(), "repomd.xml")
            pri_xml_path = os.path.join(os.getcwd(), "primary.xml.gz")
            fil_xml_path = os.path.join(os.getcwd(), "filelists.xml.gz")
            oth_xml_path = os.path.join(os.getcwd(), "other.xml.gz")
            pri_db_path = os.path.join(os.getcwd(), "primary.sqlite")
            fil_db_path = os.path.join(os.getcwd(), "filelists.sqlite")
            oth_db_path = os.path.join(os.getcwd(), "other.sqlite")
            upd_xml_path = os.path.join(os.getcwd(), "updateinfo.xml.gz")

            pri_xml = cr.PrimaryXmlFile(pri_xml_path)
            fil_xml = cr.FilelistsXmlFile(fil_xml_path)
            oth_xml = cr.OtherXmlFile(oth_xml_path)
            pri_db = cr.PrimarySqlite(pri_db_path)
            fil_db = cr.FilelistsSqlite(fil_db_path)
            oth_db = cr.OtherSqlite(oth_db_path)
            upd_xml = cr.UpdateInfoXmlFile(upd_xml_path)

            artifacts = publication.published_artifact.all()
            pri_xml.set_num_of_pkgs(len(artifacts))
            fil_xml.set_num_of_pkgs(len(artifacts))
            oth_xml.set_num_of_pkgs(len(artifacts))

            # Process all packages
            for artifact in artifacts:
                # TODO: pass attributes from db rather than use the filesystem
                pkg = cr.package_from_rpm(
                    artifact.content_artifact.artifact.file.path)
                pkg.location_href = artifact.content_artifact.relative_path
                pri_xml.add_pkg(pkg)
                fil_xml.add_pkg(pkg)
                oth_xml.add_pkg(pkg)
                pri_db.add_pkg(pkg)
                fil_db.add_pkg(pkg)
                oth_db.add_pkg(pkg)

            # Process update records
            for update_record in UpdateRecord.objects.filter(
                    pk__in=publication.repository_version.content):
                upd_xml.add_chunk(update_record_xml(update_record))

            pri_xml.close()
            fil_xml.close()
            oth_xml.close()
            upd_xml.close()

            repomd = cr.Repomd()

            repomdrecords = (("primary", pri_xml_path,
                              pri_db), ("filelists", fil_xml_path, fil_db),
                             ("other", oth_xml_path,
                              oth_db), ("primary_db", pri_db_path, None),
                             ("filelists_db", fil_db_path,
                              None), ("other_db", oth_db_path, None),
                             ("updateinfo", upd_xml_path, None))

            for name, path, db_to_update in repomdrecords:
                record = cr.RepomdRecord(name, path)
                record.fill(cr.SHA256)
                if (db_to_update):
                    db_to_update.dbinfo_update(record.checksum)
                    db_to_update.close()
                repomd.set_record(record)
                metadata = PublishedMetadata(
                    relative_path=os.path.join(REPODATA_PATH,
                                               os.path.basename(path)),
                    publication=publication,
                    file=File(open(os.path.basename(path), 'rb')))
                metadata.save()

            open(repomd_path, "w").write(repomd.xml_dump())

            metadata = PublishedMetadata(
                relative_path=os.path.join(REPODATA_PATH,
                                           os.path.basename(repomd_path)),
                publication=publication,
                file=File(open(os.path.basename(repomd_path), 'rb')))
            metadata.save()
Exemplo n.º 25
0
def publish(publisher_pk, repository_version_pk):
    """
    Use provided publisher to create a Publication based on a RepositoryVersion.

    Args:
        publisher_pk (str): Use the publish settings provided by this publisher.
        repository_version_pk (str): Create a publication from this repository version.
    """
    publisher = RpmPublisher.objects.get(pk=publisher_pk)
    repository_version = RepositoryVersion.objects.get(pk=repository_version_pk)

    log.info(_('Publishing: repository={repo}, version={version}, publisher={publisher}').format(
        repo=repository_version.repository.name,
        version=repository_version.number,
        publisher=publisher.name,
    ))

    with WorkingDirectory():
        with Publication.create(repository_version, publisher) as publication:
            populate(publication)

            # Prepare metadata files
            repomd_path = os.path.join(os.getcwd(), "repomd.xml")
            pri_xml_path = os.path.join(os.getcwd(), "primary.xml.gz")
            fil_xml_path = os.path.join(os.getcwd(), "filelists.xml.gz")
            oth_xml_path = os.path.join(os.getcwd(), "other.xml.gz")
            pri_db_path = os.path.join(os.getcwd(), "primary.sqlite")
            fil_db_path = os.path.join(os.getcwd(), "filelists.sqlite")
            oth_db_path = os.path.join(os.getcwd(), "other.sqlite")
            upd_xml_path = os.path.join(os.getcwd(), "updateinfo.xml.gz")

            pri_xml = cr.PrimaryXmlFile(pri_xml_path)
            fil_xml = cr.FilelistsXmlFile(fil_xml_path)
            oth_xml = cr.OtherXmlFile(oth_xml_path)
            pri_db = cr.PrimarySqlite(pri_db_path)
            fil_db = cr.FilelistsSqlite(fil_db_path)
            oth_db = cr.OtherSqlite(oth_db_path)
            upd_xml = cr.UpdateInfoXmlFile(upd_xml_path)

            artifacts = publication.published_artifact.all()
            pri_xml.set_num_of_pkgs(len(artifacts))
            fil_xml.set_num_of_pkgs(len(artifacts))
            oth_xml.set_num_of_pkgs(len(artifacts))

            # Process all packages
            for artifact in artifacts:
                # TODO: pass attributes from db rather than use the filesystem
                pkg = cr.package_from_rpm(artifact.content_artifact.artifact.file.path)
                pkg.location_href = artifact.content_artifact.relative_path
                pri_xml.add_pkg(pkg)
                fil_xml.add_pkg(pkg)
                oth_xml.add_pkg(pkg)
                pri_db.add_pkg(pkg)
                fil_db.add_pkg(pkg)
                oth_db.add_pkg(pkg)

            # Process update records
            for update_record in UpdateRecord.objects.filter(
                    pk__in=publication.repository_version.content):
                upd_xml.add_chunk(update_record_xml(update_record))

            pri_xml.close()
            fil_xml.close()
            oth_xml.close()
            upd_xml.close()

            repomd = cr.Repomd()

            repomdrecords = (("primary", pri_xml_path, pri_db),
                             ("filelists", fil_xml_path, fil_db),
                             ("other", oth_xml_path, oth_db),
                             ("primary_db", pri_db_path, None),
                             ("filelists_db", fil_db_path, None),
                             ("other_db", oth_db_path, None),
                             ("updateinfo", upd_xml_path, None))

            for name, path, db_to_update in repomdrecords:
                record = cr.RepomdRecord(name, path)
                record.fill(cr.SHA256)
                if (db_to_update):
                    db_to_update.dbinfo_update(record.checksum)
                    db_to_update.close()
                    repomd.set_record(record)
                metadata = PublishedMetadata(
                    relative_path=os.path.join(REPODATA_PATH, os.path.basename(path)),
                    publication=publication,
                    file=File(open(os.path.basename(path), 'rb'))
                )
                metadata.save()

            open(repomd_path, "w").write(repomd.xml_dump())

            metadata = PublishedMetadata(
                relative_path=os.path.join(REPODATA_PATH, os.path.basename(repomd_path)),
                publication=publication,
                file=File(open(os.path.basename(repomd_path), 'rb'))
            )
            metadata.save()
Exemplo n.º 26
0
    def test_package_archer(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)
        self.assertEqual(
            pkg.pkgId,
            "4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e")
        self.assertEqual(pkg.name, "Archer")
        self.assertEqual(pkg.arch, "x86_64")
        self.assertEqual(pkg.version, "3.4.5")
        self.assertEqual(pkg.epoch, "2")
        self.assertEqual(pkg.release, "6")
        self.assertEqual(pkg.summary, "Complex package.")
        self.assertEqual(pkg.description, "Archer package")
        self.assertEqual(pkg.url, "http://soo_complex_package.eu/")
        #self.assertEqual(pkg.time_file, 1365416502)
        self.assertEqual(pkg.time_build, 1365416480)
        self.assertEqual(pkg.rpm_license, "GPL")
        self.assertEqual(pkg.rpm_vendor, "ISIS")
        self.assertEqual(pkg.rpm_group, "Development/Tools")
        self.assertEqual(pkg.rpm_buildhost, "localhost.localdomain")
        self.assertEqual(pkg.rpm_sourcerpm, "Archer-3.4.5-6.src.rpm")
        self.assertEqual(pkg.rpm_header_start, 280)
        self.assertEqual(pkg.rpm_header_end, 2865)
        self.assertEqual(pkg.rpm_packager, "Sterling Archer")
        self.assertEqual(pkg.size_package, 3101)
        self.assertEqual(pkg.size_installed, 0)
        self.assertEqual(pkg.size_archive, 544)
        self.assertEqual(pkg.location_href, None)
        self.assertEqual(pkg.location_base, None)
        self.assertEqual(pkg.checksum_type, "sha256")
        self.assertEqual(pkg.requires,
                         [('fooa', 'LE', '0', '2', None, False),
                          ('foob', 'GE', '0', '1.0.0', '1', False),
                          ('fooc', 'EQ', '0', '3', None, False),
                          ('food', 'LT', '0', '4', None, False),
                          ('fooe', 'GT', '0', '5', None, False),
                          ('foof', 'EQ', '0', '6', None, True)])
        self.assertEqual(pkg.provides,
                         [('bara', 'LE', '0', '22', None, False),
                          ('barb', 'GE', '0', '11.22.33', '44', False),
                          ('barc', 'EQ', '0', '33', None, False),
                          ('bard', 'LT', '0', '44', None, False),
                          ('bare', 'GT', '0', '55', None, False),
                          ('Archer', 'EQ', '2', '3.4.5', '6', False),
                          ('Archer(x86-64)', 'EQ', '2', '3.4.5', '6', False)])
        self.assertEqual(pkg.conflicts,
                         [('bba', 'LE', '0', '2222', None, False),
                          ('bbb', 'GE', '0', '1111.2222.3333', '4444', False),
                          ('bbc', 'EQ', '0', '3333', None, False),
                          ('bbd', 'LT', '0', '4444', None, False),
                          ('bbe', 'GT', '0', '5555', None, False)])
        self.assertEqual(pkg.obsoletes,
                         [('aaa', 'LE', '0', '222', None, False),
                          ('aab', 'GE', '0', '111.2.3', '4', False),
                          ('aac', 'EQ', '0', '333', None, False),
                          ('aad', 'LT', '0', '444', None, False),
                          ('aae', 'GT', '0', '555', None, False)])
        self.assertEqual(pkg.suggests, [])
        self.assertEqual(pkg.enhances, [])
        self.assertEqual(pkg.recommends, [])
        self.assertEqual(pkg.supplements, [])
        self.assertEqual(pkg.files,
                         [('', '/usr/bin/', 'complex_a'),
                          ('dir', '/usr/share/doc/', 'Archer-3.4.5'),
                          ('', '/usr/share/doc/Archer-3.4.5/', 'README')])
        self.assertEqual(pkg.changelogs,
                         [('Tomas Mlcoch <*****@*****.**> - 1.1.1-1',
                           1334664000, '- First changelog.'),
                          ('Tomas Mlcoch <*****@*****.**> - 2.2.2-2',
                           1334750400, '- That was totally ninja!'),
                          ('Tomas Mlcoch <*****@*****.**> - 3.3.3-3',
                           1365422400, '- 3. changelog.')])

        self.assertEqual(pkg.nvra(), "Archer-3.4.5-6.x86_64")
        self.assertEqual(pkg.nevra(), "Archer-2:3.4.5-6.x86_64")
Exemplo n.º 27
0
    def test_xmlfile_add_pkg(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)
        pkg.time_file = 111

        # Primary
        path = os.path.join(self.tmpdir, "primary.xml")
        f = cr.PrimaryXmlFile(path, cr.NO_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        self.assertRaises(TypeError, f.add_pkg, None)
        self.assertRaises(TypeError, f.add_pkg, 123)
        self.assertRaises(TypeError, f.add_pkg, "foo")
        self.assertRaises(TypeError, f.add_pkg, [456])
        f.close()

        self.assertTrue(os.path.isfile(path))
        self.assertEqual(open(path).read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="0">
<package type="rpm">
  <name>Archer</name>
  <arch>x86_64</arch>
  <version epoch="2" ver="3.4.5" rel="6"/>
  <checksum type="sha256" pkgid="YES">4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e</checksum>
  <summary>Complex package.</summary>
  <description>Archer package</description>
  <packager>Sterling Archer</packager>
  <url>http://soo_complex_package.eu/</url>
  <time file="111" build="1365416480"/>
  <size package="3101" installed="0" archive="544"/>
  <location href=""/>
  <format>
    <rpm:license>GPL</rpm:license>
    <rpm:vendor>ISIS</rpm:vendor>
    <rpm:group>Development/Tools</rpm:group>
    <rpm:buildhost>localhost.localdomain</rpm:buildhost>
    <rpm:sourcerpm>Archer-3.4.5-6.src.rpm</rpm:sourcerpm>
    <rpm:header-range start="280" end="2865"/>
    <rpm:provides>
      <rpm:entry name="bara" flags="LE" epoch="0" ver="22"/>
      <rpm:entry name="barb" flags="GE" epoch="0" ver="11.22.33" rel="44"/>
      <rpm:entry name="barc" flags="EQ" epoch="0" ver="33"/>
      <rpm:entry name="bard" flags="LT" epoch="0" ver="44"/>
      <rpm:entry name="bare" flags="GT" epoch="0" ver="55"/>
      <rpm:entry name="Archer" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
      <rpm:entry name="Archer(x86-64)" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
    </rpm:provides>
    <rpm:requires>
      <rpm:entry name="fooa" flags="LE" epoch="0" ver="2"/>
      <rpm:entry name="foob" flags="GE" epoch="0" ver="1.0.0" rel="1"/>
      <rpm:entry name="fooc" flags="EQ" epoch="0" ver="3"/>
      <rpm:entry name="food" flags="LT" epoch="0" ver="4"/>
      <rpm:entry name="fooe" flags="GT" epoch="0" ver="5"/>
      <rpm:entry name="foof" flags="EQ" epoch="0" ver="6" pre="1"/>
    </rpm:requires>
    <rpm:conflicts>
      <rpm:entry name="bba" flags="LE" epoch="0" ver="2222"/>
      <rpm:entry name="bbb" flags="GE" epoch="0" ver="1111.2222.3333" rel="4444"/>
      <rpm:entry name="bbc" flags="EQ" epoch="0" ver="3333"/>
      <rpm:entry name="bbd" flags="LT" epoch="0" ver="4444"/>
      <rpm:entry name="bbe" flags="GT" epoch="0" ver="5555"/>
    </rpm:conflicts>
    <rpm:obsoletes>
      <rpm:entry name="aaa" flags="LE" epoch="0" ver="222"/>
      <rpm:entry name="aab" flags="GE" epoch="0" ver="111.2.3" rel="4"/>
      <rpm:entry name="aac" flags="EQ" epoch="0" ver="333"/>
      <rpm:entry name="aad" flags="LT" epoch="0" ver="444"/>
      <rpm:entry name="aae" flags="GT" epoch="0" ver="555"/>
    </rpm:obsoletes>
    <file>/usr/bin/complex_a</file>
  </format>
</package>
</metadata>""")

        # Filelists
        path = os.path.join(self.tmpdir, "filelists.xml")
        f = cr.FilelistsXmlFile(path, cr.NO_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        self.assertRaises(TypeError, f.add_pkg, None)
        self.assertRaises(TypeError, f.add_pkg, 123)
        self.assertRaises(TypeError, f.add_pkg, "foo")
        self.assertRaises(TypeError, f.add_pkg, [456])
        f.close()

        self.assertTrue(os.path.isfile(path))
        self.assertEqual(open(path).read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="0">
<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">
  <version epoch="2" ver="3.4.5" rel="6"/>
  <file>/usr/bin/complex_a</file>
  <file type="dir">/usr/share/doc/Archer-3.4.5</file>
  <file>/usr/share/doc/Archer-3.4.5/README</file>
</package>
</filelists>""")

        # Other
        path = os.path.join(self.tmpdir, "other.xml")
        f = cr.OtherXmlFile(path, cr.NO_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        self.assertRaises(TypeError, f.add_pkg, None)
        self.assertRaises(TypeError, f.add_pkg, 123)
        self.assertRaises(TypeError, f.add_pkg, "foo")
        self.assertRaises(TypeError, f.add_pkg, [456])
        f.close()

        self.assertTrue(os.path.isfile(path))
        self.assertEqual(open(path).read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="0">
<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">
  <version epoch="2" ver="3.4.5" rel="6"/>
  <changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 1.1.1-1" date="1334664000">- First changelog.</changelog>
  <changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 2.2.2-2" date="1334750400">- That was totally ninja!</changelog>
  <changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 3.3.3-3" date="1365422400">- 3. changelog.</changelog>
</package>
</otherdata>""")
Exemplo n.º 28
0
def do_repodata(path):
    # Prepare repodata/ directory
    repodata_path = os.path.join(path, "repodata")
    if os.path.exists(repodata_path):
        x = 0
        while True:
            new_repodata_path = "%s_%s" % (repodata_path, x)
            if not os.path.exists(new_repodata_path):
                shutil.move(repodata_path, new_repodata_path)
                break
            x += 1
    os.mkdir(repodata_path)

    # Prepare metadata files
    repomd_path  = os.path.join(repodata_path, "repomd.xml")
    pri_xml_path = os.path.join(repodata_path, "primary.xml.gz")
    fil_xml_path = os.path.join(repodata_path, "filelists.xml.gz")
    oth_xml_path = os.path.join(repodata_path, "other.xml.gz")
    pri_db_path  = os.path.join(repodata_path, "primary.sqlite")
    fil_db_path  = os.path.join(repodata_path, "filelists.sqlite")
    oth_db_path  = os.path.join(repodata_path, "other.sqlite")

    pri_xml = cr.PrimaryXmlFile(pri_xml_path)
    fil_xml = cr.FilelistsXmlFile(fil_xml_path)
    oth_xml = cr.OtherXmlFile(oth_xml_path)
    pri_db  = cr.PrimarySqlite(pri_db_path)
    fil_db  = cr.FilelistsSqlite(fil_db_path)
    oth_db  = cr.OtherSqlite(oth_db_path)

    # List directory and prepare list of files to process
    pkg_list = []
    for filename in os.listdir(path):
        filename = os.path.join(path, filename)
        if os.path.isfile(filename) and filename.endswith(".rpm"):
            pkg_list.append(filename)

    pri_xml.set_num_of_pkgs(len(pkg_list))
    fil_xml.set_num_of_pkgs(len(pkg_list))
    oth_xml.set_num_of_pkgs(len(pkg_list))

    # Process all packages
    for filename in pkg_list:
        pkg = cr.package_from_rpm(filename)
        pkg.location_href = os.path.basename(filename)
        print "Processing: %s" % pkg.nevra()
        pri_xml.add_pkg(pkg)
        fil_xml.add_pkg(pkg)
        oth_xml.add_pkg(pkg)
        pri_db.add_pkg(pkg)
        fil_db.add_pkg(pkg)
        oth_db.add_pkg(pkg)

    pri_xml.close()
    fil_xml.close()
    oth_xml.close()

    # Note: DBs are still open! We have to calculate checksums of xml files
    # and insert them to the databases first!

    # Prepare repomd.xml
    repomd = cr.Repomd()

    # Add records into the repomd.xml
    repomdrecords = (("primary",      pri_xml_path, pri_db),
                     ("filelists",    fil_xml_path, fil_db),
                     ("other",        oth_xml_path, oth_db),
                     ("primary_db",   pri_db_path,  None),
                     ("filelists_db", fil_db_path,  None),
                     ("other_db",     oth_db_path,  None))
    for name, path, db_to_update in repomdrecords:
        record = cr.RepomdRecord(name, path)
        record.fill(cr.SHA256)
        if (db_to_update):
            db_to_update.dbinfo_update(record.checksum)
            db_to_update.close()
        repomd.set_record(record)

    # Write repomd.xml
    open(repomd_path, "w").write(repomd.xml_dump())
Exemplo n.º 29
0
    def test_sqlite_primary(self):
        path = os.path.join(self.tmpdir, "primary.db")
        db = cr.Sqlite(path, cr.DB_PRIMARY)
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        db.add_pkg(pkg)
        self.assertRaises(TypeError, db.add_pkg, None)
        self.assertRaises(TypeError, db.add_pkg, 123)
        self.assertRaises(TypeError, db.add_pkg, "foo")
        db.dbinfo_update("somechecksum")
        self.assertRaises(TypeError, db.dbinfo_update, pkg)
        self.assertRaises(TypeError, db.dbinfo_update, None)
        self.assertRaises(TypeError, db.dbinfo_update, 123)
        db.close()

        self.assertTrue(os.path.isfile(path))

        con = sqlite3.connect(path)

        # Check packages table
        res = con.execute("select * from packages").fetchall()
        self.assertEqual(res, [(
            1,
            u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e',
            u'Archer', u'x86_64', u'3.4.5', u'2', u'6', u'Complex package.',
            u'Archer package', u'http://soo_complex_package.eu/', res[0][10],
            1365416480, u'GPL', u'ISIS', u'Development/Tools',
            u'localhost.localdomain', u'Archer-3.4.5-6.src.rpm', 280, 2865,
            u'Sterling Archer', 3101, 0, 544, None, None, u'sha256')])

        # Check provides table
        self.assertEqual(
            con.execute("select * from provides").fetchall(),
            [(u'bara', u'LE', u'0', u'22', None, 1),
             (u'barb', u'GE', u'0', u'11.22.33', u'44', 1),
             (u'barc', u'EQ', u'0', u'33', None, 1),
             (u'bard', u'LT', u'0', u'44', None, 1),
             (u'bare', u'GT', u'0', u'55', None, 1),
             (u'Archer', u'EQ', u'2', u'3.4.5', u'6', 1),
             (u'Archer(x86-64)', u'EQ', u'2', u'3.4.5', u'6', 1)])

        # Check conflicts table
        self.assertEqual(
            con.execute("select * from conflicts").fetchall(),
            [(u'bba', u'LE', u'0', u'2222', None, 1),
             (u'bbb', u'GE', u'0', u'1111.2222.3333', u'4444', 1),
             (u'bbc', u'EQ', u'0', u'3333', None, 1),
             (u'bbd', u'LT', u'0', u'4444', None, 1),
             (u'bbe', u'GT', u'0', u'5555', None, 1)])

        # Check obsoletes table
        self.assertEqual(
            con.execute("select * from obsoletes").fetchall(),
            [(u'aaa', u'LE', u'0', u'222', None, 1),
             (u'aab', u'GE', u'0', u'111.2.3', u'4', 1),
             (u'aac', u'EQ', u'0', u'333', None, 1),
             (u'aad', u'LT', u'0', u'444', None, 1),
             (u'aae', u'GT', u'0', u'555', None, 1)])

        # Check requires table
        self.assertEqual(
            con.execute("select * from requires").fetchall(),
            [(u'fooa', u'LE', u'0', u'2', None, 1, u'FALSE'),
             (u'foob', u'GE', u'0', u'1.0.0', u'1', 1, u'FALSE'),
             (u'fooc', u'EQ', u'0', u'3', None, 1, u'FALSE'),
             (u'food', u'LT', u'0', u'4', None, 1, u'FALSE'),
             (u'fooe', u'GT', u'0', u'5', None, 1, u'FALSE'),
             (u'foof', u'EQ', u'0', u'6', None, 1, u'TRUE')])

        # Check files table
        self.assertEqual(
            con.execute("select * from files").fetchall(),
            [(u'/usr/bin/complex_a', u'file', 1)])

        # Check db_info table
        self.assertEqual(
            con.execute("select * from db_info").fetchall(),
            [(10, u'somechecksum')])
Exemplo n.º 30
0
 def test_pkg_id_str_02(self):
     pkg = cr.package_from_rpm(fixtures.PACKAGE_RIMMER)
     idstr = pkg_id_str(pkg)
     self.assertEqual(idstr, "60dee92d523e8390eb7430fca8ffce461b5b2ad4eb19878cde5c16d72955ee49")
Exemplo n.º 31
0
    def test_package_archer(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)
        self.assertEqual(pkg.pkgId, "4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e")
        self.assertEqual(pkg.name, "Archer")
        self.assertEqual(pkg.arch, "x86_64")
        self.assertEqual(pkg.version, "3.4.5")
        self.assertEqual(pkg.epoch, "2")
        self.assertEqual(pkg.release, "6")
        self.assertEqual(pkg.summary, "Complex package.")
        self.assertEqual(pkg.description, "Archer package")
        self.assertEqual(pkg.url, "http://soo_complex_package.eu/")
        #self.assertEqual(pkg.time_file, 1365416502)
        self.assertEqual(pkg.time_build, 1365416480)
        self.assertEqual(pkg.rpm_license, "GPL")
        self.assertEqual(pkg.rpm_vendor, "ISIS")
        self.assertEqual(pkg.rpm_group, "Development/Tools")
        self.assertEqual(pkg.rpm_buildhost, "localhost.localdomain")
        self.assertEqual(pkg.rpm_sourcerpm, "Archer-3.4.5-6.src.rpm")
        self.assertEqual(pkg.rpm_header_start, 280)
        self.assertEqual(pkg.rpm_header_end, 2865)
        self.assertEqual(pkg.rpm_packager, "Sterling Archer")
        self.assertEqual(pkg.size_package, 3101)
        self.assertEqual(pkg.size_installed, 0)
        self.assertEqual(pkg.size_archive, 544)
        self.assertEqual(pkg.location_href, None)
        self.assertEqual(pkg.location_base, None)
        self.assertEqual(pkg.checksum_type, "sha256")
        self.assertEqual(pkg.requires, [
            ('fooa', 'LE', '0', '2', None, False),
            ('foob', 'GE', '0', '1.0.0', '1', False),
            ('fooc', 'EQ', '0', '3', None, False),
            ('food', 'LT', '0', '4', None, False),
            ('fooe', 'GT', '0', '5', None, False),
            ('foof', 'EQ', '0', '6', None, True)
            ])
        self.assertEqual(pkg.provides, [
            ('bara', 'LE', '0', '22', None, False),
            ('barb', 'GE', '0', '11.22.33', '44', False),
            ('barc', 'EQ', '0', '33', None, False),
            ('bard', 'LT', '0', '44', None, False),
            ('bare', 'GT', '0', '55', None, False),
            ('Archer', 'EQ', '2', '3.4.5', '6', False),
            ('Archer(x86-64)', 'EQ', '2', '3.4.5', '6', False)
            ])
        self.assertEqual(pkg.conflicts, [
            ('bba', 'LE', '0', '2222', None, False),
            ('bbb', 'GE', '0', '1111.2222.3333', '4444', False),
            ('bbc', 'EQ', '0', '3333', None, False),
            ('bbd', 'LT', '0', '4444', None, False),
            ('bbe', 'GT', '0', '5555', None, False)
            ])
        self.assertEqual(pkg.obsoletes, [
            ('aaa', 'LE', '0', '222', None, False),
            ('aab', 'GE', '0', '111.2.3', '4', False),
            ('aac', 'EQ', '0', '333', None, False),
            ('aad', 'LT', '0', '444', None, False),
            ('aae', 'GT', '0', '555', None, False)
            ])
        self.assertEqual(pkg.suggests, [])
        self.assertEqual(pkg.enhances, [])
        self.assertEqual(pkg.recommends, [])
        self.assertEqual(pkg.supplements, [])
        self.assertEqual(pkg.files, [
            ('', '/usr/bin/', 'complex_a'),
            ('dir', '/usr/share/doc/', 'Archer-3.4.5'),
            ('', '/usr/share/doc/Archer-3.4.5/', 'README')
            ])
        self.assertEqual(pkg.changelogs, [
            ('Tomas Mlcoch <*****@*****.**> - 1.1.1-1', 1334664000L,
                '- First changelog.'),
            ('Tomas Mlcoch <*****@*****.**> - 2.2.2-2', 1334750400L,
                '- That was totally ninja!'),
            ('Tomas Mlcoch <*****@*****.**> - 3.3.3-3', 1365422400L,
                '- 3. changelog.')
            ])

        self.assertEqual(pkg.nvra(), "Archer-3.4.5-6.x86_64")
        self.assertEqual(pkg.nevra(), "Archer-2:3.4.5-6.x86_64")
Exemplo n.º 32
0
    def test_sqlite_primary(self):
        path = os.path.join(self.tmpdir, "primary.db")
        db = cr.Sqlite(path, cr.DB_PRIMARY)
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        db.add_pkg(pkg)
        self.assertRaises(TypeError, db.add_pkg, None)
        self.assertRaises(TypeError, db.add_pkg, 123)
        self.assertRaises(TypeError, db.add_pkg, "foo")
        db.dbinfo_update("somechecksum")
        self.assertRaises(TypeError, db.dbinfo_update, pkg)
        self.assertRaises(TypeError, db.dbinfo_update, None)
        self.assertRaises(TypeError, db.dbinfo_update, 123)
        db.close()

        self.assertTrue(os.path.isfile(path))

        con = sqlite3.connect(path)

        # Check packages table
        res = con.execute("select * from packages").fetchall()
        self.assertEqual(res,
            [(1, u'4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e',
              u'Archer', u'x86_64', u'3.4.5', u'2', u'6', u'Complex package.',
              u'Archer package', u'http://soo_complex_package.eu/',
              res[0][10], 1365416480, u'GPL', u'ISIS', u'Development/Tools',
              u'localhost.localdomain', u'Archer-3.4.5-6.src.rpm', 280, 2865,
              u'Sterling Archer', 3101, 0, 544, None, None, u'sha256')])

        # Check provides table
        self.assertEqual(con.execute("select * from provides").fetchall(),
            [(u'bara', u'LE', u'0', u'22', None, 1),
             (u'barb', u'GE', u'0', u'11.22.33', u'44', 1),
             (u'barc', u'EQ', u'0', u'33', None, 1),
             (u'bard', u'LT', u'0', u'44', None, 1),
             (u'bare', u'GT', u'0', u'55', None, 1),
             (u'Archer', u'EQ', u'2', u'3.4.5', u'6', 1),
             (u'Archer(x86-64)', u'EQ', u'2', u'3.4.5', u'6', 1)])

        # Check conflicts table
        self.assertEqual(con.execute("select * from conflicts").fetchall(),
            [(u'bba', u'LE', u'0', u'2222', None, 1),
             (u'bbb', u'GE', u'0', u'1111.2222.3333', u'4444', 1),
             (u'bbc', u'EQ', u'0', u'3333', None, 1),
             (u'bbd', u'LT', u'0', u'4444', None, 1),
             (u'bbe', u'GT', u'0', u'5555', None, 1)])

        # Check obsoletes table
        self.assertEqual(con.execute("select * from obsoletes").fetchall(),
           [(u'aaa', u'LE', u'0', u'222', None, 1),
            (u'aab', u'GE', u'0', u'111.2.3', u'4', 1),
            (u'aac', u'EQ', u'0', u'333', None, 1),
            (u'aad', u'LT', u'0', u'444', None, 1),
            (u'aae', u'GT', u'0', u'555', None, 1)])

        # Check requires table
        self.assertEqual(con.execute("select * from requires").fetchall(),
            [(u'fooa', u'LE', u'0', u'2', None, 1, u'FALSE'),
             (u'foob', u'GE', u'0', u'1.0.0', u'1', 1, u'FALSE'),
             (u'fooc', u'EQ', u'0', u'3', None, 1, u'FALSE'),
             (u'food', u'LT', u'0', u'4', None, 1, u'FALSE'),
             (u'fooe', u'GT', u'0', u'5', None, 1, u'FALSE'),
             (u'foof', u'EQ', u'0', u'6', None, 1, u'TRUE')])

        # Check files table
        self.assertEqual(con.execute("select * from files").fetchall(),
            [(u'/usr/bin/complex_a', u'file', 1)])

        # Check db_info table
        self.assertEqual(con.execute("select * from db_info").fetchall(),
            [(10, u'somechecksum')])
Exemplo n.º 33
0
    def test_xmlfile_add_pkg(self):
        pkg = cr.package_from_rpm(PKG_ARCHER_PATH)
        self.assertTrue(pkg)
        pkg.time_file = 111

        # Primary
        path = os.path.join(self.tmpdir, "primary.xml")
        f = cr.PrimaryXmlFile(path, cr.NO_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        self.assertRaises(TypeError, f.add_pkg, None)
        self.assertRaises(TypeError, f.add_pkg, 123)
        self.assertRaises(TypeError, f.add_pkg, "foo")
        self.assertRaises(TypeError, f.add_pkg, [456])
        f.close()

        self.assertTrue(os.path.isfile(path))
        with open(path) as primary:
            self.assertEqual(primary.read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://linux.duke.edu/metadata/common" xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="0">
<package type="rpm">
  <name>Archer</name>
  <arch>x86_64</arch>
  <version epoch="2" ver="3.4.5" rel="6"/>
  <checksum type="sha256" pkgid="YES">4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e</checksum>
  <summary>Complex package.</summary>
  <description>Archer package</description>
  <packager>Sterling Archer</packager>
  <url>http://soo_complex_package.eu/</url>
  <time file="111" build="1365416480"/>
  <size package="3101" installed="0" archive="544"/>
  <location href=""/>
  <format>
    <rpm:license>GPL</rpm:license>
    <rpm:vendor>ISIS</rpm:vendor>
    <rpm:group>Development/Tools</rpm:group>
    <rpm:buildhost>localhost.localdomain</rpm:buildhost>
    <rpm:sourcerpm>Archer-3.4.5-6.src.rpm</rpm:sourcerpm>
    <rpm:header-range start="280" end="2865"/>
    <rpm:provides>
      <rpm:entry name="bara" flags="LE" epoch="0" ver="22"/>
      <rpm:entry name="barb" flags="GE" epoch="0" ver="11.22.33" rel="44"/>
      <rpm:entry name="barc" flags="EQ" epoch="0" ver="33"/>
      <rpm:entry name="bard" flags="LT" epoch="0" ver="44"/>
      <rpm:entry name="bare" flags="GT" epoch="0" ver="55"/>
      <rpm:entry name="Archer" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
      <rpm:entry name="Archer(x86-64)" flags="EQ" epoch="2" ver="3.4.5" rel="6"/>
    </rpm:provides>
    <rpm:requires>
      <rpm:entry name="fooa" flags="LE" epoch="0" ver="2"/>
      <rpm:entry name="foob" flags="GE" epoch="0" ver="1.0.0" rel="1"/>
      <rpm:entry name="fooc" flags="EQ" epoch="0" ver="3"/>
      <rpm:entry name="food" flags="LT" epoch="0" ver="4"/>
      <rpm:entry name="fooe" flags="GT" epoch="0" ver="5"/>
      <rpm:entry name="foof" flags="EQ" epoch="0" ver="6" pre="1"/>
    </rpm:requires>
    <rpm:conflicts>
      <rpm:entry name="bba" flags="LE" epoch="0" ver="2222"/>
      <rpm:entry name="bbb" flags="GE" epoch="0" ver="1111.2222.3333" rel="4444"/>
      <rpm:entry name="bbc" flags="EQ" epoch="0" ver="3333"/>
      <rpm:entry name="bbd" flags="LT" epoch="0" ver="4444"/>
      <rpm:entry name="bbe" flags="GT" epoch="0" ver="5555"/>
    </rpm:conflicts>
    <rpm:obsoletes>
      <rpm:entry name="aaa" flags="LE" epoch="0" ver="222"/>
      <rpm:entry name="aab" flags="GE" epoch="0" ver="111.2.3" rel="4"/>
      <rpm:entry name="aac" flags="EQ" epoch="0" ver="333"/>
      <rpm:entry name="aad" flags="LT" epoch="0" ver="444"/>
      <rpm:entry name="aae" flags="GT" epoch="0" ver="555"/>
    </rpm:obsoletes>
    <file>/usr/bin/complex_a</file>
  </format>
</package>
</metadata>""")

        # Filelists
        path = os.path.join(self.tmpdir, "filelists.xml")
        f = cr.FilelistsXmlFile(path, cr.NO_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        self.assertRaises(TypeError, f.add_pkg, None)
        self.assertRaises(TypeError, f.add_pkg, 123)
        self.assertRaises(TypeError, f.add_pkg, "foo")
        self.assertRaises(TypeError, f.add_pkg, [456])
        f.close()

        self.assertTrue(os.path.isfile(path))
        with open(path) as filelists:
            self.assertEqual(filelists.read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<filelists xmlns="http://linux.duke.edu/metadata/filelists" packages="0">
<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">
  <version epoch="2" ver="3.4.5" rel="6"/>
  <file>/usr/bin/complex_a</file>
  <file type="dir">/usr/share/doc/Archer-3.4.5</file>
  <file>/usr/share/doc/Archer-3.4.5/README</file>
</package>
</filelists>""")

        # Other
        path = os.path.join(self.tmpdir, "other.xml")
        f = cr.OtherXmlFile(path, cr.NO_COMPRESSION)
        self.assertTrue(f)
        self.assertTrue(os.path.isfile(path))
        f.add_pkg(pkg)
        self.assertRaises(TypeError, f.add_pkg, None)
        self.assertRaises(TypeError, f.add_pkg, 123)
        self.assertRaises(TypeError, f.add_pkg, "foo")
        self.assertRaises(TypeError, f.add_pkg, [456])
        f.close()

        self.assertTrue(os.path.isfile(path))
        with open(path) as other:
            self.assertEqual(other.read(),
"""<?xml version="1.0" encoding="UTF-8"?>
<otherdata xmlns="http://linux.duke.edu/metadata/other" packages="0">
<package pkgid="4e0b775220c67f0f2c1fd2177e626b9c863a098130224ff09778ede25cea9a9e" name="Archer" arch="x86_64">
  <version epoch="2" ver="3.4.5" rel="6"/>
  <changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 1.1.1-1" date="1334664000">- First changelog.</changelog>
  <changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 2.2.2-2" date="1334750400">- That was totally ninja!</changelog>
  <changelog author="Tomas Mlcoch &lt;[email protected]&gt; - 3.3.3-3" date="1365422400">- 3. changelog.</changelog>
</package>
</otherdata>""")
Exemplo n.º 34
0
def cr_package_from_file(rpm_file, log=sys.stdout):
    log.write('[%s] Loading information from %s\n' % (stamp(), rpm_file))
    np = cr.package_from_rpm(rpm_file)
    np.location_href = rpm_file
    return np
Exemplo n.º 35
0
def import_(keep, repo, rpms):
    """Import RPM files to a repo."""

    config = load_config()
    base = config[repo].base
    architectures = config[repo].architectures

    db = load_db()
    db.connect()

    repodirs = set()

    click.secho('importing RPMs', fg='cyan')
    with db.atomic():
        db.create_tables([NVR, Artifact])
        with click.progressbar(iterable=rpms, fill_char='█') as rpms_bar:
            for rpm in rpms_bar:
                # read metadata from RPM file
                pkg = createrepo_c.package_from_rpm(f'{rpm}')

                # record NVR label in database
                if pkg.arch == 'src':
                    label = f'{pkg.name}-{pkg.version}-{pkg.release}'
                else:
                    label = pkg.rpm_sourcerpm[:-8]
                nvr, _ = NVR.get_or_create(label=label)

                if pkg.arch == 'noarch':
                    # noarch goes in all architectures
                    for architecture in architectures:
                        # compute destination path
                        repodirs.add(base / architecture)
                        destination = base / architecture / 'packages' / rpm.name[
                            0] / rpm.name

                        # record Artifact in database
                        artifact, _ = Artifact.get_or_create(
                            nvr=nvr, path=destination.relative_to(base))

                        # move RPM file to destination
                        safe_check(rpm, destination)
                        shutil.copy2(rpm, destination)
                        selinux.restorecon(destination)

                    if not keep:
                        rpm.unlink()
                else:
                    # ensure the incoming architecture matches one of the configured architectures
                    if pkg.arch != 'src' and pkg.arch not in architectures:
                        raise SystemExit(
                            f'{rpm.name}: architecture not configured for {repo}'
                        )

                    # compute destination path
                    if pkg.name.endswith('-debuginfo') or pkg.name.endswith(
                            '-debugsource'):
                        repodirs.add(base / pkg.arch / 'debug')
                        destination = base / pkg.arch / 'debug' / 'packages' / rpm.name[
                            0] / rpm.name
                    else:
                        repodirs.add(base / pkg.arch)
                        destination = base / pkg.arch / 'packages' / rpm.name[
                            0] / rpm.name

                    # record Artifact in database
                    artifact, _ = Artifact.get_or_create(
                        nvr=nvr, path=destination.relative_to(base))

                    # move RPM file to destination
                    if keep:
                        safe_check(rpm, destination)
                        shutil.copy2(rpm, destination)
                    else:
                        safe_check(rpm, destination)
                        shutil.move(rpm, destination)
                    selinux.restorecon(destination)

    db.close()

    click.secho('generating repodata', fg='cyan')
    with click.progressbar(iterable=repodirs, fill_char='█') as repodirs_bar:
        for repodir in repodirs_bar:
            createrepo(repodir)
Exemplo n.º 36
0
 def process_pkg(filename, href):
     pkg = createrepo.package_from_rpm(filename)
     pkg.location_href = href
     return pkg