Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a high-level API for creating repodata #271

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/python/simple_createrepo.py → examples/python/manual_createrepo.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os.path
import createrepo_c as cr

def do_repodata(path):
def manual_method(path):
# Prepare repodata/ directory
repodata_path = os.path.join(path, "repodata")
if os.path.exists(repodata_path):
Expand Down Expand Up @@ -37,10 +37,10 @@ def do_repodata(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)
with os.scandir(path) as entries:
for entry in entries:
if entry.is_file() and entry.path.endswith(".rpm"):
pkg_list.append(entry.path)

pri_xml.set_num_of_pkgs(len(pkg_list))
fil_xml.set_num_of_pkgs(len(pkg_list))
Expand Down Expand Up @@ -93,6 +93,6 @@ def do_repodata(path):
print("Usage: %s <directory>" % (sys.argv[0]))
sys.exit(1)

do_repodata(sys.argv[1])
manual_method(sys.argv[1])

print("Repository created in %s" % sys.argv[1])
21 changes: 21 additions & 0 deletions examples/python/simple_repository_reading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python

import os
import sys
import createrepo_c as cr

REPO_PATH = "tests/testdata/repo_with_additional_metadata/"


def parse_repository(path):
reader = cr.RepositoryReader.from_path(path)

for package in reader.iter_packages():
print("Package {}".format(package.nevra()))

for advisory in reader.advisories():
print("Advisory {}".format(advisory.id))


if __name__ == "__main__":
parse_repository(REPO_PATH)
67 changes: 67 additions & 0 deletions examples/python/simple_repository_writing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python

import os
import sys
import createrepo_c as cr


def write_repository_v1(path):
# List directory and prepare list of files to process
pkg_list = []

with os.scandir(path) as entries:
for entry in entries:
if entry.is_file() and entry.path.endswith(".rpm"):
pkg_list.append(entry.path)

# create a RepositoryWriter with a context manager - finish() is called automatically
# let's just use the default options
with cr.RepositoryWriter(path) as writer:
writer.repomd.add_repo_tag("Fedora 34")
writer.repomd.set_revision("1628310033")
# we have to set the number of packages we will add, before we add them
writer.set_num_of_pkgs(len(pkg_list))

for filename in pkg_list:
pkg = writer.add_pkg_from_file(filename)
print("Added: %s" % pkg.nevra())


def write_repository_v2(path):
# List directory and prepare list of files to process
pkg_list = []

with os.scandir(path) as entries:
for entry in entries:
if entry.is_file() and entry.path.endswith(".rpm"):
pkg_list.append(entry.path)

# create a writer without a context manager - you need to manually call finish()
# change a couple of the defaults too
writer = cr.RepositoryWriter(
path,
unique_md_filenames=False,
changelog_limit=4,
checksum_type=cr.SHA512,
compression=cr.GZ_COMPRESSION,
)
writer.repomd.add_repo_tag("Fedora 34")
writer.repomd.set_revision("1628310033")
writer.set_num_of_pkgs(len(pkg_list))

for filename in pkg_list:
pkg = writer.add_pkg_from_file(filename)
print("Added: %s" % pkg.nevra())

writer.finish()


if __name__ == "__main__":
if len(sys.argv) != 2 or not os.path.isdir(sys.argv[1]):
print("Usage: %s <directory>" % (sys.argv[0]))
sys.exit(1)

write_repository_v1(sys.argv[1])
# write_repository_v2(sys.argv[1])

print("Repository created in %s" % sys.argv[1])
2 changes: 1 addition & 1 deletion examples/python/updateinfo_gen_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def generate():
pkg.src = "foo.src.rpm"
pkg.filename = "foo-1.2.3-1.rpm"
pkg.sum = "123456789"
pkg.sum_type = cr.MD5
pkg.sum_type = cr.SHA256
pkg.reboot_suggested = False

col = cr.UpdateCollection()
Expand Down
2 changes: 1 addition & 1 deletion examples/python/updateinfo_gen_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate():
pkg.src = "foo.src.rpm"
pkg.filename = "foo-1.2.3-1.rpm"
pkg.sum = "123456789"
pkg.sum_type = cr.MD5
pkg.sum_type = cr.SHA256
pkg.reboot_suggested = False

col = cr.UpdateCollection()
Expand Down
4 changes: 2 additions & 2 deletions src/compression_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef enum {
CR_CW_MODE_SENTINEL, /*!< Sentinel of the list */
} cr_OpenMode;

/** Stat build about open content during compression (writting).
/** Stat build about open content during compression (writing).
*/
typedef struct {
gint64 size; /*!< Size of content */
Expand Down Expand Up @@ -87,7 +87,7 @@ typedef struct {
void *INNERFILE; /*!< Pointer to underlying FILE */
cr_OpenMode mode; /*!< Mode */
cr_ContentStat *stat; /*!< Content stats */
cr_ChecksumCtx *checksum_ctx; /*!< Checksum contenxt */
cr_ChecksumCtx *checksum_ctx; /*!< Checksum context */
} CR_FILE;

#define CR_CW_ERR -1 /*!< Return value - Error */
Expand Down
2 changes: 1 addition & 1 deletion src/createrepo_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ main(int argc, char **argv)
fex_db_filename = g_strconcat(tmp_out_repo, "/filelists-ext.sqlite", NULL);
oth_db_filename = g_strconcat(tmp_out_repo, "/other.sqlite", NULL);
} else {
g_debug("Creating databases localy");
g_debug("Creating databases locally");
const gchar *tmpdir = g_get_tmp_dir();
pri_db_filename = g_build_filename(tmpdir, "primary.XXXXXX.sqlite", NULL);
fil_db_filename = g_build_filename(tmpdir, "filelists.XXXXXX.sqlite", NULL);
Expand Down
Loading
Loading