xref: /titanic_50/usr/src/tools/scripts/hg-active.py (revision cdf0c1d55d9b3b6beaf994835440dfb01aef5cf0)
1*cdf0c1d5Smjnelson#! /usr/bin/python
2*cdf0c1d5Smjnelson#
3*cdf0c1d5Smjnelson#  This program is free software; you can redistribute it and/or modify
4*cdf0c1d5Smjnelson#  it under the terms of the GNU General Public License version 2
5*cdf0c1d5Smjnelson#  as published by the Free Software Foundation.
6*cdf0c1d5Smjnelson#
7*cdf0c1d5Smjnelson#  This program is distributed in the hope that it will be useful,
8*cdf0c1d5Smjnelson#  but WITHOUT ANY WARRANTY; without even the implied warranty of
9*cdf0c1d5Smjnelson#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10*cdf0c1d5Smjnelson#  GNU General Public License for more details.
11*cdf0c1d5Smjnelson#
12*cdf0c1d5Smjnelson#  You should have received a copy of the GNU General Public License
13*cdf0c1d5Smjnelson#  along with this program; if not, write to the Free Software
14*cdf0c1d5Smjnelson#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*cdf0c1d5Smjnelson#
16*cdf0c1d5Smjnelson
17*cdf0c1d5Smjnelson#
18*cdf0c1d5Smjnelson# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
19*cdf0c1d5Smjnelson# Use is subject to license terms.
20*cdf0c1d5Smjnelson#
21*cdf0c1d5Smjnelson# ident	"%Z%%M%	%I%	%E% SMI"
22*cdf0c1d5Smjnelson#
23*cdf0c1d5Smjnelson
24*cdf0c1d5Smjnelson'''
25*cdf0c1d5SmjnelsonCreate a wx-style active list on stdout based on a Mercurial
26*cdf0c1d5Smjnelsonworkspace in support of webrev's Mercurial support.
27*cdf0c1d5Smjnelson'''
28*cdf0c1d5Smjnelson
29*cdf0c1d5Smjnelson#
30*cdf0c1d5Smjnelson# NB: This assumes the normal onbld directory structure
31*cdf0c1d5Smjnelson#
32*cdf0c1d5Smjnelsonimport sys, os
33*cdf0c1d5Smjnelsonsys.path.insert(1, "%s/../lib/python" % os.path.dirname(__file__))
34*cdf0c1d5Smjnelsonsys.path.insert(1, "%s/.." % os.path.dirname(__file__))
35*cdf0c1d5Smjnelson
36*cdf0c1d5Smjnelsonfrom onbld.Scm import Version
37*cdf0c1d5Smjnelson
38*cdf0c1d5Smjnelsontry:
39*cdf0c1d5Smjnelson    Version.check_version()
40*cdf0c1d5Smjnelsonexcept Version.VersionMismatch, e:
41*cdf0c1d5Smjnelson    sys.stderr.write("Error: %s\n" % e)
42*cdf0c1d5Smjnelson    sys.exit(1)
43*cdf0c1d5Smjnelson
44*cdf0c1d5Smjnelsonimport getopt, binascii
45*cdf0c1d5Smjnelsonfrom mercurial import hg, repo
46*cdf0c1d5Smjnelsonfrom onbld.Scm.WorkSpace import WorkSpace
47*cdf0c1d5Smjnelson
48*cdf0c1d5Smjnelsondef usage():
49*cdf0c1d5Smjnelson    sys.stderr.write("usage: %s [-p parent] -w workspace\n" %
50*cdf0c1d5Smjnelson                     os.path.basename(__file__))
51*cdf0c1d5Smjnelson    sys.exit(2)
52*cdf0c1d5Smjnelson
53*cdf0c1d5Smjnelsondef main(argv):
54*cdf0c1d5Smjnelson    try:
55*cdf0c1d5Smjnelson        opts, args = getopt.getopt(argv, 'w:p:')
56*cdf0c1d5Smjnelson    except getopt.GetoptError, e:
57*cdf0c1d5Smjnelson        sys.stderr.write(str(e) + '\n')
58*cdf0c1d5Smjnelson        usage()
59*cdf0c1d5Smjnelson
60*cdf0c1d5Smjnelson    parentpath = None
61*cdf0c1d5Smjnelson    wspath = None
62*cdf0c1d5Smjnelson
63*cdf0c1d5Smjnelson    for opt, arg in opts:
64*cdf0c1d5Smjnelson        if opt == '-w':
65*cdf0c1d5Smjnelson            wspath = arg
66*cdf0c1d5Smjnelson        elif opt == '-p':
67*cdf0c1d5Smjnelson            parentpath = arg
68*cdf0c1d5Smjnelson
69*cdf0c1d5Smjnelson    if not wspath:
70*cdf0c1d5Smjnelson        usage()
71*cdf0c1d5Smjnelson
72*cdf0c1d5Smjnelson    try:
73*cdf0c1d5Smjnelson        repository = hg.repository(None, wspath)
74*cdf0c1d5Smjnelson    except repo.RepoError, e:
75*cdf0c1d5Smjnelson        sys.stderr.write("failed to open repository: %s\n" % e)
76*cdf0c1d5Smjnelson        sys.exit(1)
77*cdf0c1d5Smjnelson
78*cdf0c1d5Smjnelson    ws = WorkSpace(repository)
79*cdf0c1d5Smjnelson    act = ws.active(parentpath)
80*cdf0c1d5Smjnelson
81*cdf0c1d5Smjnelson    node = act.parenttip.node()
82*cdf0c1d5Smjnelson    parenttip = binascii.hexlify(node)
83*cdf0c1d5Smjnelson    print "HG_PARENT=" + parenttip
84*cdf0c1d5Smjnelson
85*cdf0c1d5Smjnelson    entries = [i for i in act]
86*cdf0c1d5Smjnelson    entries.sort()
87*cdf0c1d5Smjnelson
88*cdf0c1d5Smjnelson    for entry in entries:
89*cdf0c1d5Smjnelson        if entry.is_renamed():
90*cdf0c1d5Smjnelson            print "%s %s" % (entry.name, entry.parentname)
91*cdf0c1d5Smjnelson        else:
92*cdf0c1d5Smjnelson            print entry.name
93*cdf0c1d5Smjnelson
94*cdf0c1d5Smjnelson        # Strip blank lines.
95*cdf0c1d5Smjnelson        comments = filter(lambda x: x and not x.isspace(),
96*cdf0c1d5Smjnelson                          entry.comments)
97*cdf0c1d5Smjnelson
98*cdf0c1d5Smjnelson        print
99*cdf0c1d5Smjnelson        if comments:
100*cdf0c1d5Smjnelson            print '\n'.join(comments)
101*cdf0c1d5Smjnelson        else:
102*cdf0c1d5Smjnelson            print "*** NO COMMENTS ***"
103*cdf0c1d5Smjnelson        print
104*cdf0c1d5Smjnelson
105*cdf0c1d5Smjnelsonif __name__ == '__main__':
106*cdf0c1d5Smjnelson    try:
107*cdf0c1d5Smjnelson        main(sys.argv[1:])
108*cdf0c1d5Smjnelson    except KeyboardInterrupt:
109*cdf0c1d5Smjnelson        sys.exit(1)
110