config
view python/html2flux.py @ 224:57677a2bf772
remove umask
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Wed May 16 08:58:47 2012 -0700 (2 days ago) |
| parents | |
| children |
line source
1 #!/usr/bin/env python
3 import sys
4 from lxml import etree
6 from lsex import lsex # local import
7 executables = set([i.rsplit('/', 1)[-1] for i in lsex() ])
9 def printmenu(dl, output, top=True):
11 # XXX should do more checking
12 for child in dl.iterchildren():
13 if not top and child.tag == 'a':
14 print >> output, '[submenu] (%s)' % child.text
15 if child.tag == 'dt':
16 label = ' '.join([ i.strip() for i in child.itertext() if i.strip() ])
17 if child.tag == 'dd':
18 command = ' '.join([ i.strip() for i in child.itertext() if i.strip() ])
19 executable = command.split()[0]
20 if executable in executables:
21 print >> output, '[exec] (%s) {%s}' % (label, command)
22 if child.tag == 'dl':
23 printmenu(child, output, top=False)
24 if not top:
25 print >> output, '[end]'
27 def main(args = sys.argv[1:]):
29 # setup input, output
30 if args:
31 htmlfile = file(args[0])
32 else:
33 htmlfile = sys.stdin
34 html = htmlfile.read()
35 fluxout = sys.stdout
37 # get first element
38 dom = etree.fromstring(html)
39 dl = dom.find('.//dl')
41 printmenu(dl, fluxout)
43 if __name__ == '__main__':
44 main()
