[PATCH 07/21] Add a new lookaside module
Mathieu Bridon
bochecha at fedoraproject.org
Wed May 6 11:53:03 UTC 2015
From: Mathieu Bridon <bochecha at daitauha.fr>
At the moment this doesn't do much: it only stores the 3
lookaside-related parameters we have (a download url, an upload url and
a hash type), but eventually it will become a full-fledged lookaside
cache client.
Using a property for it makes it trivial for downstreams to override it
if they need to use their own implementation of a lookaside cache
client.
And using a cached property means we won't reinitialize the
CGILookasideCache object every time we access the
Commands.lookasidecache attribute.
---
src/pyrpkg/__init__.py | 16 ++++++++++++++++
src/pyrpkg/lookaside.py | 30 ++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
create mode 100644 src/pyrpkg/lookaside.py
diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 9e706b4..b06c68b 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -39,7 +39,9 @@ except ImportError:
pass
from pyrpkg.errors import HashtypeMixingError, rpkgError, rpkgAuthError
+from pyrpkg.lookaside import CGILookasideCache
from pyrpkg.sources import SourcesFile
+from pyrpkg.utils import cached_property
# Setup our logger
@@ -166,6 +168,20 @@ class Commands(object):
# that we can do clone actions without knowing things like the spec
# file or rpm data.
+ @cached_property
+ def lookasidecache(self):
+ """A helper to interact with the lookaside cache
+
+ This is a pyrpkg.lookaside.CGILookasideCache instance, providing all
+ the needed stuff to communicate with a Fedora-style lookaside cache.
+
+ Downstream users of the pyrpkg API may override this property with
+ their own, returning their own implementation of a lookaside cache
+ helper object.
+ """
+ return CGILookasideCache(
+ self.lookasidehash, self.lookaside, self.lookaside_cgi)
+
@property
def path(self):
return self._path
diff --git a/src/pyrpkg/lookaside.py b/src/pyrpkg/lookaside.py
new file mode 100644
index 0000000..f7d191e
--- /dev/null
+++ b/src/pyrpkg/lookaside.py
@@ -0,0 +1,30 @@
+# Copyright (c) 2015 - Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
+# the full text of the license.
+
+
+"""Interact with a lookaside cache
+
+This module contains everything needed to upload and download source files the
+way it is done by Fedora, RHEL, and other distributions maintainers.
+"""
+
+
+class CGILookasideCache(object):
+ """A class to interact with a CGI-based lookaside cache"""
+ def __init__(self, hashtype, download_url, upload_url):
+ """Constructor
+
+ Args:
+ hashtype (str): The hash algorithm to use for uploads. (e.g 'md5')
+ download_url (str): The URL used to download source files.
+ upload_url (str): The URL of the CGI script called when uploading
+ source files.
+ """
+ self.hashtype = hashtype
+ self.download_url = download_url
+ self.upload_url = upload_url
--
2.1.0
More information about the rel-eng
mailing list