diff options
author | 2018-07-02 14:52:17 -0700 | |
---|---|---|
committer | 2018-07-06 22:22:11 -0700 | |
commit | 691285b64caf4497d693462751d81a74934b36a1 (patch) | |
tree | 449d7b41e948513b4dded5ab6a9712515d39b0f2 /gkeys | |
parent | gkeys/fileops.py: Add new updateseeds function (diff) | |
download | gentoo-keys-691285b64caf4497d693462751d81a74934b36a1.tar.gz gentoo-keys-691285b64caf4497d693462751d81a74934b36a1.tar.bz2 gentoo-keys-691285b64caf4497d693462751d81a74934b36a1.zip |
gkeys/fetch.py: New Fetch class
Add sig_path assignment, makes the sig_path available to class instance holders like _verify()
Use the lack of a returned timestamp to abort the process
If the main file is not downloaded, then don't bother looking for a signature.
This allows a verify action to exit smoothly.
There is a message about the reason for not downloading, so is not hidden.
Signed-off-by: Brian Dolbec <dolsen@gentoo.org>
Diffstat (limited to 'gkeys')
-rw-r--r-- | gkeys/gkeys/fetch.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/gkeys/gkeys/fetch.py b/gkeys/gkeys/fetch.py new file mode 100644 index 0000000..365124a --- /dev/null +++ b/gkeys/gkeys/fetch.py @@ -0,0 +1,63 @@ + +from sslfetch.connections import Connector, get_timestamp +from gkeys import _unicode + +EXTENSIONS = ['.sig', '.asc', '.gpg','.gpgsig'] + + +class Fetch(object): + + def __init__(self, logger): + self.logger = logger + connector_output = { + 'info': self.logger.info, + 'debug': self.logger.debug, + 'error': self.logger.error, + 'exception': self.logger.exception, + # we want any warnings to be printed to the terminal + # so assign it to logging.error + 'warning': self.logger.error, + 'kwargs-info': {}, + 'kwargs-debug': {}, + 'kwargs-error': {}, + 'kwargs-exception': {}, + 'kwargs-warning': {}, + } + self.fetcher = Connector(connector_output, None, "Gentoo Keys") + self.sig_path = None + + def fetch_url(self, url, filepath, signature=True, timestamp=None, timestamp_path=None, climit=60): + if not timestamp_path: + timestamp_path = filepath + ".timestamp" + messages = [] + self.logger.debug( + _unicode("FETCH: fetching %s signed file ") % filepath) + self.logger.debug( + _unicode("FETCH: timestamp path: %s") % timestamp_path) + success, signedfile, timestamp = self.fetcher.fetch_file( + url, filepath, timestamp_path, climit=climit, timestamp=timestamp) + if timestamp is '': + self.logger.debug("Fetch.fetch_url; file not downloaded") + return (False, messages) + elif not success: + messages.append(_unicode("File %s cannot be retrieved.") % filepath) + elif '.' + url.rsplit('.', 1)[1] not in EXTENSIONS: + self.logger.debug("File %s successfully retrieved.", filepath) + if signature: + success_fetch = False + for ext in EXTENSIONS: + sig_path = filepath + ext + signature = url + ext + self.logger.debug( + _unicode("FETCH: fetching %s signature ") + % signature) + success_fetch, sig, timestamp = self.fetcher.fetch_file(signature, sig_path) + if success_fetch: + self.sig_path = sig_path + break + else: + signature = None + return (success, messages) + + def verify_cycle(self, tpath, climit=60): + return self.fetcher.verify_cycle(tpath, climit=60) |