More Actions improvements.
authorBrian Dolbec <dolsen@gentoo.org>
Sun, 14 Jul 2013 06:01:47 +0000 (23:01 -0700)
committerBrian Dolbec <dolsen@gentoo.org>
Sun, 14 Jul 2013 17:15:10 +0000 (10:15 -0700)
gkeys/actions.py
gkeys/cli.py

index 497ec38fd657dc8302d3a10474b64874c14770c5..9873362760f20adc060f5a946119058f443fb22b 100644 (file)
     @license: GNU GPL2, see COPYING for details.
 """
 
+from __future__ import print_function
+
 
 from gkeys.config import GKEY
 from gkeys.lib import GkeysGPG
 from gkeys.seed import Seeds
 
 
-
+Avialable_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'listkey',
+            'addkey', 'removekey', 'movekey', 'installed']
 
 
 class Actions(object):
     '''Primary api actions'''
 
-    def __init__(self, config, output, logger=None):
+    def __init__(self, config, output=None, logger=None):
         self.config = config
         self.output = output
         self.logger = logger
@@ -165,9 +168,9 @@ class Actions(object):
             kwargs = self.build_gkeydict(args)
             # get the desired seed
             keyresults = self.seeds.list(**kwargs)
-            if keyresults and not args.nick == '*':
+            if keyresults and not args.nick == '*' and self.output:
                 self.output(keyresults, "\n Found GKEY seeds:")
-            elif keyresults:
+            elif keyresults and self.output:
                 self.output(['all'], "\n Installed seeds:")
             else:
                 self.logger.info("ACTIONS: listkey; "
@@ -181,27 +184,31 @@ class Actions(object):
             # get confirmation
             # fill in code here
             keydir = self.config.get_key(args.seeds + "-keydir")
-            self.logger.debug("ACTIONS: addkey; keysdir = %s" % keydir)
+            self.logger.debug("ACTIONS: listkey; keysdir = %s" % keydir)
             self.gpg = GkeysGPG(self.config, keydir)
             results = {}
             #failed = []
+            print(" GPG output:")
             for key in keyresults:
                 if not key.keyring and not args.nick == '*':
                     self.logger.debug("ACTIONS: listkey; NO keyring... Ignoring")
                     return {"Failed: No keyid's found for %s" % key.name : ''}
-                self.logger.debug("ACTIONS: listkey; listing keyring:")
-                self.logger.debug("ACTIONS: " + str(key.keyring))
+                self.logger.debug("ACTIONS: listkey; listing keyring:"
+                    + str(key.keyring))
                 results[key.name] = self.gpg.list_keys(key.keyring)
-                for result in results[key.name]:
-                    self.logger.debug("ACTIONS: listkey; result.failed = " +
-                        str(result.failed))
                 if self.config.options['print_results']:
-                    for result in results[key.name]:
-                        print("key desired:", key.name, ", keyring listed:",
-                            result.username, ", keyid:", result.keyid,
-                            ", fingerprint:", result.fingerprint)
-                        self.logger.debug("stderr_out: " + str(result.stderr_out))
-        return {"No keyrings to list": False}
+                    print(results[key.name].output)
+                    self.logger.debug("data output:\n" +
+                        str(results[key.name].output))
+                    #for result in results[key.name].status.data:
+                        #print("key desired:", key.name, ", keyring listed:",
+                            #result)
+                        #self.logger.debug("data record: " + str(result))
+                else:
+                    return results
+            return {'done': True}
+        else:
+            return {"No keyrings to list": False}
 
 
     def addkey(self, args):
@@ -212,9 +219,9 @@ class Actions(object):
         if self.seeds:
             # get the desired seed
             keyresults = self.seeds.list(**kwargs)
-            if keyresults and not args.nick == '*':
+            if keyresults and not args.nick == '*' and self.output:
                 self.output(keyresults, "\n Found GKEY seeds:")
-            elif keyresults:
+            elif keyresults and self.output:
                 self.output(['all'], "\n Installing seeds:")
             else:
                 self.logger.info("ACTIONS: addkey; "
@@ -255,7 +262,7 @@ class Actions(object):
                         self.logger.debug("stderr_out: " + str(result.stderr_out))
                         if result.failed:
                             failed.append(key)
-            if failed:
+            if failed and self.output:
                 self.output(failed, "\n Failed to install:")
             return {'Completed'}
         return {"No seeds to search or install": False}
@@ -271,6 +278,12 @@ class Actions(object):
         pass
 
 
+    def installed(self, args):
+        '''Action installed method.
+        lists the installed key directories'''
+        pass
+
+
     def user_confirm(self, message):
         '''Get input from the user to confirm to proceed
         with the desired action
index 36592d5321ae49c12608cf692268a470858e931a..d34ed4dc0c5bd193f6b5a485c5e1706658c36467 100644 (file)
@@ -24,7 +24,7 @@ from gkeys import seed
 from gkeys import lib
 
 from gkeys.config import GKeysConfig
-from gkeys.actions import Actions
+from gkeys.actions import Actions, Avialable_Actions
 
 
 
@@ -59,8 +59,7 @@ class Main(object):
         @returns argparse.Namespace object
         '''
         #logger.debug('MAIN: parse_args; args: %s' % args)
-        actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'listkey',
-            'addkey', 'removekey', 'movekey']
+        actions = Avialable_Actions
         parser = argparse.ArgumentParser(
             prog='gkeys',
             description='Gentoo-keys manager program',
@@ -150,6 +149,7 @@ class Main(object):
         # super simple output for the time being
         print(header)
         print("\n".join([str(x) for x in results]))
+        print()