1
# Support for scanning init scripts for LSB info
5
FACILITIES = '/var/lib/lsb/facilities'
7
beginre = re.compile(re.escape('### BEGIN INIT INFO'))
8
endre = re.compile(re.escape('### END INIT INFO'))
9
linere = re.compile(r'\#\s+([^:]+):\s*(.*)')
11
def scan_initfile(initfile):
12
headers = {'Description': []}
15
for line in open(initfile).xreadlines():
17
if beginre.match(line):
20
elif scanning and endre.match(line):
29
if line[1:3] == ' ' or line[1] == '\t':
30
headers['Description'].append(line[1:].strip())
33
match = linere.match(line)
35
print >> sys.stderr, "Warning: ignoring invalid init info line"
36
print >> sys.stderr, "-> %s" % line
39
header, body = match.groups()
40
if header == "Description":
41
headers[header].append(body.strip())
42
elif header in ('Default-Start', 'Default-Stop'):
43
headers[header] = map(int, body.split())
44
elif header in ('Required-Start', 'Required-Stop', 'Provides'):
45
headers[header] = body.split()
47
headers[header] = body
51
def save_facilities(facilities):
59
items = facilities.items()
60
fh = open(FACILITIES, 'w')
61
for facility, entries in items:
62
if facility[0] == '$': continue
63
for scriptname, pri in entries.items():
65
print >> fh, "%(scriptname)s %(facility)s %(start)d %(stop)d" % locals()
68
def load_facilities():
70
if os.path.exists(FACILITIES):
71
for line in open(FACILITIES).xreadlines():
73
scriptname, name, start, stop = line.strip().split()
74
facilities.get(name, {})[scriptname] = (int(start), int(stop))
76
print >> sys.stderr, 'Invalid facility line', line