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 5D363138200 for ; Tue, 16 Jul 2013 00:50:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6B731E09DD; Tue, 16 Jul 2013 00:50:17 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B71E1E09D5 for ; Tue, 16 Jul 2013 00:50:16 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5C45F33E88C for ; Tue, 16 Jul 2013 00:50:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 02B12E5461 for ; Tue, 16 Jul 2013 00:50:14 +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: <1373822122.c7c2cd9758351b873324b5faaf06e2a34f39b22d.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 X-VCS-Directories: gkeys/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: c7c2cd9758351b873324b5faaf06e2a34f39b22d X-VCS-Branch: master Date: Tue, 16 Jul 2013 00:50:14 +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: 64f267c4-c748-48d7-94b0-8a754b4a2d3e X-Archives-Hash: b5d9e226e814cc5e09f55cd521c6c02e commit: c7c2cd9758351b873324b5faaf06e2a34f39b22d Author: Brian Dolbec gentoo org> AuthorDate: Sun Jul 14 06:04:26 2013 +0000 Commit: Brian Dolbec gmail com> CommitDate: Sun Jul 14 17:15:22 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=c7c2cd97 Split out common keypath code to it's own function Add a reset task() to clear/reset additional args. Code list_keys() --- gkeys/lib.py | 58 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/gkeys/lib.py b/gkeys/lib.py index cae7f07..0f7ae5e 100644 --- a/gkeys/lib.py +++ b/gkeys/lib.py @@ -36,6 +36,28 @@ class GkeysGPG(GPG): GPG.__init__(self, config) self.config = config self.keydir = keydir + self.task = None + self.task_value = None + + + def set_keypath(self, keyring, task=None): + logger.debug("keydir: %s, keyring: %s" % (self.keydir, keyring)) + self.task = task + keypath = pjoin(self.keydir, keyring) + # --keyring file | Note that this adds a keyring to the current list. + # If the intent is to use the specified keyring alone, + # use --keyring along with --no-default-keyring. + self.task_value = ['--no-default-keyring', '--keyring', keypath] + task.extend(self.task_value) + return + + + def reset_task(self): + if self.task: + for item in self.task_value: + self.task.remove(item) + self.task = None + self.task_value = None def add_key(self, gkey): @@ -44,14 +66,8 @@ class GkeysGPG(GPG): @param gkey: GKEY namedtuple with (name, keyid/longkeyid, keyring, fingerprint,) ''' - logger.debug("keydir: %s, keyring: %s" % (self.keydir, gkey.keyring)) - keypath = pjoin(self.keydir, gkey.keyring) - # --keyring file | Note that this adds a keyring to the current list. - # If the intent is to use the specified keyring alone, - # use --keyring along with --no-default-keyring. - self.config['tasks']['recv-keys'] = [ - '--no-default-keyring', '--keyring', keypath, - ] + self.set_keypath(gkey.keyring, self.config['tasks']['recv-keys']) + # prefer the longkeyid if available #logger.debug("LIB: add_key; keyids %s, %s" # % (str(gkey.longkeyid), str(gkey.keyid))) @@ -94,13 +110,13 @@ class GkeysGPG(GPG): @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint) ''' - pass + return [] def del_keyring(self, keyring): '''Delete the specified key to the specified keyring ''' - pass + return [] def update_key(self, gkey, keyring): @@ -109,22 +125,36 @@ class GkeysGPG(GPG): @param key: tuple of (name, keyid, fingerprint) @param keyring: the keyring to add the key to ''' - pass + return [] - def list_keys(self, keyring=None): + def list_keys(self, keyring): '''List all keys in the specified keyring or all key in all keyrings if keyring=None @param keyring: the keyring to add the key to ''' - pass + if not keyring: + logger.debug("LIB: list_keys(), invalid keyring parameter: %s" + % str(keyring)) + return [] + if '--with-colons' in self.config['tasks']['list-keys']: + self.config['tasks']['list-keys'].remove('--with-colons') + + self.set_keypath(keyring, self.config['tasks']['list-keys']) + logger.debug("** Calling runGPG with Running 'gpg %s --list-keys %s'" + % (' '.join(self.config['tasks']['list-keys']), keyring) + ) + result = self.runGPG(task='list-keys', inputfile=keyring) + logger.info('GPG return code: ' + str(result.returncode)) + self.reset_task() + return result def list_keyrings(self): '''List all available keyrings ''' - pass + return [] def verify_key(self, gkey):