improved help text with flexibel helper class and added cfgfile docu
This commit is contained in:
@@ -9,6 +9,12 @@ from optparse import OptionParser
|
||||
import ConfigParser
|
||||
import getpass
|
||||
|
||||
class MyOptParser(OptionParser):
|
||||
"""OptionParser derived class for enabling us to give out a
|
||||
nicer help text where text can follow the option section"""
|
||||
def format_epilog(self, formatter):
|
||||
return self.epilog.replace('%prog',os.path.basename(sys.argv[0]))
|
||||
|
||||
def read_cfg(filename):
|
||||
cfg = ConfigParser.ConfigParser()
|
||||
|
||||
@@ -63,13 +69,19 @@ mylogger.addHandler(ch)
|
||||
|
||||
################################################
|
||||
# OPTION PARSING
|
||||
usage = """usage %prog [options] groupname [usernames]
|
||||
usage = """%prog [options] groupname [usernames]
|
||||
|
||||
Used to inspect or change members of a group in Active Directory
|
||||
User names can be given as full distinguished names or just as
|
||||
the short names (in that case they will be extended by the
|
||||
standard OU extension)
|
||||
|
||||
The configuration is read from a configuration file (default
|
||||
locations:
|
||||
"""
|
||||
usage += ", ".join(cfgfile_loc) + ')\n'
|
||||
|
||||
usage_epilog = """
|
||||
Examples:
|
||||
List group members
|
||||
%prog svc_ra_x06sa
|
||||
@@ -85,10 +97,9 @@ usage = """usage %prog [options] groupname [usernames]
|
||||
List users matching a pattern
|
||||
%prog -u 'mueller*'
|
||||
|
||||
The configuration is read from a configuration file (default
|
||||
locations: """
|
||||
usage += ", ".join(cfgfile_loc) + ')\n'
|
||||
usage += """Configuration file example:
|
||||
"""
|
||||
|
||||
examplecfg = """# Configuration file example:
|
||||
|
||||
[Ldap]
|
||||
# URL for contacting the LDAP server
|
||||
@@ -100,13 +111,13 @@ group_ou = ou=Groups,ou=PSI,dc=d,dc=psi,dc=ch
|
||||
# minimally privileged Ldap user and password for running normal
|
||||
# lookup queries
|
||||
default_user_dn = CN=linux_ldap,OU=Services,OU=IT,DC=d,DC=psi,DC=ch
|
||||
default_user_pw = TBVsK5zOfqMyxVmXco7y
|
||||
default_user_pw = DEFaultPassword
|
||||
# Optional:
|
||||
# default filter to be used for group searches
|
||||
default_group_filter = svc-ra*
|
||||
|
||||
"""
|
||||
parser = OptionParser(usage=usage)
|
||||
#parser = OptionParser(usage = usage, epilog = usage_epilog)
|
||||
parser = MyOptParser(usage = usage, epilog = usage_epilog)
|
||||
parser.add_option('-a',
|
||||
action = 'store_true',
|
||||
dest = 'flag_add',
|
||||
@@ -123,6 +134,12 @@ parser.add_option('-c',
|
||||
help = 'path of a config file',
|
||||
default = ''
|
||||
)
|
||||
parser.add_option('--configfile',
|
||||
action = 'store_true',
|
||||
dest = 'flag_examplecfg',
|
||||
help = 'show an example configuration file',
|
||||
default= False
|
||||
)
|
||||
parser.add_option('-u',
|
||||
action = 'store',
|
||||
dest = 'userfilter',
|
||||
@@ -197,6 +214,10 @@ if options.flag_version:
|
||||
sys.stdout.write('Library version: ' + libversion + '\n')
|
||||
sys.exit(0)
|
||||
|
||||
if options.flag_examplecfg:
|
||||
sys.stdout.write(examplecfg)
|
||||
sys.exit(0)
|
||||
|
||||
cfgfile = None
|
||||
if(options.cfgfile != ''):
|
||||
cfgfile = options.cfgfile
|
||||
|
||||
Reference in New Issue
Block a user