[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5596 - in trunk: gnue-common/src/apps gnue-common/utils gnue-forms gnue
From: |
jcater |
Subject: |
r5596 - in trunk: gnue-common/src/apps gnue-common/utils gnue-forms gnue-forms/src gnue-pointofsale/src |
Date: |
Wed, 31 Mar 2004 15:37:39 -0600 (CST) |
Author: jcater
Date: 2004-03-31 15:37:38 -0600 (Wed, 31 Mar 2004)
New Revision: 5596
Added:
trunk/gnue-common/src/apps/CommandOption.py
trunk/gnue-common/src/apps/manpage.py
Modified:
trunk/gnue-common/src/apps/GBaseApp.py
trunk/gnue-common/src/apps/GConfig.py
trunk/gnue-common/src/apps/GDebug.py
trunk/gnue-common/utils/update-tool-docs
trunk/gnue-forms/setup.py
trunk/gnue-forms/src/GFClient.py
trunk/gnue-pointofsale/src/POSClient.py
Log:
Changed command line option support a little:
* Instead of a list, a CommandOption class was added (old-style lists still
work, though.)
* Commands can be "classified", such as "dev"-related, etc
* "Dev" options (such as --profile and --interactive-debugger) are no longer
listed on main --help page.
* --help-dev was added, which shows only "dev" options
* --configuration-options was renamed to --help-config
* Started on --help-connections, which would show all available dbdrivers
* Changed --generate-man-page into a more generic --selfdoc manpage . There
are also --selfdoc-format, --selfdoc-file, and --selfdoc-options, so each tool
can support their own selfdoc methods (just catch the GBaseApp.selfdoc() call.)
* Moved the manpage generation code out of GBaseApp and into its own file.
* Manpages group options according to target audience.
Added: trunk/gnue-common/src/apps/CommandOption.py
===================================================================
--- trunk/gnue-common/src/apps/CommandOption.py 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-common/src/apps/CommandOption.py 2004-03-31 21:37:38 UTC (rev
5596)
@@ -0,0 +1,46 @@
+#
+# 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
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise 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.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# GBaseApp.py
+#
+# DESCRIPTION:
+"""
+Class that provides a basis for GNUe applications.
+
+Typically, this class will not be called; rather, a tool will
+be a GClientApp or GServerApp.
+"""
+
+
+class CommandOption:
+ def __init__(self, name, shortOption=None, longOption=None,
+ acceptsArgument=False, default=None, argumentName=None,
+ help="", category="general"):
+
+ self.name = name
+ self.shortOption = shortOption
+ self.longOption = longOption or name.replace('_','-')
+ self.acceptsArgument=acceptsArgument
+ self.default = default
+ self.argumentName = argumentName
+ self.help = help
+ self.category = category
+
Modified: trunk/gnue-common/src/apps/GBaseApp.py
===================================================================
--- trunk/gnue-common/src/apps/GBaseApp.py 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-common/src/apps/GBaseApp.py 2004-03-31 21:37:38 UTC (rev
5596)
@@ -29,10 +29,7 @@
be a GClientApp or GServerApp.
"""
-import getopt
-import sys
-import string
-import os
+import sys, os, getopt, string, types
import ConfigParser
from gnue import paths
@@ -40,7 +37,7 @@
from gnue.common.apps import GConfig
from gnue.common.apps import GDebug
from gnue.common.datasources import GConnections
-from gnue.common.utils.TextUtils import lineWrap
+from CommandOption import CommandOption
class GBaseApp:
"""
@@ -61,6 +58,7 @@
USAGE = "[options]"
USE_CONNECTIONS = 1 # Set to 1 if the program uses dbdrivers
USE_DATABASE_OPTIONS = 0 # Also implies USE_CONNECTIONS = 1
+ USE_RPC_OPTIONS = 0
# More options, but won't be changed unless
@@ -81,74 +79,121 @@
ARGUMENTS = [] # Will contain an array of command line arguments
connections = None # Will contain a GConnection object
+ # Should contain a dict of all help-<foo> options (only the <foo> part)
+ # Values would look like: 'dev': self.printHelpDev
+ helpCategories = { }
def __init__(self, connections=None, application=None, defaults=None):
+ self.helpCategories.update({'dev': self.printHelpDev,
+ 'connections': self.printHelpConn,
+ 'rpc': self.printHelpRPC })
- # format of COMMAND_OPTIONS and _base_options:
- # [option, option] where option is:
- # [dictionary key name, short option, long option,
- # argument follows option?, default value,
- # argument name, help message]
+ # Basic options
self._base_options = [
- [ 'version',None,'version',False,0, None,
- _('Displays the version information for this program.') ],
- [ 'debug_level',None,'debug-level',True,0, "level",
- _('Enables debugging messages. Argument specifies the ') + \
- _('level of messages to display (e.g., "--debug-level 5" displays
') + \
- _('all debugging messages at level 5 or below.)') ],
- [ 'debug_file',None,'debug-file',True,None, "file",
- _('Sends all debugging messages to a specified file ') + \
- _('(e.g., "--debug-file trace.log" sends all output to
"trace.log")') ],
- [ 'help', None, 'help', False, None, None,
- _('Displays this help screen.') ],
- [ 'configuration_options', None, 'configuration-options', False,
None, None,
- _('Displays a list of valid configuration file entries, their
purpose, and their default values.') ],
- [ 'man_page', None, 'generate-man-page', False, None, None,
- _('Generates a groff-formatted man page as a file in the current
directory.') ],
- [ 'profile', None, 'profile', False, None, None,
- _("Run Python's built-in profiler and display the resulting ") + \
- _("run statistics.") ],
- [ 'debugger', None, 'interactive-debugger', False, None, None,
- _("Run the app inside Python's built-in debugger ")],
+
+ ##
+ ## Base options
+ ##
+
+ CommandOption('version', category="base",
+ help=_('Displays the version information for this program.') ),
+
+ CommandOption('debug-level', category="base", default=0,
+ acceptsArgument=True, argumentName=_("level"),
+ help=_('Enables debugging messages. Argument specifies the '
+ 'level of messages to display (e.g., "--debug-level 5"
displays '
+ 'all debugging messages at level 5 or below.)') ),
+
+ CommandOption('debug-file', category="base",
+ acceptsArgument=True, argumentName=_("filename"),
+ help=_('Sends all debugging messages to a specified file '
+ '(e.g., "--debug-file trace.log" sends all output to
"trace.log")') ),
+
+ CommandOption('help', category="base",
+ help=_('Displays this help screen.') ),
+
+ CommandOption('help-config', category="base",
+ help=_('Displays a list of valid configuration file entries,
their '
+ 'purpose, and their default values.') ),
+
+ ##
+ ## Developer options
+ ##
+
+ CommandOption('help-dev', category="base",
+ help=_('Display all options of interest to core developers. ') ),
+
+ CommandOption('selfdoc', category="dev",
+ acceptsArgument=True, argumentName=_("type[,subtype]"),
+ help=_('Generates self-documentation.') ),
+
+ CommandOption('selfdoc-format', category="dev",
+ acceptsArgument=True, argumentName=_("format"),
+ help=_('Format to output the self-documentation in. Supported
formats '
+ 'are dependent on the type of selfdoc being created.') ),
+
+ CommandOption('selfdoc-file', category="dev",
+ acceptsArgument=True, argumentName=_("filename"),
+ help=_('Specifies the filename that selfdoc should write to. If
not provided, output is sent to stdout.') ),
+
+ CommandOption('selfdoc-options', category="dev",
+ acceptsArgument=True, argumentName=_("options"),
+ help=_('Options specific to individual selfdoc types.') ),
+
+ CommandOption('profile', category="dev",
+ help=_("Run Python's built-in profiler and display the resulting
"
+ "run statistics.") ),
+
+ CommandOption('interactive-debugger', category="dev",
+ help=_("Run the app inside Python's built-in debugger ")),
]
if self.USE_DATABASE_OPTIONS:
self.USE_CONNECTIONS = 1
self._base_options += [
- [ 'username', None, 'username', True, '', 'name',
- _('Username used to log into the database. Note that if '
- 'specified, this will be used for all databases. If not '
- 'supplied, the program will prompt for username.')],
- [ 'password', None, 'password', True, '', 'passwd',
- _('Password used to log into the database. Note that if '
- 'specified, this will be used for all databases. If not '
- 'supplied, the program will prompt for password if needed.'
- '\nNOTE: SUPPLYING A PASSWORD VIA THE COMMAND LINE MAY BE '
- 'CONSIDERED A SECURITY RISK AND IS NOT RECOMMENDED.)') ]
+
+ CommandOption('username', category="connections", default='',
+ acceptsArgument=True, argumentName='name',
+ help=_('Username used to log into the database. Note that if '
+ 'specified, this will be used for all databases. If not '
+ 'supplied, the program will prompt for username.') ),
+
+ CommandOption('password', category="connections", default='',
+ acceptsArgument=True, argumentName='passwd',
+ help=_('Password used to log into the database. Note that if '
+ 'specified, this will be used for all databases. If not '
+ 'supplied, the program will prompt for password if
needed.'
+ '\nNOTE: SUPPLYING A PASSWORD VIA THE COMMAND LINE MAY BE
'
+ 'CONSIDERED A SECURITY RISK AND IS NOT RECOMMENDED.)') )
]
if self.USE_CONNECTIONS:
self._base_options += [
- [ 'connections', None, 'connections', True, None, "loc",
- _('Specifies the location of the connection definition file. ') + \
- _('<loc> may specify a file name ') + \
- '(/usr/local/gnue/etc/connections.conf),' + \
- _('or a URL location ') + \
- '(http://localhost/connections.conf).' + \
- _('If this option is not specified, the environent variable ') + \
- _('GNUE_CONNECTIONS is checked.') + \
- _('If neither of them is set, "%s" is used as a default.') %
- os.path.join (paths.config, "connections.conf")] ]
+ CommandOption('help-connections', category="base",
+ help=_('Display help information related to database '
+ 'connections, including a list of available drivers.') ),
+ CommandOption('connections', category="connections",
+ acceptsArgument=True, argumentName="loc",
+ help=_('Specifies the location of the connection definition
file. '
+ '<loc> may specify a file name '
+ '(/usr/local/gnue/etc/connections.conf),'
+ 'or a URL location '
+ '(http://localhost/connections.conf).'
+ 'If this option is not specified, the environent variable
'
+ 'GNUE_CONNECTIONS is checked.'
+ 'If neither of them is set, "%s" is used as a default.') %
+ os.path.join (paths.config, "connections.conf")) ]
+
# Python version check
try:
- if sys.hexversion < 0x02000000:
- self.handleStartupError (_('This application requires Python 2.0 or
greater. You are running Python %s') % sys.version[:5])
+ if sys.hexversion < 0x02010000:
+ self.handleStartupError (_('This application requires Python 2.1 or
greater. You are running Python %s') % sys.version[:5])
except AttributeError:
# Really, really old version of Python...
- self.handleStartupError (_('This application requires Python 2.0 or
greater.'))
+ self.handleStartupError (_('This application requires Python 2.1 or
greater.'))
#
@@ -158,15 +203,22 @@
longoptions = []
lookup = {}
+ # Convert old-style options to new-style
+ if self.COMMAND_OPTIONS and type(self.COMMAND_OPTIONS[0]) ==
types.ListType:
+ options=self.COMMAND_OPTIONS
+ self.COMMAND_OPTIONS = []
+ for option in options:
+ self.COMMAND_OPTIONS.append(CommandOption(*option))
+
for optionset in [self._base_options, self.COMMAND_OPTIONS]:
for option in optionset:
- self.OPTIONS[option[0]] = option[4]
- if option[1] != None:
- shortoptions += option[1]
- lookup["-" + option[1]] = option[0]
- lookup["--" + option[2]] = option[0]
- lo = option[2]
- if option[3]:
+ self.OPTIONS[option.name] = option.default
+ if option.shortOption:
+ shortoptions += option.shortOption
+ lookup["-" + option.shortOption] = option.name
+ lookup["--" + option.longOption] = option.name
+ lo = option.longOption
+ if option.acceptsArgument:
lo += '='
shortoptions += ':'
longoptions.append(lo)
@@ -191,16 +243,37 @@
else:
self.OPTIONS[lookup[o[0]]] = 1
+ # Process any help-<foo> requests
+ for task in self.helpCategories.keys():
+ if self.OPTIONS.get('help-%s'%task,0):
+ self.helpCategories[task]()
+ sys.exit()
+
if self.OPTIONS['help']:
self.printHelp()
sys.exit()
elif self.OPTIONS['version']:
self.printVersion()
sys.exit()
- elif self.OPTIONS['man_page']:
- self.dumpManPage()
+ elif self.OPTIONS['selfdoc']:
+ if self.OPTIONS['selfdoc-file']:
+ doprint = False
+ handle = open(self.OPTIONS['selfdoc-file'],'w')
+ else:
+ doprint = True
+ import StringIO
+ handle = StringIO.StringIO
+
+ self.selfdoc(self.OPTIONS['selfdoc'], handle,
+ self.OPTIONS['selfdoc-format'],
+ self.OPTIONS['selfdoc-options'])
+ if doprint:
+ handle.seek(0)
+ print handle.read()
+ handle.close()
sys.exit()
- elif self.OPTIONS['configuration_options']:
+
+ elif self.OPTIONS['help-config']:
print GConfig.printableConfigOptions(defaults)
sys.exit()
@@ -212,12 +285,12 @@
# Setup debugging
# Should we run in debugger?
- elif self.OPTIONS['debugger']:
+ elif self.OPTIONS['interactive-debugger']:
self.run = self._debugger
try:
- GDebug.setDebug(int("%s" % self.OPTIONS['debug_level']),
- self.OPTIONS['debug_file'])
+ GDebug.setDebug(int("%s" % self.OPTIONS['debug-level']),
+ self.OPTIONS['debug-file'])
except ValueError:
self.handleStartupError(_('The debug_level option ("-d") expects a
numerical value.'))
@@ -235,10 +308,10 @@
self.handleStartupError(_('The gnue.conf file is incomplete: ')\
+ '\n %s' % msg)
except Exception, msg:
- type=string.splitfields(str(sys.exc_type),'.')
- type.reverse()
+ etype=string.splitfields(str(sys.exc_type),'.')
+ etype.reverse()
self.handleStartupError( \
- _('%s while reading gnue.conf: ') % type[0] \
+ _('%s while reading gnue.conf: ') % etype[0] \
+ '\n %s' % msg)
# Add custom import to python's namespace
@@ -304,25 +377,33 @@
print _("GNUe Common Version %s\n") % commonVersion
#
- # Display help information for this program
+ # "Help" helpers
#
- def printHelp(self):
+ def buildHelpOptions(self, category=None):
allOptions = {}
descriptors = {}
maxLength = 0
for optionset in [self._base_options, self.COMMAND_OPTIONS]:
for option in optionset:
- allOptions[string.upper(option[2])] = option
- if option[5]:
- descr = '--%s <%s>' % (option[2], option[5])
+ # Limit this to the correct category. A category
+ # of None implies all options except "dev".
+ if not ( ( category is None and \
+ option.category != "dev" ) or \
+ ( category == option.category ) ):
+ continue
+
+ allOptions[string.upper(option.longOption)] = option
+
+ if option.acceptsArgument:
+ descr = '--%s <%s>' % (option.longOption, option.argumentName)
else:
- descr = '--%s' % (option[2])
- if option[1]:
- descr += ', -%s' % option[1]
+ descr = '--%s' % (option.longOption)
+ if option.shortOption:
+ descr += ', -%s' % option.shortOption
- descriptors[string.upper(option[2])] = descr
+ descriptors[string.upper(option.longOption)] = descr
if len(descr) > maxLength:
maxLength = len(descr)
@@ -347,175 +428,80 @@
dispOptions += "\n %s %s" % (descriptors[optionKey],
" " * (maxLength - len(descriptors[optionKey])))
- for word in string.split(allOptions[optionKey][6]):
+ for word in string.split(allOptions[optionKey].help):
if (len(word) + pos) > width:
pos = 0
- dispOptions = dispOptions + "\n" + " " * margin
+ dispOptions += "\n" + " " * margin
pos = pos + len(word) + 1
- dispOptions = dispOptions + word + " "
+ dispOptions += word + " "
- dispOptions = dispOptions + "\n"
+ dispOptions += "\n"
+ return dispOptions
+
+ def printHelpHeader(self):
self.printVersion()
- print _("Usage: %s %s\n\n%s\n\nAvailable command line options:\n%s") % \
- (self.COMMAND, self.USAGE, self.SUMMARY, dispOptions)
+ print _("Usage: ") + self.COMMAND + ' ' + self.USAGE
+ print
+
+ def printHelpFooter(self):
+ print
print "%s\n" % self.REPORT_BUGS_TO
-
#
- # Create a man page for this utility.
+ # Display help information for this program
#
- def dumpManPage(self):
- import time
- year = time.strftime("%Y", time.localtime(time.time()))
+ def printHelp(self):
+ self.printVersion()
+ print _("Usage: ") + self.COMMAND + ' ' + self.USAGE
+ print "\n" + self.SUMMARY + '\n'
+ print _('Available command line options:')
+ print self.buildHelpOptions()
+ self.printHelpFooter()
- dest = open("%s.1" % self.COMMAND,"w")
+ #
+ # Display dev help information for this program
+ #
+ def printHelpDev(self):
+ self.printHelpHeader()
+ print _("The following options are mainly of interest to GNUe
developers.\n"
+ "To view general help, run this command with the --help option.")
+ print
+ print _('Developer-specific command line options:')
+ print self.buildHelpOptions("dev")
+ self.printHelpFooter()
- COMMAND = string.replace(self.COMMAND,'-','\-')
+ def printHelpConn(self):
+ self.printHelpHeader()
+ print _("The following connection/database-related options are
available.\n"
+ "To view general help, run this command with the --help option.")
+ print
+ print _('Database/connection command line options:')
+ print self.buildHelpOptions("connections")
+ print
+ print _('The following database drivers are installed on your system:')
+ print " TODO\n"
+ # print self.connections.getAvailableDrivers()
+ self.printHelpFooter()
- #
- # HEADER + NAME Sections
- #
- dest.write ("""\
-.ig
-Copyright (C) 2000-%s Free Software Foundation, Inc.
+ def printHelpRPC(self):
+ self.printHelpHeader()
+ print _("The following options are mainly of interest to GNUe
developers.\n"
+ "To view general help, run this command with the --help option.")
+ print
+ print _('Developer-specific command line options:')
+ print self.buildHelpOptions()
+ self.printHelpFooter()
-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.
+ def selfdoc(self, command, handle, format=None, options={}):
+ if command == 'manpage':
+ import manpage
+ manpage.ManPage(self, handle, format, options)
-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())),
- self.NAME))
- dest.write('.SH NAME\n')
- dest.write('%s \- %s\n' % (COMMAND,
- string.replace(self.NAME,'-','\-')))
-
-
- #
- # SYNOPSIS Section
- #
- dest.write('.SH SYNOPSIS\n')
- dest.write('.ll +8\n')
- dest.write('.B %s\n' % COMMAND)
- for p in string.split(self.USAGE):
- part = p
- if part[0] == '[' and part[-1] == ']':
- pre = '[\n.I '
- post = '\n]'
- part = part[1:-1]
- else:
- pre = '.I '
- post = ''
-
- if part == '...':
- part = '\&...'
-
- if string.find(part,'=') > 0:
- first, last = string.split(part,'=',2)
- part = string.replace(part,
- '=','\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(self.SUMMARY,'-','\-'),70) + '\n')
-
-
- #
- # OPTIONS Section
- #
- dest.write('.SH OPTIONS\n')
-
- allOptions = {}
- descriptors = {}
- for optionset in [self._base_options, self.COMMAND_OPTIONS]:
- for option in optionset:
- allOptions[string.upper(option[2])] = option
-
- if option[5]:
- descr = '.B \-\-%s <%s>' % (option[2], option[5])
- else:
- descr = '.B \-\-%s' % (option[2])
- if option[1]:
- descr += ', \-%s' % option[1]
-
- descriptors[string.upper(option[2])] = descr
-
-
- sorted = allOptions.keys()
- sorted.sort()
-
- dispOptions = ""
-
- for optionKey in sorted:
- dest.write(".TP\n%s\n" % (descriptors[optionKey]))
- dest.write(string.replace(string.replace(
- lineWrap(
- string.replace(allOptions[optionKey][6],'-','\-'),70),
- "\n.", "\n\\."), "\n'", "\n\\'"))
-
- #
- # 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.
-""" % {'COMMAND': COMMAND,
- 'YEAR': year,
- 'BUGS': self.REPORT_BUGS_TO,
- 'AUTHOR': self.AUTHOR,
- 'EMAIL': self.EMAIL})
-
- #
- # Cleanup
- #
- dest.close()
- print "Man file create: %s.1" % self.COMMAND
-
#
# Converts a
#
Modified: trunk/gnue-common/src/apps/GConfig.py
===================================================================
--- trunk/gnue-common/src/apps/GConfig.py 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-common/src/apps/GConfig.py 2004-03-31 21:37:38 UTC (rev
5596)
@@ -61,12 +61,12 @@
__builtin__.__dict__[name] = alias.gConfig
- #
+ #
# loadApplicationConfig
#
# Loads the specified file only once.
# Subsequent calls setup the defaults for any missing values
- #
+ #
def loadApplicationConfig(self, configFilename="gnue.conf",
homeConfigDir=".gnue", section="DEFAULT", defaults = None):
GDebug.printMesg(1,'Reading configuration info from %s section %s' %
(configFilename, section))
@@ -78,7 +78,7 @@
parser = GConfigParser(defaults)
self._loadedConfigs[configFilename]=parser
-
+
# Build valid file list
fileLocations = []
etc_base = getInstalledBase('%s_etc' % section, 'common_etc')
@@ -97,7 +97,7 @@
if etc_base:
fileLocations.append(os.path.join(etc_base,configFilename+'.fixed'))
- #
+ #
# Load the values from the files specified
#
try:
@@ -113,7 +113,7 @@
raise InvalidFormatError, _('The file cannot be parsed.')
#
- # Common only needs checked once
+ # Common only needs checked once
#
# Load any [common] defaults
self._integrateDefaultDict(configFilename,'common',
@@ -166,7 +166,7 @@
def gConfigDict(self, configFilename=None, section=None):
if not configFilename: configFilename = self._defaultConfigFilename
if not section: section = self._defaultSection
-
+
options = {}
for option in self._loadedConfigs[configFilename].options(section):
options[option] =
self._loadedConfigs[configFilename].get(section,string.lower(option))
@@ -185,26 +185,26 @@
"""
Add support for our GTypecast systems to the generic ConfigParser
"""
- def __init__(self, defaults):
+ def __init__(self, defaults):
self.__defaults = defaults
ConfigParser.__init__(self)
typecasts = self.__typecasts = {}
# FIXME: I don't know what kind of elements are stored in 'defaults'.
# add a correct iteration over the "defaults-dictionary"!
if defaults and (len (defaults) > 0):
- for f in defaults:
- try:
+ for f in defaults:
+ try:
typecasts[f['Name'].lower()] = f['Typecast']
- except KeyError:
+ except KeyError:
typecasts[f['Name'].lower()] = str
-
- def get(self, section, field):
- try:
+
+ def get(self, section, field):
+ try:
val = ConfigParser.get(self, section, field)
return self.__typecasts[field.lower()](val)
- except KeyError:
+ except KeyError:
return val
- except ValueError:
+ except ValueError:
raise ValueError, _("Config option %s is of wrong type in [%s]") %
(field, section)
@@ -285,5 +285,5 @@
"common_appbase": paths.data,
"common_shared": os.path.join (paths.data, "share", "gnue")}
-
-
+
+
Modified: trunk/gnue-common/src/apps/GDebug.py
===================================================================
--- trunk/gnue-common/src/apps/GDebug.py 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-common/src/apps/GDebug.py 2004-03-31 21:37:38 UTC (rev
5596)
@@ -1,19 +1,19 @@
#
# 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
+# 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
# version 2, or (at your option) any later version.
#
-# GNU Enterprise 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
+# GNU Enterprise 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.
#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
# - Suite 330, Boston, MA 02111-1307, USA.
#
# Copyright 2000-2004 Free Software Foundation
@@ -59,21 +59,21 @@
def setDebugger(debugger):
global _DEBUGGER
_DEBUGGER = debugger
-
-def setDebug (level, file=None):
+
+def setDebug (level, file=None):
global _DEBUG_LEVEL, printMesg
_DEBUG_LEVEL = int(level)
- if _DEBUG_LEVEL > 0:
+ if _DEBUG_LEVEL > 0:
printMesg = _printMesg
- if (file):
+ if (file):
fh = open( file, 'w' )
catchStderr( fh )
else:
catchStderr( sys.__stderr__ )
__builtin__.__dict__['gDebug'] = printMesg
-
+
def catchStderr(fh):
global _fh
_fh = fh
@@ -96,31 +96,31 @@
# We use _noPrintMesg and _printMesg assignment to printMesg
# to speed things up when debug mode is not being used. It's
# assigned in setDebug()
-#
+#
def _noPrintMesg(level, message, dropToDebugger=0):
pass
def _printMesg(level, message, dropToDebugger=0):
- if ( level <= _DEBUG_LEVEL ):
+ if ( level <= _DEBUG_LEVEL ):
global _fh, _DEBUGGER
if type(message)==type(u''):
message=message.encode('utf-8')
caller = extract_stack()[-2]
- try:
- if caller[0][-3:] == '.py':
+ try:
+ if caller[0][-3:] == '.py':
file = "[%s:%s] " % (string.split(caller[0][:-3],'/')[-1], caller[1])
- else:
+ else:
file = "[%s:%s] " % (string.split(caller[0],'/')[-1], caller[1])
- except:
+ except:
file = ""
lines = string.split("%s" % message, '\n')
for line in lines:
_fh.write("DB%03d: %s%s\n" % (level, file, line))
-
+
if dropToDebugger and _DEBUGGER:
_DEBUGGER.set_trace()
-
+
printMesg = _noPrintMesg
__builtin__.__dict__['gDebug'] = printMesg
Added: trunk/gnue-common/src/apps/manpage.py
===================================================================
--- trunk/gnue-common/src/apps/manpage.py 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-common/src/apps/manpage.py 2004-03-31 21:37:38 UTC (rev
5596)
@@ -0,0 +1,187 @@
+#
+# 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
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise 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.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# selfdoc.py
+#
+# DESCRIPTION:
+"""
+Tool self-documenting base class
+"""
+# NOTES:
+#
+
+import time, string
+from gnue.common.utils.TextUtils import lineWrap
+
+
+class ManPage:
+ """
+ Create a man page for this utility.
+ """
+
+ def __init__(self, app, dest, format=None, options={}):
+
+ year = time.strftime("%Y", time.localtime(time.time()))
+
+ COMMAND = string.replace(app.COMMAND,'-','\-')
+
+ #
+ # 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())),
+ app.NAME))
+ dest.write('.SH NAME\n')
+ dest.write('%s \- %s\n' % (COMMAND,
+ string.replace(app.NAME,'-','\-')))
+
+
+ #
+ # 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
+ if part[0] == '[' and part[-1] == ']':
+ pre = '[\n.I '
+ post = '\n]'
+ part = part[1:-1]
+ else:
+ pre = '.I '
+ post = ''
+
+ if part == '...':
+ part = '\&...'
+
+ if string.find(part,'=') > 0:
+ first, last = string.split(part,'=',2)
+ part = string.replace(part,
+ '=','\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')
+
+
+ #
+ # 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
+ else:
+ allOptions[string.upper(option.longOption)] = option
+
+ if option.acceptsArgument:
+ descr = '.B \-\-%s <%s>' % (option.longOption, option.argumentName
or _("value"))
+ else:
+ descr = '.B \-\-%s' % (option.longOption)
+ if option.shortOption:
+ descr += ', \-%s' % option.shortOption
+
+ descriptors[string.upper(option.longOption)] = descr
+
+
+ for optionSet, descr in (
+ (allOptions,'GENERAL OPTIONS'),
+ (devOptions,'DEVELOPER OPTIONS') ):
+
+ sorted = optionSet.keys()
+ sorted.sort()
+
+ 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\\'"))
+
+ #
+ # 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.
+""" % {'COMMAND': COMMAND,
+ 'YEAR': year,
+ 'BUGS': app.REPORT_BUGS_TO,
+ 'AUTHOR': app.AUTHOR,
+ 'EMAIL': app.EMAIL})
+
Modified: trunk/gnue-common/utils/update-tool-docs
===================================================================
--- trunk/gnue-common/utils/update-tool-docs 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-common/utils/update-tool-docs 2004-03-31 21:37:38 UTC (rev
5596)
@@ -7,28 +7,28 @@
# Forms
gcvs $GDTD forms gnue-forms/doc/gnue-forms.dtd
-(cd gnue-forms/doc/man && gfcvs --generate-man-page)
+(cd gnue-forms/doc/man && gfcvs --selfdoc manpage --selfdoc-file gnue-forms.1)
# Reports
gcvs $GDTD reports gnue-reports/doc/gnue-reports.dtd
-(cd gnue-reports/doc/man && grcvs --generate-man-page)
-(cd gnue-reports/doc/man && grdcvs --generate-man-page)
+(cd gnue-reports/doc/man && grcvs --selfdoc manpage --selfdoc-file
gnue-reports.1)
+(cd gnue-reports/doc/man && grdcvs --selfdoc manpage --selfdoc-file
gnue-reports-server.1)
# Schema
gcvs $GDTD schema gnue-common/doc/gnue-schema.dtd
-(cd gnue-common/doc/man && gsscvs --generate-man-page)
-(cd gnue-common/doc/man && gimcvs --generate-man-page)
+(cd gnue-common/doc/man && gsscvs --selfdoc manpage --selfdoc-file
gnue-schema.1)
+(cd gnue-common/doc/man && gimcvs --selfdoc manpage --selfdoc-file
gnue-import.1)
# Designer
-(cd gnue-designer/doc/man && gdes --generate-man-page)
+(cd gnue-designer/doc/man && gdes --selfdoc manpage --selfdoc-file
gnue-designer.1)
# Appserver
-(cd gnue-appserver/doc/man && gacvs --generate-man-page)
-(cd gnue-appserver/doc/man && ggcvs --generate-man-page)
+(cd gnue-appserver/doc/man && gacvs --selfdoc manpage --selfdoc-file
gnue-appserver.1)
+(cd gnue-appserver/doc/man && ggcvs --selfdoc manpage --selfdoc-file
gnue-gsdgen.1)
# Navigator
gcvs $GDTD navigator gnue-navigator/doc/gnue-navigator.dtd
-(cd gnue-navigator/doc/man && gncvs --generate-man-page)
+(cd gnue-navigator/doc/man && gncvs --selfdoc manpage --selfdoc-file
gnue-navigator.1)
# gnurpc
gcvs $GDTD gnurpc gnue-common/doc/RPC-grpc-file.dtd
Modified: trunk/gnue-forms/setup.py
===================================================================
--- trunk/gnue-forms/setup.py 2004-03-31 21:32:37 UTC (rev 5595)
+++ trunk/gnue-forms/setup.py 2004-03-31 21:37:38 UTC (rev 5596)
@@ -37,9 +37,9 @@
# =============================================================================
class setup (GSetup.GSetup):
-
- package = PACKAGE.lower()
+ package = PACKAGE.lower()
+
# ---------------------------------------------------------------------------
# Definition of basic parameters for distribution and installation.
# Please add new files/directories that should be installed here.
@@ -47,7 +47,7 @@
# ---------------------------------------------------------------------------
def set_params (self, params):
-
+
# The Work
params ["name"] = PACKAGE
params ["version"] = VERSION
@@ -167,17 +167,17 @@
# wxPython
print "checking wxPython library: ",
if (os.environ.has_key('DISPLAY') and len(os.environ["DISPLAY"])) or \
- os.name!='posix':
+ os.name!='posix':
try:
- from wxPython import wx
- if wx.__version__[0:2]=='2.':
- print "ok (%s)" % wx.__version__
+ from wxPython import wx
+ if wx.__version__[0:2]=='2.':
+ print "ok (%s)" % wx.__version__
UIOK = 1
# WORKAROUND:
# return now because subsequent import of pygtk will segfault.
return
- else:
- print "Version 2.3 or greater needed"
+ else:
+ print "Version 2.3 or greater needed"
except ImportError:
pass
else:
Modified: trunk/gnue-forms/src/GFClient.py
===================================================================
--- trunk/gnue-forms/src/GFClient.py 2004-03-31 21:32:37 UTC (rev 5595)
+++ trunk/gnue-forms/src/GFClient.py 2004-03-31 21:37:38 UTC (rev 5596)
@@ -110,7 +110,7 @@
else:
self.handleStartupError(_("Unable to load any valid UI drivers.
Aborting."))
- if hasattr(self._ui,'handleStartupError') and not
self.OPTIONS['debug_level']:
+ if hasattr(self._ui,'handleStartupError') and not
self.OPTIONS['debug-level']:
self.handleStartupError = self._ui.handleStartupError
## if hasattr(self._ui,'handleUncaughtException'):
Modified: trunk/gnue-pointofsale/src/POSClient.py
===================================================================
--- trunk/gnue-pointofsale/src/POSClient.py 2004-03-31 21:32:37 UTC (rev
5595)
+++ trunk/gnue-pointofsale/src/POSClient.py 2004-03-31 21:37:38 UTC (rev
5596)
@@ -81,7 +81,7 @@
self.handleStartupError('Unable to load backend provider:\n\n%s\n\n%s'
% (mesg1, mesg2))
- if hasattr(self.frontend,'handleStartupError') and not
self.OPTIONS['debug_level']:
+ if hasattr(self.frontend,'handleStartupError') and not
self.OPTIONS['debug-level']:
self.handleStartupError = self.frontend.handleStartupError
## if hasattr(self.frontend,'handleUncaughtException'):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5596 - in trunk: gnue-common/src/apps gnue-common/utils gnue-forms gnue-forms/src gnue-pointofsale/src,
jcater <=