Mercurial > vim-lawrencium
annotate resources/GenerateHgUsage.py @ 91:e21a1819ab27
New command to export a patch and allow existing log command to take options.
* Hglogexport command takes patch name as input. If the env variable
HG_EXPORT_PATCH_DIR is set, then the patch will be created under it.
Otherwise, it will be created in the directory from which vim
was launched.
* HgLog command takes options that can be passed to hg log command.
E.g., the following command will list just 3 logs by user bob.
:Hglog -u bob -l 3
Testing:
* Patch gets created under the right directory when env variable is set
and not set.
* Hglog command honors -u and -l options. It also works when current
file name is given as input --> :Hglog % -u bob -l 3
author | Kannan Rajah <krajah@maprtech.com> |
---|---|
date | Sat, 05 Jul 2014 17:16:42 -0700 |
parents | f02e37f395ae |
children |
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 |