111838SLiane.Praza@Sun.COM#!/usr/bin/python2.4 27078Smjnelson# 37078Smjnelson# This program is free software; you can redistribute it and/or modify 47078Smjnelson# it under the terms of the GNU General Public License version 2 57078Smjnelson# as published by the Free Software Foundation. 67078Smjnelson# 77078Smjnelson# This program is distributed in the hope that it will be useful, 87078Smjnelson# but WITHOUT ANY WARRANTY; without even the implied warranty of 97078Smjnelson# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 107078Smjnelson# GNU General Public License for more details. 117078Smjnelson# 127078Smjnelson# You should have received a copy of the GNU General Public License 137078Smjnelson# along with this program; if not, write to the Free Software 147078Smjnelson# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 157078Smjnelson# 167078Smjnelson 177078Smjnelson# 18*12216Srichlowe@richlowe.net# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 197078Smjnelson# 207078Smjnelson 217078Smjnelson''' 227078SmjnelsonCreate a wx-style active list on stdout based on a Mercurial 237078Smjnelsonworkspace in support of webrev's Mercurial support. 247078Smjnelson''' 257078Smjnelson 267078Smjnelson# 277078Smjnelson# NB: This assumes the normal onbld directory structure 287078Smjnelson# 297078Smjnelsonimport sys, os 30*12216Srichlowe@richlowe.net 31*12216Srichlowe@richlowe.netsys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib", 32*12216Srichlowe@richlowe.net "python%d.%d" % sys.version_info[:2])) 33*12216Srichlowe@richlowe.net 34*12216Srichlowe@richlowe.net# Allow running from the source tree, using the modules in the source tree 35*12216Srichlowe@richlowe.netsys.path.insert(2, os.path.join(os.path.dirname(__file__), "..")) 367078Smjnelson 377078Smjnelsonfrom onbld.Scm import Version 387078Smjnelson 397078Smjnelsontry: 407078Smjnelson Version.check_version() 4110399Srichlowe@richlowe.netexcept Version.VersionMismatch, versionerror: 4210399Srichlowe@richlowe.net sys.stderr.write("Error: %s\n" % versionerror) 437078Smjnelson sys.exit(1) 447078Smjnelson 4510399Srichlowe@richlowe.net 467078Smjnelsonimport getopt, binascii 4710399Srichlowe@richlowe.netfrom mercurial import hg, ui, util 4810399Srichlowe@richlowe.netfrom onbld.Scm.WorkSpace import WorkSpace, HgRepoError 4910399Srichlowe@richlowe.net 507078Smjnelson 517078Smjnelsondef usage(): 527078Smjnelson sys.stderr.write("usage: %s [-p parent] -w workspace\n" % 537078Smjnelson os.path.basename(__file__)) 547078Smjnelson sys.exit(2) 557078Smjnelson 5610399Srichlowe@richlowe.net 577078Smjnelsondef main(argv): 587078Smjnelson try: 597298SMark.J.Nelson@Sun.COM opts = getopt.getopt(argv, 'w:o:p:')[0] 607078Smjnelson except getopt.GetoptError, e: 617078Smjnelson sys.stderr.write(str(e) + '\n') 627078Smjnelson usage() 637078Smjnelson 647078Smjnelson parentpath = None 657078Smjnelson wspath = None 667298SMark.J.Nelson@Sun.COM outputfile = None 677078Smjnelson 687078Smjnelson for opt, arg in opts: 697078Smjnelson if opt == '-w': 707078Smjnelson wspath = arg 717298SMark.J.Nelson@Sun.COM elif opt == '-o': 727298SMark.J.Nelson@Sun.COM outputfile = arg 737078Smjnelson elif opt == '-p': 747078Smjnelson parentpath = arg 757078Smjnelson 767078Smjnelson if not wspath: 777078Smjnelson usage() 787078Smjnelson 797078Smjnelson try: 8010399Srichlowe@richlowe.net repository = hg.repository(ui.ui(), wspath) 8110399Srichlowe@richlowe.net except HgRepoError, e: 827078Smjnelson sys.stderr.write("failed to open repository: %s\n" % e) 837078Smjnelson sys.exit(1) 8410399Srichlowe@richlowe.net 857078Smjnelson ws = WorkSpace(repository) 867078Smjnelson act = ws.active(parentpath) 877078Smjnelson 887078Smjnelson node = act.parenttip.node() 897078Smjnelson parenttip = binascii.hexlify(node) 907298SMark.J.Nelson@Sun.COM 917298SMark.J.Nelson@Sun.COM fh = None 927298SMark.J.Nelson@Sun.COM if outputfile: 937298SMark.J.Nelson@Sun.COM try: 947298SMark.J.Nelson@Sun.COM fh = open(outputfile, 'w') 957298SMark.J.Nelson@Sun.COM except EnvironmentError, e: 967298SMark.J.Nelson@Sun.COM sys.stderr.write("could not open output file: %s\n" % e) 977298SMark.J.Nelson@Sun.COM sys.exit(1) 987298SMark.J.Nelson@Sun.COM else: 997298SMark.J.Nelson@Sun.COM fh = sys.stdout 1007298SMark.J.Nelson@Sun.COM 1017298SMark.J.Nelson@Sun.COM fh.write("HG_PARENT=%s\n" % parenttip) 1027078Smjnelson 1037078Smjnelson entries = [i for i in act] 1047078Smjnelson entries.sort() 1057078Smjnelson 1067078Smjnelson for entry in entries: 10710789SEdward.Pilatowicz@Sun.COM if entry.is_renamed() or entry.is_copied(): 1087298SMark.J.Nelson@Sun.COM fh.write("%s %s\n" % (entry.name, entry.parentname)) 1097078Smjnelson else: 1107298SMark.J.Nelson@Sun.COM fh.write("%s\n" % entry.name) 1117078Smjnelson 1127078Smjnelson # Strip blank lines. 1137078Smjnelson comments = filter(lambda x: x and not x.isspace(), 1147078Smjnelson entry.comments) 1157078Smjnelson 1167298SMark.J.Nelson@Sun.COM fh.write('\n') 1177078Smjnelson if comments: 1187298SMark.J.Nelson@Sun.COM fh.write('%s\n' % '\n'.join(comments)) 1197078Smjnelson else: 1207298SMark.J.Nelson@Sun.COM fh.write("*** NO COMMENTS ***\n") 1217298SMark.J.Nelson@Sun.COM fh.write('\n') 1227078Smjnelson 1237078Smjnelsonif __name__ == '__main__': 1247078Smjnelson try: 1257078Smjnelson main(sys.argv[1:]) 1267078Smjnelson except KeyboardInterrupt: 1277078Smjnelson sys.exit(1) 1287298SMark.J.Nelson@Sun.COM except util.Abort, msg: 1297298SMark.J.Nelson@Sun.COM sys.stderr.write("Abort: %s\n" % msg) 1307298SMark.J.Nelson@Sun.COM sys.exit(1) 131