comparison resources/GenerateHgUsage.py @ 15:f02e37f395ae

Added ability to add files from the `hg status` window. Added ability to refresh the `hg status` window. Added generation of `hg` commands usage, and used that for a better `:Hg` auto-completion.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Dec 2011 17:09:37 -0800
parents
children
comparison
equal deleted inserted replaced
14:eab2680e6818 15:f02e37f395ae
1 import re
2 import urllib2
3 from BeautifulSoup import BeautifulSoup
4
5 # Load the documentation page.
6 print "Loading HG documentation from selenic.com..."
7 url = urllib2.urlopen("http://www.selenic.com/mercurial/hg.1.html")
8 soup = BeautifulSoup(url)
9
10 # Open the output file.
11 output = 'hg_usage.vim'
12 f = open(output, 'w')
13
14 # A little header for people peeking in there.
15 f.write("\" LAWRENCIUM - MERCURIAL USAGE\n")
16 f.write("\" This file is generated automatically.\n")
17 f.write("\n")
18
19 # Start with the global options.
20 f.write("let g:lawrencium_hg_options = [\n")
21 for option in soup.find('div', id='options').findAll('span', {'class': 'option'}):
22 f.write(" \\'%s',\n" % option.string)
23 f.write(" \\]\n")
24 f.write("\n")
25
26 # Now get the usage for all commands.
27 f.write("let g:lawrencium_hg_commands = {\n")
28 for command in soup.find('div', id='commands').findAll('div', {'class': 'section'}):
29 print " - %s" % format(command.h2.string)
30 f.write(" \\'%s': [\n" % command.h2.string)
31 option_table = command.find('table', { 'class': re.compile('option-list') })
32 if option_table:
33 for option in option_table.findAll('span', { 'class': 'option'}):
34 f.write(" \\'%s',\n" % option.string)
35 f.write(" \\],\n")
36 f.write(" \\}\n")
37 f.write("\n")
38
39 # Close the output file, and we're done.
40 f.close()
41 print "Done!"
42