1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/python
#---------------------------------------------------------------
# Project : Mandrake Linux
# Module : share
# File : draksec_help.py
# Version : $Id$
# Author : Thierry Vignaud
# Created On : Sat Jan 26 17:38:39 2002
# Purpose : loads a python module and creates a help hash
# for draksec.
#---------------------------------------------------------------
import sys
import imp
import inspect
import re
header = '''package security::help;
# !! THIS FILE WAS AUTO-GENERATED BY draksec_help.py !!
# !! DO NOT MODIFY HERE, MODIFY IN THE *MSEC* CVS !!
use strict;
use common;
our %help = (
'''
footer = ''');
'''
### strings used in the rewritting
function_str = '''
'%s' => N("Arguments: %s
%s"),
'''
### code
modulename = sys.argv[1]
module = __import__(modulename)
sys.stdout.write(header)
clean = re.compile('^.[a-z].*\n', re.M)
clean2 = re.compile('^\n', re.M)
perl = re.compile('^([A-Z_0-9]*) (.*)$', re.M)
for f in inspect.getmembers(module, inspect.isfunction):
(args, varargs, varkw, locals) = inspect.getargspec(f[1])
doc = f[1].__doc__
if doc and len(doc) > 2:
doc = doc[2:]
argspec = inspect.formatargspec(args, varargs, varkw, locals) + '\n'
if f[0] == 'set_security_conf':
doc = clean.sub('', doc)
doc = clean2.sub('', doc)
doc = perl.sub('\\1 => N("\\2"),', doc)
sys.stdout.write(doc)
else:
s = function_str % (f[0], argspec, doc)
sys.stdout.write(s)
sys.stdout.write(footer)
# draksec_help.py ends here
|