| |
@@ -19,18 +19,153 @@
|
| |
import six
|
| |
import sys
|
| |
|
| |
-
|
| |
- from pyrpkg.errors import InvalidHashType, UploadError
|
| |
+ from pyrpkg.errors import InvalidHashType, UploadError, LayoutError
|
| |
from pyrpkg.lookaside import CGILookasideCache
|
| |
+ from pyrpkg.layout.layouts import DistGitLayout
|
| |
+
|
| |
+ from . import utils
|
| |
+
|
| |
+
|
| |
+ def is_dist_git(folder):
|
| |
+ """
|
| |
+ Indicates if a folder is using a dist-git layout.
|
| |
+
|
| |
+ Parameters
|
| |
+ ----------
|
| |
+ folder: str
|
| |
+ The directory to inspect.
|
| |
+
|
| |
+ Returns
|
| |
+ -------
|
| |
+ bool
|
| |
+ A bool flag indicating if `folder` is using
|
| |
+ a dist-git layout format.
|
| |
+ """
|
| |
+ result = False
|
| |
+
|
| |
+ try:
|
| |
+ DistGitLayout.from_path(folder)
|
| |
+ result = True
|
| |
+ except LayoutError:
|
| |
+ result = False
|
| |
+ finally:
|
| |
+ return result
|
| |
|
| |
|
| |
class StreamLookasideCache(CGILookasideCache):
|
| |
- def __init__(self, hashtype, download_url, upload_url):
|
| |
+ """
|
| |
+ CentosStream lookaside specialized class.
|
| |
+
|
| |
+ It inherits most of its behavior from `pyrpkg.lookasideCGILookasideCache`.
|
| |
+ """
|
| |
+
|
| |
+ def __init__(self, hashtype, download_url, upload_url, client_cert=None, ca_cert=None):
|
| |
super(StreamLookasideCache, self).__init__(
|
| |
- hashtype, download_url, upload_url)
|
| |
+ hashtype, download_url, upload_url,
|
| |
+ client_cert=client_cert, ca_cert=ca_cert)
|
| |
|
| |
- self.download_path = (
|
| |
- '%(name)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s')
|
| |
+ def remote_file_exists(self, name, filename, hashstr):
|
| |
+ """
|
| |
+ Check if a remote file exists.
|
| |
+
|
| |
+ This method inherits the behavior of its parent class from pyrpkg.
|
| |
+
|
| |
+ It uses the internal `utils.get_repo_name` mehtod to parse the name in case
|
| |
+ it is a scm url.
|
| |
+
|
| |
+ Parameters
|
| |
+ ----------
|
| |
+ name: str
|
| |
+ The repository name and org.
|
| |
+
|
| |
+ filename: str
|
| |
+ The filename (something.tar.gz).
|
| |
+
|
| |
+ hash:
|
| |
+ The hash string for the file.
|
| |
+
|
| |
+ Returns
|
| |
+ -------
|
| |
+ bool
|
| |
+ A boolean value to inditicate if the file exists.
|
| |
+ """
|
| |
+ _name = utils.get_repo_name(name) if is_dist_git(os.getcwd()) else name
|
| |
+
|
| |
+ return super(StreamLookasideCache, self).remote_file_exists(
|
| |
+ _name, filename, hashstr)
|
| |
+
|
| |
+ def upload(self, name, filename, hashstr, offline=False):
|
| |
+ """
|
| |
+ Uploads a file to lookaside cache.
|
| |
+
|
| |
+ This method inherits the behavior of its parent class from pyrpkg.
|
| |
+
|
| |
+ It uses the internal `utils.get_repo_name` mehtod to parse the name in case
|
| |
+ it is a scm url.
|
| |
+
|
| |
+ Parameters
|
| |
+ ----------
|
| |
+ name: str
|
| |
+ The repository name and org.
|
| |
+
|
| |
+ filename: str
|
| |
+ The filename (something.tar.gz).
|
| |
+
|
| |
+ hash:
|
| |
+ The hash string for the file.
|
| |
+
|
| |
+ Raises
|
| |
+ ------
|
| |
+ pyrpkg.errors.rpkgError
|
| |
+ Raises specialized classes that inherits from pyrokg base errors.
|
| |
+
|
| |
+ Returns
|
| |
+ -------
|
| |
+ None
|
| |
+ Does not return anything
|
| |
+ """
|
| |
+ _name = utils.get_repo_name(name) if is_dist_git(os.getcwd()) else name
|
| |
+
|
| |
+ return super(StreamLookasideCache, self).upload(
|
| |
+ _name, filename, hashstr)
|
| |
+
|
| |
+ def download(self, name, filename, hashstr, outfile, hashtype=None, **kwargs):
|
| |
+ """
|
| |
+ Downloads a file from lookaside cache to the local filesystem.
|
| |
+
|
| |
+ This method inherits the behavior of its parent class from pyrpkg.
|
| |
+
|
| |
+ It uses the internal `utils.get_repo_name` mehtod to parse the name in case
|
| |
+ it is a scm url.
|
| |
+
|
| |
+ Parameters
|
| |
+ ----------
|
| |
+ name: str
|
| |
+ The repository name and org.
|
| |
+
|
| |
+ filename: str
|
| |
+ The filename (something.tar.gz).
|
| |
+
|
| |
+ hash: str
|
| |
+ The hash string for the file.
|
| |
+
|
| |
+ outfile: str
|
| |
+
|
| |
+
|
| |
+ Raises
|
| |
+ ------
|
| |
+ pyrpkg.errors.rpkgError
|
| |
+ Raises specialized implementations of `yrpkg.errors.rpkgError`.
|
| |
+
|
| |
+ Returns
|
| |
+ -------
|
| |
+ None
|
| |
+ Does not return anything
|
| |
+ """
|
| |
+ _name = utils.get_repo_name(name) if is_dist_git(os.getcwd()) else name
|
| |
+
|
| |
+ return super(StreamLookasideCache, self).download(
|
| |
+ _name, filename, hashstr, outfile, hashtype=hashtype, **kwargs)
|
| |
|
| |
|
| |
class SIGLookasideCache(CGILookasideCache):
|
| |
@@ -56,13 +191,15 @@
|
| |
# type it would explode with "unsupported second type in tuple". Let's
|
| |
# convert to str just to be sure.
|
| |
# https://bugzilla.redhat.com/show_bug.cgi?id=1241059
|
| |
+ _name = utils.get_repo_name(name) if is_dist_git(os.getcwd()) else name
|
| |
+
|
| |
if six.PY2 and isinstance(filename, six.text_type):
|
| |
filename = filename.encode('utf-8')
|
| |
|
| |
if six.PY2 and isinstance(self.branch, six.text_type):
|
| |
self.branch = self.branch.encode('utf-8')
|
| |
|
| |
- post_data = [('name', name),
|
| |
+ post_data = [('name', _name),
|
| |
('%ssum' % self.hashtype, hash),
|
| |
('branch', self.branch),
|
| |
('filename', filename)]
|
| |
Forces the use of
rpms
as org name in case repository is a dist-git one when doing lookaside operations.