From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 888BE13877A for ; Wed, 20 Aug 2014 03:55:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2350DE084A; Wed, 20 Aug 2014 03:55:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 218EAE083A for ; Wed, 20 Aug 2014 03:55:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EF1CB34002D for ; Wed, 20 Aug 2014 03:55:19 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 9A88839AE for ; Wed, 20 Aug 2014 03:55:18 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1404150068.58d9bbc078e6714e4a9ae1975576428bc355bdc0.dol-sen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys/lib.py gkeys/seed.py X-VCS-Directories: gkeys/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 58d9bbc078e6714e4a9ae1975576428bc355bdc0 X-VCS-Branch: master Date: Wed, 20 Aug 2014 03:55:18 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 32754e50-947a-41cb-9fa4-8d90d4caef5c X-Archives-Hash: 879003cc8da3a1b1f296adb267d6a033 commit: 58d9bbc078e6714e4a9ae1975576428bc355bdc0 Author: Brian Dolbec gentoo org> AuthorDate: Mon Jun 30 17:41:08 2014 +0000 Commit: Brian Dolbec gmail com> CommitDate: Mon Jun 30 17:41:08 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=58d9bbc0 add seed file installed db --- gkeys/lib.py | 41 ++++++++++++++++++++++++++--------------- gkeys/seed.py | 34 +++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/gkeys/lib.py b/gkeys/lib.py index b888367..c80cff6 100644 --- a/gkeys/lib.py +++ b/gkeys/lib.py @@ -25,6 +25,7 @@ from os.path import join as pjoin from pyGPG.gpg import GPG from gkeys.fileops import ensure_dirs from gkeys.log import logger +from gkeys.seed import Seeds class GkeysGPG(GPG): '''Gentoo-keys primary gpg class''' @@ -90,38 +91,44 @@ class GkeysGPG(GPG): '''Add the specified key to the specified keydir @param gkey: GKEY namedtuple with - (name, keyid/longkeyid, keydir, fingerprint,) + (name, nick, keydir, fingerprint) ''' self.set_keyserver() self.set_keydir(gkey.keydir, 'recv-keys', reset=True) self.set_keyring('pubring.gpg', 'recv-keys', reset=False) + # Save the gkey seed to the installed db + self.set_keyseedfile() + self.seedfile.update(gkey) + if not self.seedfile.save(): + logger.error("GkeysGPG.add_key(); failed to save seed" + gkey.nick) + return [] logger.debug("LIB: add_key; ensure dirs: " + self.keydir) ensure_dirs(str(self.keydir)) - keyids = gkey.keyid + fingerprints = gkey.fingerprint results = [] - for keyid in keyids: - logger.debug("LIB: add_key; final keyids" + keyid) + for fingerprint in fingerprints: + logger.debug("LIB: add_key; adding fingerprint" + fingerprint) logger.debug("** Calling runGPG with Running 'gpg %s --recv-keys %s' for: %s" % (' '.join(self.config.get_key('tasks', 'recv-keys')), - keyid, gkey.name) - ) - result = self.runGPG(task='recv-keys', inputfile=keyid) + fingerprint, gkey.name)) + result = self.runGPG(task='recv-keys', inputfile=fingerprint) logger.info('GPG return code: ' + str(result.returncode)) if result.fingerprint in gkey.fingerprint: result.failed = False message = "Fingerprints match... Import successful: " - message += "key: %s" %keyid - message += "\n result len: %s, %s" %(len(result.fingerprint), result.fingerprint) - message += "\n gkey len: %s, %s" %(len(gkey.fingerprint[0]), gkey.fingerprint[0]) + message += "fingerprint: %s" % fingerprint + message += "\n result len: %s, %s" % (len(result.fingerprint), result.fingerprint) + message += "\n gkey len: %s, %s" % (len(gkey.fingerprint[0]), gkey.fingerprint[0]) logger.info(message) else: result.failed = True message = "Fingerprints do not match... Import failed for " - message += "key: %s" %keyid - message += "\n result: %s" %(result.fingerprint) - message += "\n gkey..: %s" %(str(gkey.fingerprint)) + message += "fingerprint: %s" % fingerprint + message += "\n result: %s" % (result.fingerprint) + message += "\n gkey..: %s" % (str(gkey.fingerprint)) logger.error(message) results.append(result) + print("lib.add_key(), result =") print(result.stderr_out) return results @@ -129,7 +136,7 @@ class GkeysGPG(GPG): def del_key(self, gkey, keydir): '''Delete the specified key in the specified keydir - @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint) + @param gkey: GKEY namedtuple with (name, nick, keydir, fingerprint) ''' return [] @@ -143,7 +150,7 @@ class GkeysGPG(GPG): def update_key(self, gkey, keydir): '''Update the specified key in the specified keydir - @param key: tuple of (name, keyid, fingerprint) + @param key: tuple of (name, nick, keydir, fingerprint) @param keydir: the keydir to add the key to ''' return [] @@ -195,3 +202,7 @@ class GkeysGPG(GPG): '''Verify the file specified at filepath ''' pass + + def set_keyseedfile(self): + self.seedfile = Seeds(pjoin(self.keydir, 'gkey.seeds')) + self.seedfile.load() diff --git a/gkeys/seed.py b/gkeys/seed.py index 9dfa955..cfb2b98 100644 --- a/gkeys/seed.py +++ b/gkeys/seed.py @@ -88,20 +88,17 @@ class Seeds(object): return False - def delete(self, gkey=None, index=None): + def delete(self, gkey=None): '''Delete the key from the seeds in memory @param gkey: GKEY, the matching GKEY to delete - @param index: int, ''' + ''' if gkey: try: - self.seeds.pop(getattr(gkey[0], 'nick'), None) + self.seeds.pop(gkey.nick, None) except ValueError: return False return True - elif index: - self.seeds.pop(index) - return True def list(self, **kwargs): @@ -125,19 +122,16 @@ class Seeds(object): '''Search for the keys matching the regular expression pattern''' pass + def nick_search(self, nick): + '''Searches the seeds for a matching nick - def index(self, gkey): - '''The index of the gkey in the seeds list - - @param gkey: GKEY, the matching GKEY to delete - @return int + @param nick: string + @returns GKEY instance or None ''' try: - index = self.seeds.index(gkey) - except ValueError: + return self.seeds[nick] + except KeyError: return None - return index - def _error(self, err): '''Class error logging function''' @@ -153,3 +147,13 @@ class Seeds(object): if is_gkey: seeds[dev] = dict(value._asdict()) return json.dumps(seeds, sort_keys=True, indent=4) + + def update(self, gkey): + '''Looks for existance of a matching nick already in the seedfile + if it exists. Then either adds or replaces the gkey + @param gkey: GKEY instance + ''' + oldkey = self.nick_search(gkey.nick[0]) + if oldkey: + self.delete(oldkey) + self.add(gkey.nick, gkey)