annotate resources/GenerateHgUsage.py @ 126:47209552ec46

Shellescaped all command arguments in HgRepo.GetCommand, so that the commands work properly with ugly file names, in my case containing parentheses. Wrapping revision arguments in quotes is no longer necessary, so removed all of that as well.
author namark <nshan.nnnn@gmail.com>
date Wed, 02 Dec 2015 22:45:12 +0400
parents f02e37f395ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import re
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import urllib2
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from BeautifulSoup import BeautifulSoup
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 # Load the documentation page.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 print "Loading HG documentation from selenic.com..."
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 url = urllib2.urlopen("http://www.selenic.com/mercurial/hg.1.html")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 soup = BeautifulSoup(url)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 # Open the output file.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 output = 'hg_usage.vim'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 f = open(output, 'w')
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 # A little header for people peeking in there.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 f.write("\" LAWRENCIUM - MERCURIAL USAGE\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 f.write("\" This file is generated automatically.\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 f.write("\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 # Start with the global options.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 f.write("let g:lawrencium_hg_options = [\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 for option in soup.find('div', id='options').findAll('span', {'class': 'option'}):
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 f.write(" \\'%s',\n" % option.string)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 f.write(" \\]\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 f.write("\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 # Now get the usage for all commands.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 f.write("let g:lawrencium_hg_commands = {\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 for command in soup.find('div', id='commands').findAll('div', {'class': 'section'}):
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 print " - %s" % format(command.h2.string)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 f.write(" \\'%s': [\n" % command.h2.string)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 option_table = command.find('table', { 'class': re.compile('option-list') })
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 if option_table:
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 for option in option_table.findAll('span', { 'class': 'option'}):
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 f.write(" \\'%s',\n" % option.string)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 f.write(" \\],\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 f.write(" \\}\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 f.write("\n")
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 # Close the output file, and we're done.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 f.close()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 print "Done!"
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42