7 |
7 |
8 import pwd, grp, os, sys |
8 import pwd, grp, os, sys |
9 |
9 |
10 import logging; log = logging.getLogger('pvl.args') |
10 import logging; log = logging.getLogger('pvl.args') |
11 |
11 |
12 def parser (parser) : |
12 def parser (parser, setuid=None) : |
13 """ |
13 """ |
14 Return an optparse.OptionGroup. |
14 Return an optparse.OptionGroup. |
15 """ |
15 """ |
|
16 |
|
17 if setuid is None : |
|
18 # autodetect: only if we will be capable of |
|
19 # XXX: use linux capabilities? |
|
20 setuid = (os.geteuid() == 0) |
16 |
21 |
17 general = optparse.OptionGroup(parser, "General options") |
22 general = optparse.OptionGroup(parser, "General options") |
18 |
23 |
19 general.add_option('-q', '--quiet', dest='loglevel', action='store_const', const=logging.ERROR, help="Less output") |
24 general.add_option('-q', '--quiet', dest='loglevel', action='store_const', const=logging.ERROR, help="Less output") |
20 general.add_option('-v', '--verbose', dest='loglevel', action='store_const', const=logging.INFO, help="More output") |
25 general.add_option('-v', '--verbose', dest='loglevel', action='store_const', const=logging.INFO, help="More output") |
21 general.add_option('-D', '--debug', dest='loglevel', action='store_const', const=logging.DEBUG, help="Even more output") |
26 general.add_option('-D', '--debug', dest='loglevel', action='store_const', const=logging.DEBUG, help="Even more output") |
22 general.add_option('--log-file', help="Log to file") |
27 general.add_option('--log-file', help="Log to file") |
23 general.add_option('--debug-module', action='append', metavar='MODULE', |
28 general.add_option('--debug-module', action='append', metavar='MODULE', |
24 help="Enable logging for the given logger/module name") |
29 help="Enable logging for the given logger/module name") |
25 |
30 |
26 general.add_option('--uid', help="Change uid") |
31 if setuid : |
27 general.add_option('--gid', help="Change gid") |
32 general.add_option('--uid', help="Change uid") |
|
33 general.add_option('--gid', help="Change gid") |
28 |
34 |
29 # defaults |
35 # defaults |
30 parser.set_defaults( |
36 parser.set_defaults( |
31 logname = parser.prog, |
37 logname = parser.prog, |
32 loglevel = logging.WARN, |
38 loglevel = logging.WARN, |