commit: 18e4734f2181d8152e37cfbb1f2903ba6ce52f91 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Sun Jun 1 15:15:35 2014 +0000 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com> CommitDate: Sun Jun 1 15:21:36 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=18e4734f
GKEY: New pretty_print property Update cli.output_results to use the new property. --- gkeys/cli.py | 2 +- gkeys/config.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gkeys/cli.py b/gkeys/cli.py index 200ca87..dd1b45a 100644 --- a/gkeys/cli.py +++ b/gkeys/cli.py @@ -147,7 +147,7 @@ class Main(object): def output_results(results, header): # super simple output for the time being print(header) - print("\n".join([str(x) for x in results])) + print("\n".join([x.pretty_print for x in results])) print() diff --git a/gkeys/config.py b/gkeys/config.py index 161315e..e9537b0 100644 --- a/gkeys/config.py +++ b/gkeys/config.py @@ -40,6 +40,15 @@ if "GENTOO_PORTAGE_EPREFIX" in EPREFIX: SEED_TYPES = ['dev', 'release'] +GKEY_STRING = ''' ---------- + Name.........: %(name)s + Nick.........: %(nick)s + Keydir.......: %(keydir)s +''' +GKEY_FINGERPRINTS = \ +''' Keyid........: %(keyid)s + Fingerprint: %(fingerprint)s +''' class GKeysConfig(GPGConfig): """ Configuration superclass which holds our gentoo-keys @@ -126,3 +135,15 @@ class GKEY(namedtuple('GKEY', ['nick', 'name', 'keydir', 'fingerprint'])): def keyid(self): '''Keyid is a substring value of the fingerprint''' return ['0x' + x[-16:] for x in self.fingerprint] + + + @property + def pretty_print(self): + '''Pretty printing a GKEY''' + gkey = {'name': ', '.join(self.name), 'nick': ', '.join(self.nick) + , 'keydir': ', '.join(self.keydir)} + output = GKEY_STRING % gkey + for f in self.fingerprint: + fingerprint = {'fingerprint': f, 'keyid': '0x' + f[-16:]} + output += GKEY_FINGERPRINTS % fingerprint + return output