[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9822 - trunk/gnue-common/src/apps
From: |
johannes |
Subject: |
[gnue] r9822 - trunk/gnue-common/src/apps |
Date: |
Wed, 21 Nov 2007 04:43:02 -0600 (CST) |
Author: johannes
Date: 2007-11-21 04:43:02 -0600 (Wed, 21 Nov 2007)
New Revision: 9822
Modified:
trunk/gnue-common/src/apps/manpage.py
Log:
More work on PEP8
Modified: trunk/gnue-common/src/apps/manpage.py
===================================================================
--- trunk/gnue-common/src/apps/manpage.py 2007-11-21 09:49:23 UTC (rev
9821)
+++ trunk/gnue-common/src/apps/manpage.py 2007-11-21 10:43:02 UTC (rev
9822)
@@ -1,6 +1,9 @@
+# GNU Enterprise Common Library - Application Services - Manpage support
#
-# This file is part of GNU Enterprise.
+# Copyright 2001-2007 Free Software Foundation
#
+# This file is part of GNU Enterprise
+#
# GNU Enterprise is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
@@ -16,79 +19,58 @@
# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
-# Copyright 2000-2007 Free Software Foundation
-#
-# FILE:
-# selfdoc.py
-#
-# DESCRIPTION:
+# $Id$
"""
Tool self-documenting base class
"""
-# NOTES:
-#
-import time, string
-from gnue.common.utils.TextUtils import lineWrap
+import time
+import textwrap
+import StringIO
+__all__ = ['ManPage']
+# =============================================================================
+# Class for building manpages for GNUe based applications
+# =============================================================================
+
class ManPage:
"""
Create a man page for this utility.
"""
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
def __init__(self, app, dest, format=None, options={}):
+ self.__format = format
+ self.__options = options
+
year = time.strftime("%Y", time.localtime(time.time()))
- COMMAND = string.replace(app.COMMAND,'-','\-')
+ COMMAND = app.COMMAND.replace('-', '\-')
- #
- # HEADER + NAME Sections
- #
-# dest.write ("""\
-# .ig
-# Copyright (C) 2000-%s Free Software Foundation, Inc.
-#
-# Permission is granted to make and distribute verbatim copies of
-# this manual provided the copyright notice and this permission notice
-# are preserved on all copies.
-#
-# Permission is granted to copy and distribute modified versions of this
-# manual under the conditions for verbatim copying, provided that the
-# entire resulting derived work is distributed under the terms of a
-# permission notice identical to this one.
-#
-# Permission is granted to copy and distribute translations of this
-# manual into another language, under the above conditions for modified
-# versions, except that this permission notice may be included in
-# translations approved by the Free Software Foundation instead of in
-# the original English.
-# ..
-# """ % year)
-
dest.write('.TH %s 1 "%s" "%s"\n' % (
- string.upper(COMMAND),
- time.strftime("%d %B %Y",
- time.localtime(time.time())),
+ COMMAND.upper(),
+ time.strftime("%d %B %Y", time.localtime(time.time())),
app.NAME))
+
dest.write('.SH NAME\n')
- dest.write('%s \- %s\n' % (COMMAND,
- string.replace(app.NAME,'-','\-')))
+ dest.write('%s \- %s\n' % (COMMAND, app.NAME.replace('-', '\-')))
-
- #
# SYNOPSIS Section
- #
dest.write('.SH SYNOPSIS\n')
+
# dest.write('.ll +8\n')
dest.write('.B %s\n' % COMMAND)
- for p in string.split(app.USAGE):
- part = p
+ for part in app.USAGE.split():
if part[0] == '[' and part[-1] == ']':
pre = '[\n.I '
post = '\n]'
part = part[1:-1]
+
else:
pre = '.I '
post = ''
@@ -96,89 +78,88 @@
if part == '...':
part = '\&...'
- if string.find(part,'=') > 0:
- first, last = string.split(part,'=',2)
- part = string.replace(part,
- '=','\n=\n.I ',1)
+ if part.find('=') > 0:
+ part = part.replace('=', '\n=\n.I ', 1)
dest.write('%s%s%s\n' % (pre, part, post))
- #
# DESCRIPTION Section
- #
dest.write('.SH DESCRIPTION\n')
- dest.write(lineWrap(string.replace(app.SUMMARY,'-','\-'),70) + '\n')
+ text = textwrap.wrap(app.SUMMARY.replace('-', '\-'), 70)
+ dest.write('\n'.join(text) + '\n')
-
- #
# OPTIONS Section
- #
dest.write('.SH OPTIONS\n')
allOptions = {}
devOptions = {}
descriptors = {}
+
for optionset in [app._base_options, app.COMMAND_OPTIONS]:
for option in optionset:
if option.category == 'dev':
- devOptions[string.upper(option.longOption)] = option
+ devOptions[option.longOption.upper()] = option
else:
- allOptions[string.upper(option.longOption)] = option
+ allOptions[option.longOption.upper()] = option
if option.acceptsArgument:
- descr = '.B \-\-%s <%s>' % (option.longOption,
option.argumentName or u_("value"))
+ descr = '.B \-\-%s <%s>' % (option.longOption, \
+ option.argumentName or u_("value"))
else:
descr = '.B \-\-%s' % (option.longOption)
+
if option.shortOption:
descr += ', \-%s' % option.shortOption
- descriptors[string.upper(option.longOption)] = descr
+ descriptors[option.longOption.upper()] = descr
- for optionSet, descr in (
- (allOptions,'GENERAL OPTIONS'),
- (devOptions,'DEVELOPER OPTIONS') ):
+ for optionset, descr in (
+ (allOptions, 'GENERAL OPTIONS'),
+ (devOptions, 'DEVELOPER OPTIONS') ):
- sorted = optionSet.keys()
- sorted.sort()
+ sopts = optionset.keys()
+ sopts.sort()
- dest.write(".TP\n.B %s\n.TP\n" %descr)
+ dest.write(".TP\n.B %s\n.TP\n" % descr)
- for optionKey in sorted:
- dest.write(".TP\n%s\n" % (descriptors[optionKey]))
- dest.write(string.replace(string.replace(
- lineWrap(
- string.replace(optionSet[optionKey].help,'-','\-'),70),
- "\n.", "\n\\."), "\n'", "\n\\'"))
+ for optionkey in sopts:
+ dest.write(".TP\n%s\n" % (descriptors[optionkey]))
+ text = optionset[optionkey].help.replace('-', '\-')
+ text = '\n'.join(textwrap.wrap(text, 70)) + '\n'
+ text = text.replace("\n.", "\n\\.").replace("\n'", "\n\\'")
- #
+ if isinstance(dest, StringIO.StringIO):
+ dest.write(text)
+ else:
+ dest.write(o(text))
+
# AUTHOR, BUGS, and COPYRIGHT sections
- #
- dest.write("""\
- .SH AUTHOR
- %(AUTHOR)s <%(EMAIL)s>
- .SH BUGS
- %(BUGS)s
- Include a complete, self-contained example
- that will allow the bug to be reproduced,
- and say which version of this tool you are using.
- .SH COPYRIGHT
- Copyright \(co 2000-%(YEAR)s Free Software Foundation, Inc.
- .LP
- %(COMMAND)s is free software; you can redistribute it and/or modify it
under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
- .LP
- %(COMMAND)s is distributed in the hope that it will be useful, but WITHOUT
ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
- .LP
- You should have received a copy of the GNU General Public License along
- with %(COMMAND)s; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ dest.write("""
+.SH AUTHOR
+%(AUTHOR)s <%(EMAIL)s>
+.SH BUGS
+%(BUGS)s
+Include a complete, self-contained example
+that will allow the bug to be reproduced,
+and say which version of this tool you are using.
+.SH COPYRIGHT
+Copyright \(co 2000-%(YEAR)s Free Software Foundation, Inc.
+.LP
+%(COMMAND)s is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+.LP
+%(COMMAND)s is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+.LP
+You should have received a copy of the GNU General Public License along
+with %(COMMAND)s; see the file COPYING. If not, write to the Free Software
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" % {'COMMAND': COMMAND,
'YEAR': year,
'BUGS': app.REPORT_BUGS_TO,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9822 - trunk/gnue-common/src/apps,
johannes <=