commit:     7bfa40a4b350767ec8e8d2812620bb8be6ce48a4
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jan  6 20:20:30 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Jan  6 21:19:39 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=7bfa40a4

gkeys-gen: Setup.py updates for man page generation

---
 gkeys-gen/gkeygen/__init__.py | 20 +++++++++++
 gkeys-gen/setup.py            | 80 ++++++++++++++++++++++++++++++++++++++++---
 gkeys/setup.py                | 76 ++++++++++++++++++++++++++++++++++++++--
 3 files changed, 168 insertions(+), 8 deletions(-)

diff --git a/gkeys-gen/gkeygen/__init__.py b/gkeys-gen/gkeygen/__init__.py
index 7e8b64e..495f798 100644
--- a/gkeys-gen/gkeygen/__init__.py
+++ b/gkeys-gen/gkeygen/__init__.py
@@ -1,5 +1,25 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
+from collections import OrderedDict
+
+from gkeygen.actions import Action_Map, Available_Actions
+
+
 __version__ = 'Git'
 __license__ = 'GPLv2'
+
+
+subdata = OrderedDict()
+for cmd in Available_Actions:
+    subdata[cmd] = Action_Map[cmd]['desc']
+
+Gkeys_Map = {
+    'options': ['help', 'config', 'debug'],
+    'desc': 'OpenPGP/GPG key generator tool',
+    'long_desc': '''Gentoo Keys (gkeys) is a Python based project that aims to 
manage
+the GPG keys used for validation on users and Gentoo's infrastracutre servers.
+Gkeys-gen is a tool for generating OpnPGP/GPG keys according to a selected 
spec.''',
+    'sub-cmds': subdata,
+    'authors': ['Brian Dolbec <dol...@gentoo.org>', 'Pavlos Ratis 
<daster...@gentoo.org>'],
+}

diff --git a/gkeys-gen/setup.py b/gkeys-gen/setup.py
index 063bff1..fc93bf0 100755
--- a/gkeys-gen/setup.py
+++ b/gkeys-gen/setup.py
@@ -1,11 +1,26 @@
 #!/usr/bin/env python
 
+
+import collections
 import os
 import sys
 
-from distutils.core import setup
+from distutils.core import setup, Command
+from distutils.command.build import build
+
 from gkeygen import __version__, __license__
 
+from gkeygen import Gkeys_Map
+from gkeygen.actions import Action_Map, Available_Actions
+
+try:
+    from py2man import manpages
+except ImportError:
+    print('creating py2man symlink')
+    os.symlink('../py2man', 'py2man')
+    from py2man import manpages
+
+
 # this affects the names of all the directories we do stuff with
 sys.path.insert(0, './')
 
@@ -18,10 +33,61 @@ except ImportError:
     EPREFIX=''
 
 
+class x_build(build):
+    """ Build command with extra build_man call. """
+
+    def run(self):
+        build.run(self)
+        self.run_command('build_man')
+
+
+class build_man(Command):
+    """ Perform substitutions in manpages. """
+
+    user_options = [
+    ]
+
+    def initialize_options(self):
+        self.build_base = None
+
+    def finalize_options(self):
+        self.set_undefined_options('build',
+            ('build_base', 'build_base'))
+
+    def run(self):
+        # create the main page
+        basepath = os.path.dirname(__file__)
+        docpath = os.path.join(basepath, 'doc')
+        templatepath = os.path.dirname(manpages.__file__)
+        man = manpages.ManPage('gkey-gen', __version__, None,
+            docpath, Gkeys_Map['authors'])
+        man.read_template(templatepath, 'command.template')
+        man.make_prog(Gkeys_Map)
+        man.read_template(templatepath, 'sub-command.template')
+        man.make_subpages(Action_Map, Available_Actions)
+
+
+def get_manpages():
+    linguas = os.environ.get('LINGUAS')
+    if linguas is not None:
+        linguas = linguas.split()
+
+    for dirpath, dirnames, filenames in os.walk('doc'):
+        groups = collections.defaultdict(list)
+        for f in filenames:
+            fn, suffix = f.rsplit('.', 1)
+            groups[suffix].append(os.path.join(dirpath, f))
+
+        topdir = dirpath[len('doc/'):]
+        if not topdir or linguas is None or topdir in linguas:
+            for g, mans in groups.items():
+                yield [os.path.join('$mandir', topdir, 'man%s' % g), mans]
+
+
 setup(
-    name='gkeygen',
+    name='gkeys-gen',
     version=__version__,
-    description="Gentoo gpg key management key generator",
+    description="OpenPGP/GPG key generator",
     author='',
     author_email='',
     maintainer='Gentoo-Keys Team',
@@ -30,12 +96,16 @@ setup(
     download_url='',
     packages=['gkeygen'],
     scripts=['bin/gkey-gen'],
-    data_files=(
+    data_files=list(get_manpages()) + [
         (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'etc/gkeys/'), 
['etc/gkeys-gen.conf']),
-        ),
+        ],
     license=__license__,
     long_description=open('README.md').read(),
     keywords='gpg',
+    cmdclass = {
+        'build': x_build,
+        'build_man': build_man,
+        },
     classifiers=[
         'Development Status :: 3 - Alpha',
         'Intended Audience :: Developers, Users',

diff --git a/gkeys/setup.py b/gkeys/setup.py
index 23af045..d6b38af 100755
--- a/gkeys/setup.py
+++ b/gkeys/setup.py
@@ -1,11 +1,26 @@
 #!/usr/bin/env python
 
+
+import collections
 import os
 import sys
 
-from distutils.core import setup
+from distutils.core import setup, Command
+from distutils.command.build import build
+
 from gkeys import __version__, __license__
 
+from gkeys import Gkeys_Map
+from gkeys.action_map import Action_Map, Available_Actions
+
+try:
+    from py2man import manpages
+except ImportError:
+    print('creating py2man symlink')
+    os.symlink('../py2man', 'py2man')
+    from py2man import manpages
+
+
 # this affects the names of all the directories we do stuff with
 sys.path.insert(0, './')
 
@@ -18,6 +33,57 @@ except ImportError:
     EPREFIX=''
 
 
+class x_build(build):
+    """ Build command with extra build_man call. """
+
+    def run(self):
+        build.run(self)
+        self.run_command('build_man')
+
+
+class build_man(Command):
+    """ Perform substitutions in manpages. """
+
+    user_options = [
+    ]
+
+    def initialize_options(self):
+        self.build_base = None
+
+    def finalize_options(self):
+        self.set_undefined_options('build',
+            ('build_base', 'build_base'))
+
+    def run(self):
+        # create the main page
+        basepath = os.path.dirname(__file__)
+        docpath = os.path.join(basepath, 'doc')
+        templatepath = os.path.dirname(manpages.__file__)
+        man = manpages.ManPage('gkeys', __version__, None,
+            docpath, Gkeys_Map['authors'])
+        man.read_template(templatepath, 'command.template')
+        man.make_prog(Gkeys_Map)
+        man.read_template(templatepath, 'sub-command.template')
+        man.make_subpages(Action_Map, Available_Actions)
+
+
+def get_manpages():
+    linguas = os.environ.get('LINGUAS')
+    if linguas is not None:
+        linguas = linguas.split()
+
+    for dirpath, dirnames, filenames in os.walk('doc'):
+        groups = collections.defaultdict(list)
+        for f in filenames:
+            fn, suffix = f.rsplit('.', 1)
+            groups[suffix].append(os.path.join(dirpath, f))
+
+        topdir = dirpath[len('doc/'):]
+        if not topdir or linguas is None or topdir in linguas:
+            for g, mans in groups.items():
+                yield [os.path.join('$mandir', topdir, 'man%s' % g), mans]
+
+
 setup(
     name='gkeys',
     version=__version__,
@@ -30,13 +96,17 @@ setup(
     download_url='',
     packages=['gkeys'],
     scripts=['bin/gkeys'],
-    data_files=(
+    data_files=list(get_manpages()) + [
         (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'etc/gkeys/'), 
['etc/gkeys.conf']),
         (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'etc/gkeys/'), 
['etc/gkeys.conf.sample']),
-        ),
+        ],
     license=__license__,
     long_description=open('README.md').read(),
     keywords='gpg',
+    cmdclass = {
+        'build': x_build,
+        'build_man': build_man,
+        },
     classifiers=[
         'Development Status :: 3 - Alpha',
         'Intended Audience :: Developers, Users',

Reply via email to