view mercurial/fancyopts.py @ 571:c7364b985ca2

[PATCH 3/5]: cleaning the template parent management in hgweb -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [PATCH 3/5]: cleaning the template parent management in hgweb From: Goffredo Baroncelli <kreijack@libero.it> the filediff template use the old style p1/p2 and p1rev/p2rev inteface; the patch removes this old stuff, and update the code to the new style manifest hash: 29536b6ee71f03a48bceb7336040070ecd0d2b9e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCxvplywK+sNU5EO8RApW4AKCrTLHofr8jELtvNRpoNJHc0sjEfgCfaY2q /H96T6BMMXA4VLFVxzOBHCo= =u4El -----END PGP SIGNATURE-----
author mpm@selenic.com
date Sat, 02 Jul 2005 12:34:45 -0800
parents f9ad1a2c72eb
children 9a8daeff0ffa
line wrap: on
line source

import os, getopt

def fancyopts(args, options, state, syntax='', minlen = 0):
    long=[]
    short=''
    map={}
    dt={}

    for s, l, d, c in options:
        map['-'+s] = map['--'+l]=l
        state[l] = d
        dt[l] = type(d)
        if not d is None and not callable(d): s, l=s+':', l+'='
        if s: short = short + s
        if l: long.append(l)

    if os.environ.has_key("HG_OPTS"):
        args = os.environ["HG_OPTS"].split() + args

    opts, args = getopt.getopt(args, short, long)

    for opt, arg in opts:
        if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg)
        elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
        elif dt[map[opt]] is type(''): state[map[opt]] = arg
        elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
        elif dt[map[opt]] is type(None): state[map[opt]] = 1

    return args