Pythonic.
[pyTivo/wmcbrine.git] / plugins / admin / buildhelp.py
blob5a3087bed2763407d79ae641e3b64d0536412d0e
1 import os
3 SCRIPTDIR = os.path.dirname(__file__)
5 ## Build initial help list
6 help_list = {}
7 title = ''
8 settings_known = {}
9 multiline = ''
10 f = open(os.path.join(SCRIPTDIR, 'help.txt'))
11 try:
12 for line in f:
13 line = line.strip()
14 if multiline:
15 if line.endswith('+\\'):
16 multiline += line[:-2]
17 else:
18 multiline += line
19 help_list[title].append(multiline)
20 multiline = ''
21 continue
22 if not line or line.startswith('#'):
23 # skip blank or commented lines
24 continue
25 if ':' not in line:
26 title = line
27 help_list[title] = []
28 else:
29 value, data = [x.strip() for x in line.split(':', 1)]
30 if value.lower() == 'available in':
31 # special setting to create section_known array
32 for section in data.split(','):
33 section = section.lower().strip()
34 if section not in settings_known:
35 settings_known[section] = []
36 settings_known[section].append(title)
37 else:
38 if line.endswith('+\\'):
39 multiline += line[:-2]
40 else:
41 help_list[title].append(line)
42 finally:
43 f.close()
44 ## Done building help list
46 def gethelp():
47 return help_list
49 def getknown(section):
50 return settings_known[section]