Initial stubbing out of a gentoo-keys gkey manager cli app, lib and config.
authorBrian Dolbec <dolsen@gentoo.org>
Mon, 3 Dec 2012 07:22:03 +0000 (23:22 -0800)
committerBrian Dolbec <dolsen@gentoo.org>
Mon, 3 Dec 2012 07:22:03 +0000 (23:22 -0800)
bin/gkeys [new file with mode: 0644]
etc/gentoo-keys.cfg [new file with mode: 0644]
gkeys/cli.py [new file with mode: 0644]
gkeys/config.py [new file with mode: 0644]
gkeys/lib.py [new file with mode: 0644]
gkeys/log.py [new file with mode: 0644]

diff --git a/bin/gkeys b/bin/gkeys
new file mode 100644 (file)
index 0000000..874d2c7
--- /dev/null
+++ b/bin/gkeys
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+'''Gentoo-keys is a gpg key manager for managing
+ gentoo's gpg-signing keys.  It is these keys that are
+ used to verify and validate release media, etc..
+
+ Distributed under the terms of the GNU General Public License v2
+
+ Copyright:
+             (c) 2011 Brian Dolbec
+             Distributed under the terms of the GNU General Public License v2
+
+ Author(s):
+             Brian Dolbec <dolsen@gentoo.org>
+
+'''
+
+from __future__ import print_function
+
+import os
+import sys
+# This block ensures that ^C interrupts are handled quietly.
+try:
+    import signal
+
+    def exithandler(signum,frame):
+        signal.signal(signal.SIGINT, signal.SIG_IGN)
+        signal.signal(signal.SIGTERM, signal.SIG_IGN)
+        print()
+        sys.exit(1)
+
+    signal.signal(signal.SIGINT, exithandler)
+    signal.signal(signal.SIGTERM, exithandler)
+    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+except KeyboardInterrupt:
+    print()
+    sys.exit(1)
+
+
+from gentoo-keys.cli import Main
+
+root = None
+try:
+    root = os.environ['ROOT']
+except KeyError:
+    pass
+
+main = Main(root=root)
+main()
diff --git a/etc/gentoo-keys.cfg b/etc/gentoo-keys.cfg
new file mode 100644 (file)
index 0000000..6aaee82
--- /dev/null
@@ -0,0 +1,19 @@
+# Gentoo-keys configuration file
+#
+
+[MAIN]
+
+# keysdir: base directory to store the binary keyrings and data
+keysdir: /home/brian/gpg-test
+
+# devkeydir: the directory where the gentoo developer keys
+# will be stored.
+devkeydir: %(keysdir)s/devs
+
+# releaskeydir: the directory where the official release media keys
+# will be stored.
+releasekeydir: %(keysdir)s/release
+
+# knownkeysfile: txt file to hold a cache of the
+# installed (name, keyid, fingerprint) keys
+knownkeysfile:  %(keysdir)s/knownkeys
diff --git a/gkeys/cli.py b/gkeys/cli.py
new file mode 100644 (file)
index 0000000..4da662c
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+"""
+    Gentoo-keys - cli.py
+
+    Command line interface module
+
+    @copyright: 2012 by Brian Dolbec <dol-sen@gentoo.org>
+    @license: GNU GPL2, see COPYING for details.
+"""
+
+from gentookeys.log import logger
+
+class Main(object):
+    '''Main command line interface class'''
+
+    def __init__(self, root=None):
+        """ Main class init function.
+
+        @param root: string, root path to use
+        """
+        self.root = root or "/"
+
+    def __call__(self):
+        logger.debug("CLI.__call__(): self.config.keys()"
+            " %s", str(self.config.keys()))
+        pass
+
diff --git a/gkeys/config.py b/gkeys/config.py
new file mode 100644 (file)
index 0000000..1f6610c
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+"""
+    Gentoo-keys - config.py
+
+    Holds configuration keys and values
+
+    @copyright: 2012 by Brian Dolbec <dol-sen@gentoo.org>
+    @license: GNU GNU GPL2, see COPYING for details.
+"""
+
+
+import ConfigParser
+from collections import namedtuple
+
+
+from pygpg.config import GPGConfig
+
+from gkeys.utils import path
+
+
+# establish the eprefix, initially set so eprefixify can
+# set it on install
+EPREFIX = "@GENTOO_PORTAGE_EPREFIX@"
+
+# check and set it if it wasn't
+if "GENTOO_PORTAGE_EPREFIX" in EPREFIX:
+    EPREFIX = ''
+
+
+
+class GKeysConfig(GPGConfig):
+    """ Configuration superclass which holds our gentoo-keys
+    config settings for pygpg """
+
+    def __init__ (self, config=None, root=None):
+        """ Class initialiser """
+        GPGConfig.__init__(self)
+
+        self.root = root or ''
+        if config:
+            self.defaults['config'] = config
+            self.defaults['configdir'] = os.path.dirname(config)
+        else
+            self.defaults['configdir'] = path([self.root, EPREFIX, '/etc/gentoo-keys'])
+            self.defaults['config'] = '%(configdir)s/gkeys.conf'
+        self.configparser = None
+
+        # read our config file overrides
+        self.read_config()
+
+
+    def _add_gkey_defaults(self):
+        self.defaults['keysdir'] = path([self.root, EPREFIX, '/var/gentoo/gkeys'])
+        self.defaults['devkeydir'] = '%(keysdir)s/devs'
+        self.defaults['releasekeydir'] = '%(keysdir)s/release')
+        self.defaults['knownkeysfile'] = '%(keysdir)s/knownkeys'
+
+
+
+    def read_config(self):
+        '''Reads the config file into memory
+        '''
+        if "%(configdir)s" in self.defaults['config']:
+            # fix the config path
+            self.defaults['config'] = self.defaults['config'] \
+                % {'configdir': self.defaults['configdir']}
+        defaults = self.get_defaults()
+        self.configparser = ConfigParser.ConfigParser(defaults)
+        self.configparser.add_section('MAIN')
+        self.configparser.read(defaults['config'])
+
+    def _get_(self, key):
+        if self.configparser and self.configparser.has_option('MAIN', key):
+            return self.configparser.get('MAIN', key)
+        else:
+            super('GKeysConfig', self)._get_(key)
+
+
+class GKEY(namedtuple('GKEY', ['name', 'keyid', 'longkeyid',
+    'fingerprint', 'keyring']):
+    '''Class to hold the relavent info about a key'''
+
+
diff --git a/gkeys/lib.py b/gkeys/lib.py
new file mode 100644 (file)
index 0000000..cc95fca
--- /dev/null
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+'''Gentoo-keys - lib.py
+This is gentoo-keys superclass which wraps the pyGPG lib
+with gentoo-keys specific convienience functions.
+
+ Distributed under the terms of the GNU General Public License v2
+
+ Copyright:
+             (c) 2011 Brian Dolbec
+             Distributed under the terms of the GNU General Public License v2
+
+ Author(s):
+             Brian Dolbec <dolsen@gentoo.org>
+
+'''
+
+
+from pygpg.gpg import GPG
+
+
+class GkeysGPG(GPG):
+    '''Gentoo-keys primary gpg class'''
+
+
+    def __init__(self, config):
+        '''class init function
+
+        @param config: GKeysConfig config instance to use
+        '''
+        GPG.__init__(self, config)
+        self.config = config
+
+
+    def add_key(self, gkey):
+        '''Add the specified key to the specified keyring
+
+        @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint)
+        '''
+        pass
+
+
+    def del_key(self, gkey, keyring):
+        '''Delete the specified key to the specified keyring
+
+        @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint)
+        '''
+        pass
+
+
+    def del_keyring(self, keyring):
+        '''Delete the specified key to the specified keyring
+        '''
+        pass
+
+
+    def update_key(self, gkey, keyring):
+        '''Update the specified key in the specified keyring
+
+        @param key: tuple of (name, keyid, fingerprint)
+        @param keyring: the keyring to add the key to
+        '''
+        pass
+
+
+    def list_keys(self, keyring=None):
+        '''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
+
+
+    def list_keyrings(self):
+        '''List all available keyrings
+        '''
+        pass
+
+
+    def verify_key(self, gkey):
+        '''verify the specified key from the specified keyring
+
+        @param gkey: GKEY namedtuple with (name, keyid/longkeyid, fingerprint)
+        '''
+        pass
+
+
+    def verify_text(self, text):
+        '''Verify a text block in memory
+        '''
+        pass
+
+
+    def verify_file(self, filepath):
+        '''Verify the file specified at filepath
+        '''
+        pass
+
+
+    def
+
diff --git a/gkeys/log.py b/gkeys/log.py
new file mode 100644 (file)
index 0000000..a584f67
--- /dev/null
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+"""
+    Gentoo-Keys - Log.py
+
+    Logging module, placeholder for our site-wide logging module
+
+    @copyright: 2012 by Brian Dolbec <dol-sen> <dol-sen@users.sourceforge.net>
+    @license: GNU GPL2, see COPYING for details.
+"""
+
+import logging
+
+logging.basicConfig()
+
+logger = logging.getLogger('gentoo-keys')
+