From 58a50b8ab5290b93631f6e20609936d426b360b8 Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Tue, 27 Nov 2012 20:01:11 -0800 Subject: properly detect and enable gpg signed list support. prevents a build failure if pygpg is not installed. --- layman/remotedb.py | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/layman/remotedb.py b/layman/remotedb.py index 851b89b..f8aea16 100644 --- a/layman/remotedb.py +++ b/layman/remotedb.py @@ -31,14 +31,22 @@ import sys import urllib2 import hashlib -from pygpg.config import GPGConfig -from pygpg.gpg import GPG + +GPG_ENABLED = False +try: + from pygpg.config import GPGConfig + from pygpg.gpg import GPG + GPG_ENABLED = True +except ImportError: + pass + from layman.utils import encoder from layman.dbbase import DbBase from layman.version import VERSION from layman.compatibility import fileopen + class RemoteDB(DbBase): '''Handles fetching the remote overlay list.''' @@ -46,6 +54,8 @@ class RemoteDB(DbBase): self.config = config self.output = config['output'] + self.detached_urls = [] + self.signed_urls = [] self.proxies = {} @@ -62,20 +72,10 @@ class RemoteDB(DbBase): self.urls = [i.strip() for i in config['overlays'].split('\n') if len(i)] - #pair up the list url and detached sig url - d_urls = [i.strip() - for i in config['gpg_detached_lists'].split('\n') if len(i)] - self.detached_urls = [] - #for index in range(0, len(d_urls), 2): - # self.detached_urls.append((d_urls[index], d_urls[index+1])) - for i in d_urls: - u = i.split() - self.detached_urls.append((u[0], u[1])) - - self.signed_urls = [i.strip() - for i in config['gpg_signed_lists'].split('\n') if len(i)] - - self.output.debug('RemoteDB.__init__(), url lists= \nself.urls: %s\nself.detached_urls: %s\nself.signed_urls: %s' % (str(self.urls), str(self.detached_urls), str(self.signed_urls)), 2) + if GPG_ENABLED: + self.get_gpg_urls() + else: + self.output.debug('RemoteDB.__init__(), NOT GPG_ENABLED, bypassing...', 2) # add up the lists to load for display, etc. # unsigned overlay lists @@ -85,6 +85,8 @@ class RemoteDB(DbBase): # single file signed, compressed, clearsigned paths.extend([self.filepath(i) + '.xml' for i in self.signed_urls]) + self.output.debug('RemoteDB.__init__(), url lists= \nself.urls: %s\nself.detached_urls: %s\nself.signed_urls: %s' % (str(self.urls), str(self.detached_urls), str(self.signed_urls)), 2) + self.output.debug('RemoteDB.__init__(), paths to load = %s' %str(paths), 2) if config['nocheck']: @@ -397,6 +399,24 @@ class RemoteDB(DbBase): self.gpg = GPG(self.gpg_config) self.output.debug("RemoteDB.init_gpg(), initialized :D",2) + def get_gpg_urls(self): + '''Extend paths with gpg signed url listings from the config + + @param paths: list or urls to fetch + ''' + #pair up the list url and detached sig url + d_urls = [i.strip() + for i in self.config['gpg_detached_lists'].split('\n') if len(i)] + + #for index in range(0, len(d_urls), 2): + # self.detached_urls.append((d_urls[index], d_urls[index+1])) + for i in d_urls: + u = i.split() + self.detached_urls.append((u[0], u[1])) + + self.signed_urls = [i.strip() + for i in config['gpg_signed_lists'].split('\n') if len(i)] + if __name__ == '__main__': import doctest -- cgit v1.2.3-1-g7c22