Split out common keypath code to it's own function
authorBrian Dolbec <dolsen@gentoo.org>
Sun, 14 Jul 2013 06:04:26 +0000 (23:04 -0700)
committerBrian Dolbec <dolsen@gentoo.org>
Sun, 14 Jul 2013 17:15:22 +0000 (10:15 -0700)
Add a reset task() to clear/reset additional args.
Code list_keys()

gkeys/lib.py

index cae7f07a8f64ce88afa1cb948b69731cff3b7beb..0f7ae5e8e72970c1a463bc1d040038b6b6439573 100644 (file)
@@ -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):