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 sqlite support #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
flake8 cleanups
Matt Dees committed Nov 1, 2020

Verified

This commit was signed with the committer’s verified signature.
henrikvtcodes Henrik VT
commit 2a596763b1c5a456ccbae590a5fe4f1215140dbe
18 changes: 9 additions & 9 deletions source/repomd.py
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@
import tempfile


import pprint

_ns = {
'common': 'http://linux.duke.edu/metadata/common',
'repo': 'http://linux.duke.edu/metadata/repo',
@@ -50,7 +48,7 @@ def get_repo_file_contents(self, data_type):
data_type - The XML Node to look for, usually 'primary' or 'primary_db'

Returns:
(bytes) - An uncompressed bytes object from the URL referenced
(bytes) - An uncompressed bytes object from the URL referenced
in the found xml node.

Common Exceptions:
@@ -67,21 +65,23 @@ def get_repo_file_contents(self, data_type):
with bz2.BZ2File(compressed) as uncompressed:
return uncompressed.read()


def load(baseurl):
repomd_obj = get_repomd_obj(baseurl)
repo_obj = None
# download and parse repomd.xml
try:
primary_contents = repomd_obj.get_repo_file_contents('primary_db')
repo_obj = SQLiteRepo(baseurl, primary_contents)
except AttributeError as e:
except AttributeError:
# silencing this error so that we can pass to the next exception
pass
if not repo_obj:
primary_contents = repomd_obj.get_repo_file_contents('primary')
repo_obj = XmlRepo(baseurl, primary_contents)
return repo_obj


class BasePackage:

@property
@@ -127,9 +127,10 @@ def __hash__(self):
def __repr__(self):
return f'<{self.__class__.__name__}: "{self.nevra}">'


class SQLitePackage(BasePackage):
"""A Class for inspecting packages in an SQLite-based repo.

Most properties are generated based on primary.packages column headers and dynamically
generated from the pkg_row constructor parameter.

@@ -161,7 +162,7 @@ class SQLitePackage(BasePackage):
location_base TEXT
checksum_type TEXT

These could vary between different yum repo versions but should be consistent with most major
These could vary between different yum repo versions but should be consistent with most major
red hat-derived distros in 2019.

There are some other properties as well that are not dynamically generated.
@@ -175,7 +176,7 @@ class SQLitePackage(BasePackage):

Parameters:
pkg_row - an sqlite3.Row object representing the sqlite table.

"""
def __init__(self, pkg_row):
self.pkg_row = pkg_row
@@ -327,7 +328,7 @@ class SQLiteRepo(BaseRepo):
def __init__(self, baseurl, metadata):
self.baseurl = baseurl
self.db_file = tempfile.NamedTemporaryFile()
self.db_file.write(metadata)
self.db_file.write(metadata)
self.conn = sqlite3.connect(self.db_file.name)
self.conn.row_factory = sqlite3.Row

@@ -360,4 +361,3 @@ def find(self, pkgname):
if res:
return SQLitePackage(res)
return None