view 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
line wrap: on
line source

import re
import urllib2
from BeautifulSoup import BeautifulSoup

# Load the documentation page.
print "Loading HG documentation from selenic.com..."
url = urllib2.urlopen("http://www.selenic.com/mercurial/hg.1.html")
soup = BeautifulSoup(url)

# Open the output file.
output = 'hg_usage.vim'
f = open(output, 'w')

# A little header for people peeking in there.
f.write("\" LAWRENCIUM - MERCURIAL USAGE\n")
f.write("\" This file is generated automatically.\n")
f.write("\n")

# Start with the global options.
f.write("let g:lawrencium_hg_options = [\n")
for option in soup.find('div', id='options').findAll('span', {'class': 'option'}):
    f.write("    \\'%s',\n" % option.string)
f.write("    \\]\n")
f.write("\n")

# Now get the usage for all commands.
f.write("let g:lawrencium_hg_commands = {\n")
for command in soup.find('div', id='commands').findAll('div', {'class': 'section'}):
    print " - %s" % format(command.h2.string) 
    f.write("    \\'%s': [\n" % command.h2.string)
    option_table = command.find('table', { 'class': re.compile('option-list') })
    if option_table:
        for option in option_table.findAll('span', { 'class': 'option'}):
            f.write("        \\'%s',\n" % option.string)
    f.write("        \\],\n")
f.write("    \\}\n")
f.write("\n")

# Close the output file, and we're done.
f.close()
print "Done!"