public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-keys:master commit in: gkeys/gkeys/
Date: Sun, 31 May 2015 05:03:18 +0000 (UTC)	[thread overview]
Message-ID: <1429552184.8afad8720eea5e69c9247fe207c9cd8e20a2a0e6.dolsen@gentoo> (raw)

commit:     8afad8720eea5e69c9247fe207c9cd8e20a2a0e6
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Jan  9 21:04:04 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Apr 20 17:49:44 2015 +0000
URL:        https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=8afad872

gkeys: remove-key refactoring

Update the remove-key action to use the proper installed db.
Populate the del_key, del_keydir functions in lib.py

 gkeys/gkeys/actions.py | 27 +++++++++++++--------------
 gkeys/gkeys/lib.py     | 35 +++++++++++++++++++++++++++++------
 2 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index cfe69ee..22d660f 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -25,7 +25,6 @@ else:
 
 from collections import defaultdict
 from json import load
-from shutil import rmtree
 
 from gkeys.lib import GkeysGPG
 from gkeys.seedhandler import SeedHandler
@@ -551,7 +550,7 @@ class Actions(object):
             keyresults = seeds.list(**kwargs)
         self.output('', '\n Removing keys...')
         success = True
-        print(keyresults)
+        #print(keyresults)
         for gkey in sorted(keyresults):
             if kwargs['nick'] != '*' and  kwargs['nick'] not in gkey.nick:
                 messages.append(_unicode("%s does not seem to be a valid key.")
@@ -569,22 +568,22 @@ class Actions(object):
                 if ans in ["no", "n"]:
                     messages.append("Key removal aborted... Nothing to be done.")
                 else:
-                    ## This next code is total crap  now
-                    ## re-write it from scratch
-                    ## there could be multiple keys installed in one keyring
-                    ## this code just rm's everything.
                     keyring = self.config.get_key('keyring')
                     catdir = os.path.join(keyring, args.category)
-                    rm_candidate = os.path.join(catdir, gkey.nick)
                     self.logger.debug(_unicode("ACTIONS: removekey; catdir = %s")
                         % catdir)
-                    if args.category:
-                        try:
-                            rmtree(rm_candidate)
-                            messages.append(_unicode("Done removing %s key.") % kwargs['nick'])
-                        except OSError:
-                            messages.append(_unicode("%s directory does not exist.") % rm_candidate)
-                            success = False
+                    self.gpg = GkeysGPG(self.config, catdir, self.logger)
+                    if len(gkey.keys) == 1 or args.keys == gkey.keys:
+                        success, msgs = self.gpg.del_keydir(gkey)
+                        messages.extend(msgs)
+                    elif args.keys:
+                        for key in args.keys:
+                            success, msgs = self.gpg.del_key(gkey, key)
+                            msgs.extend(msgs)
+                    else:
+                        for key in gkey.keys:
+                            success, msgs = self.gpg.del_key(gkey, key)
+                            msgs.extend(msgs)
         return (success, messages)
 
 

diff --git a/gkeys/gkeys/lib.py b/gkeys/gkeys/lib.py
index 9687c24..3eb267c 100644
--- a/gkeys/gkeys/lib.py
+++ b/gkeys/gkeys/lib.py
@@ -19,9 +19,10 @@ with gentoo-keys specific convienience functions.
 # for py 2.6 compatibility
 from __future__ import print_function
 
-
+import os
 from os.path import abspath, pardir
 from os.path import join as pjoin
+from shutil import rmtree
 
 from pyGPG.gpg import GPG
 from gkeys.checks import KeyChecks
@@ -165,18 +166,40 @@ class GkeysGPG(GPG):
         return results
 
 
-    def del_key(self, gkey, keydir):
-        '''Delete the specified key in the specified keydir
+    def del_key(self, gkey, key):
+        '''Delete the specified key
 
         @param gkey: GKEY namedtuple with (name, nick, keydir, fingerprint)
+        @param key: Fingerprint of the primary key to delete
         '''
-        return []
+        self.set_keydir(gkey.keydir, 'del-key', reset=True)
+        self.set_keyring('pubring.gpg', 'del-key', reset=False)
+        self.set_keyseedfile(refresh=True)
+        self.logger.debug("LIB: del_key, gkey: %s" % str(gkey))
+        self.logger.debug("LIB: del_key, key: %s" % key)
+        self.logger.debug("** Calling runGPG with: 'gpg %s --delete-keys' for: %s"
+            % (' '.join(self.config.get_key('tasks', 'delete-keys')), str(gkey)))
+        result = self.runGPG(task='delete-keys', inputfile=key)
+        self.logger.info('GPG return code: ' + str(result.returncode))
+        self.update_gkey(gkey, save=True)
+        return (False, [])
 
 
-    def del_keydir(self, keydir):
+    def del_keydir(self, gkey):
         '''Delete the specified keydir
+
+        @param gkey: GKEY namedtuple with (name, nick, keydir, fingerprint)
         '''
-        return []
+        rm_candidate = os.path.join(self.basedir, gkey.keydir)
+        success = False
+        messages = []
+        try:
+            rmtree(rm_candidate)
+            messages.append("Done removing %s key." % gkey.nick)
+            success = True
+        except OSError:
+            messages.append("%s directory does not exist or is a symbolic link." % rm_candidate)
+        return (success, messages)
 
 
     def refresh_key(self, gkey):


             reply	other threads:[~2015-05-31  5:03 UTC|newest]

Thread overview: 144+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-31  5:03 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-08-15 16:15 [gentoo-commits] proj/gentoo-keys:master commit in: gkeys/gkeys/ Brian Dolbec
2018-08-15  1:51 Brian Dolbec
2018-08-15  1:05 Brian Dolbec
2018-07-07 15:10 Brian Dolbec
2018-07-07 15:10 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2018-07-07  5:23 Brian Dolbec
2016-12-24  9:13 [gentoo-commits] proj/gentoo-keys:gsoc-2016 " Brian Dolbec
2016-12-24  0:38 ` [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
2016-12-24  9:13 [gentoo-commits] proj/gentoo-keys:gsoc-2016 " Brian Dolbec
2016-10-27 21:49 ` [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
2016-12-24  9:13 [gentoo-commits] proj/gentoo-keys:gsoc-2016 " Brian Dolbec
2016-12-24  0:38 ` [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
2016-12-24  9:13 [gentoo-commits] proj/gentoo-keys:gsoc-2016 " Brian Dolbec
2016-10-27 18:41 ` [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
2016-12-24  4:52 Brian Dolbec
2016-06-01 15:16 Brian Dolbec
2016-06-01 15:16 Brian Dolbec
2016-01-23 23:33 Brian Dolbec
2016-01-23 23:33 Brian Dolbec
2016-01-23 19:04 Brian Dolbec
2015-12-25 17:03 Brian Dolbec
2015-12-13  0:51 Brian Dolbec
2015-08-25 14:10 Brian Dolbec
2015-08-25 14:10 Brian Dolbec
2015-08-09 22:52 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-08-09  1:09 Brian Dolbec
2015-07-25 16:45 Brian Dolbec
2015-07-25 16:45 Brian Dolbec
2015-07-25 16:45 Brian Dolbec
2015-06-22 13:41 Brian Dolbec
2015-06-01  1:56 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-05-31  5:03 Brian Dolbec
2015-03-18 15:32 Brian Dolbec
2015-03-17 19:51 Brian Dolbec
2015-03-08 15:09 Brian Dolbec
2015-03-06 21:04 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-02-11 17:37 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-09 21:07 Brian Dolbec
2015-01-08  4:13 Brian Dolbec
2015-01-07 23:39 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-05 23:12 Brian Dolbec
2015-01-01 22:32 Brian Dolbec
2015-01-01 17:44 Brian Dolbec
2015-01-01 17:44 Brian Dolbec
2015-01-01 17:44 Brian Dolbec
2015-01-01 17:44 Brian Dolbec
2015-01-01 17:44 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-31 21:34 Brian Dolbec
2014-12-26 18:37 Brian Dolbec
2014-12-26 18:37 Brian Dolbec
2014-12-26 18:37 Brian Dolbec
2014-12-26  5:02 Brian Dolbec
2014-12-26  5:02 Brian Dolbec
2014-12-26  5:02 Brian Dolbec
2014-12-25 22:07 Brian Dolbec
2014-12-25 22:07 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-25 20:43 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-24 19:59 Brian Dolbec
2014-12-23  2:50 Brian Dolbec
2014-12-23  2:50 Brian Dolbec
2014-12-23  0:13 Brian Dolbec
2014-12-22 23:11 Brian Dolbec
2014-12-22 23:11 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429552184.8afad8720eea5e69c9247fe207c9cd8e20a2a0e6.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox