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