gkeys/actions.py: Add listseedfiles() and fix -S option support.
authorBrian Dolbec <dolsen@gentoo.org>
Sat, 1 Mar 2014 00:54:25 +0000 (16:54 -0800)
committerBrian Dolbec <dolsen@gentoo.org>
Sat, 1 Mar 2014 00:54:25 +0000 (16:54 -0800)
etc/gkeys.conf
gkeys/actions.py

index 46d45aaa995fe0e6b0f2dad259d266ded37116eb..2497c30bb02a6750450074fa1c8e921e9cc27e11 100644 (file)
@@ -31,14 +31,19 @@ overlays-keydir: %(keysdir)s/overlays
 known-keysfile:  %(keysdir)s/knownkeys
 
 
+# seedsdir: base directory for all seed files
+# used when searching all seed files.
+seedsdir: %(keysdir)s/seeds
+
+
 # releaseseedfile: txt file of one tuple of (name, keyid, fingerprint)
 # entry per line
-release-seedfile: /etc/gentoo-keys/release.seeds
+release-seedfile: %(seedsdir)s/release.seeds
 
 
 # devseedfile: txt file of one tuple of (name, keyid, fingerprint)
 # entry per line
-dev-seedfile: /etc/gentoo-keys/developer.seeds
+dev-seedfile: %(seedsdir)s/developer.seeds
 
 
 # logfile directory
index 77ac212cf913373a8a043ff1bd8adcaf46b7dcad..2e2b1b7bb8aef2f9e7a6b043cf9d67e313d1eea5 100644 (file)
 
 from __future__ import print_function
 
+import os
+
 
 from gkeys.seedhandler import SeedHandler
 from gkeys.lib import GkeysGPG
 from gkeys.seed import Seeds
 
 
-Avialable_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'listkey',
-            'addkey', 'removekey', 'movekey', 'installed']
+Avialable_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed',
+            'listseedfiles', 'listkey', 'addkey', 'removekey', 'movekey',
+            'installed']
 
 
 class Actions(object):
@@ -32,13 +35,17 @@ class Actions(object):
         self.seeds = None
 
 
-    def load_seeds(self, filename):
-        if not filename:
+    def load_seeds(self, seeds=None ,seedfile=None):
+        if not seeds and not seedfile:
             self.logger.error("ACTIONS: load_seeds; no filename to load: "
             "setting = %s.  Please use the -s option to indicate: which seed "
             "file to use." % filename)
             return None
-        filepath = self.config.get_key(filename + "-seedfile")
+        if seeds:
+            filepath = self.config.get_key(filename + "-seedfile")
+        elif seedfile:
+            filepath = os.path.join(self.config.get_key('seedsdir'),
+                                    '%s.seeds' % seedfile)
         self.logger.debug("ACTIONS: load_seeds; seeds filepath to load: "
             "%s" % filepath)
         seeds = Seeds()
@@ -52,7 +59,7 @@ class Actions(object):
         kwargs = handler.build_gkeydict(args)
         self.logger.debug("ACTIONS: listseed; kwargs: %s" % str(kwargs))
         if not self.seeds:
-            self.seeds = self.load_seeds(args.seeds)
+            self.seeds = self.load_seeds(args.seeds, args.seedfile)
         if self.seeds:
             results = self.seeds.list(**kwargs)
             return results
@@ -275,3 +282,9 @@ class Actions(object):
         '''
         pass
 
+
+    def listseedfiles(self, args):
+        seedsdir = self.config.get_key('seedsdir')
+        files = os.listdir(seedsdir)
+        return {"Seed files found at path: %s\n   %s"
+            % (seedsdir, "\n   ".join(files)): True}