1*24bb1048SAlexander Pyhalov#!@PYTHON@ 2cdf0c1d5Smjnelson# 3cdf0c1d5Smjnelson# This program is free software; you can redistribute it and/or modify 4cdf0c1d5Smjnelson# it under the terms of the GNU General Public License version 2 5cdf0c1d5Smjnelson# as published by the Free Software Foundation. 6cdf0c1d5Smjnelson# 7cdf0c1d5Smjnelson# This program is distributed in the hope that it will be useful, 8cdf0c1d5Smjnelson# but WITHOUT ANY WARRANTY; without even the implied warranty of 9cdf0c1d5Smjnelson# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10cdf0c1d5Smjnelson# GNU General Public License for more details. 11cdf0c1d5Smjnelson# 12cdf0c1d5Smjnelson# You should have received a copy of the GNU General Public License 13cdf0c1d5Smjnelson# along with this program; if not, write to the Free Software 14cdf0c1d5Smjnelson# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 15cdf0c1d5Smjnelson# 16cdf0c1d5Smjnelson 17cdf0c1d5Smjnelson# 1887ab3622SRichard Lowe# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 19cdf0c1d5Smjnelson# 20cdf0c1d5Smjnelson 21cdf0c1d5Smjnelson''' 22cdf0c1d5SmjnelsonCreate a wx-style active list on stdout based on a Mercurial 23cdf0c1d5Smjnelsonworkspace in support of webrev's Mercurial support. 24cdf0c1d5Smjnelson''' 25cdf0c1d5Smjnelson 26cdf0c1d5Smjnelson# 27cdf0c1d5Smjnelson# NB: This assumes the normal onbld directory structure 28cdf0c1d5Smjnelson# 29cdf0c1d5Smjnelsonimport sys, os 3087ab3622SRichard Lowe 3187ab3622SRichard Lowesys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib", 3287ab3622SRichard Lowe "python%d.%d" % sys.version_info[:2])) 3387ab3622SRichard Lowe 3487ab3622SRichard Lowe# Allow running from the source tree, using the modules in the source tree 3587ab3622SRichard Lowesys.path.insert(2, os.path.join(os.path.dirname(__file__), "..")) 36cdf0c1d5Smjnelson 37cdf0c1d5Smjnelsonfrom onbld.Scm import Version 38cdf0c1d5Smjnelson 39cdf0c1d5Smjnelsontry: 40cdf0c1d5Smjnelson Version.check_version() 41c959a081SRichard Loweexcept Version.VersionMismatch, versionerror: 42c959a081SRichard Lowe sys.stderr.write("Error: %s\n" % versionerror) 43cdf0c1d5Smjnelson sys.exit(1) 44cdf0c1d5Smjnelson 45c959a081SRichard Lowe 46cdf0c1d5Smjnelsonimport getopt, binascii 4787039217SRichard Lowefrom mercurial import error, hg, ui, util 4887039217SRichard Lowefrom onbld.Scm.WorkSpace import WorkSpace 49c959a081SRichard Lowe 50cdf0c1d5Smjnelson 51cdf0c1d5Smjnelsondef usage(): 52cdf0c1d5Smjnelson sys.stderr.write("usage: %s [-p parent] -w workspace\n" % 53cdf0c1d5Smjnelson os.path.basename(__file__)) 54cdf0c1d5Smjnelson sys.exit(2) 55cdf0c1d5Smjnelson 56c959a081SRichard Lowe 57cdf0c1d5Smjnelsondef main(argv): 58cdf0c1d5Smjnelson try: 599a70fc3bSMark J. Nelson opts = getopt.getopt(argv, 'w:o:p:')[0] 60cdf0c1d5Smjnelson except getopt.GetoptError, e: 61cdf0c1d5Smjnelson sys.stderr.write(str(e) + '\n') 62cdf0c1d5Smjnelson usage() 63cdf0c1d5Smjnelson 64cdf0c1d5Smjnelson parentpath = None 65cdf0c1d5Smjnelson wspath = None 669a70fc3bSMark J. Nelson outputfile = None 67cdf0c1d5Smjnelson 68cdf0c1d5Smjnelson for opt, arg in opts: 69cdf0c1d5Smjnelson if opt == '-w': 70cdf0c1d5Smjnelson wspath = arg 719a70fc3bSMark J. Nelson elif opt == '-o': 729a70fc3bSMark J. Nelson outputfile = arg 73cdf0c1d5Smjnelson elif opt == '-p': 74cdf0c1d5Smjnelson parentpath = arg 75cdf0c1d5Smjnelson 76cdf0c1d5Smjnelson if not wspath: 77cdf0c1d5Smjnelson usage() 78cdf0c1d5Smjnelson 79cdf0c1d5Smjnelson try: 80c959a081SRichard Lowe repository = hg.repository(ui.ui(), wspath) 8187039217SRichard Lowe except error.RepoError, e: 82cdf0c1d5Smjnelson sys.stderr.write("failed to open repository: %s\n" % e) 83cdf0c1d5Smjnelson sys.exit(1) 84cdf0c1d5Smjnelson 85cdf0c1d5Smjnelson ws = WorkSpace(repository) 86cdf0c1d5Smjnelson act = ws.active(parentpath) 87cdf0c1d5Smjnelson 88cdf0c1d5Smjnelson node = act.parenttip.node() 89cdf0c1d5Smjnelson parenttip = binascii.hexlify(node) 909a70fc3bSMark J. Nelson 919a70fc3bSMark J. Nelson fh = None 929a70fc3bSMark J. Nelson if outputfile: 939a70fc3bSMark J. Nelson try: 949a70fc3bSMark J. Nelson fh = open(outputfile, 'w') 959a70fc3bSMark J. Nelson except EnvironmentError, e: 969a70fc3bSMark J. Nelson sys.stderr.write("could not open output file: %s\n" % e) 979a70fc3bSMark J. Nelson sys.exit(1) 989a70fc3bSMark J. Nelson else: 999a70fc3bSMark J. Nelson fh = sys.stdout 1009a70fc3bSMark J. Nelson 1019a70fc3bSMark J. Nelson fh.write("HG_PARENT=%s\n" % parenttip) 102cdf0c1d5Smjnelson 103cdf0c1d5Smjnelson entries = [i for i in act] 104cdf0c1d5Smjnelson entries.sort() 105cdf0c1d5Smjnelson 106cdf0c1d5Smjnelson for entry in entries: 107e6ccc173SEdward Pilatowicz if entry.is_renamed() or entry.is_copied(): 1089a70fc3bSMark J. Nelson fh.write("%s %s\n" % (entry.name, entry.parentname)) 109cdf0c1d5Smjnelson else: 1109a70fc3bSMark J. Nelson fh.write("%s\n" % entry.name) 111cdf0c1d5Smjnelson 112cdf0c1d5Smjnelson # Strip blank lines. 113cdf0c1d5Smjnelson comments = filter(lambda x: x and not x.isspace(), 114cdf0c1d5Smjnelson entry.comments) 115cdf0c1d5Smjnelson 1169a70fc3bSMark J. Nelson fh.write('\n') 117cdf0c1d5Smjnelson if comments: 1189a70fc3bSMark J. Nelson fh.write('%s\n' % '\n'.join(comments)) 119cdf0c1d5Smjnelson else: 1209a70fc3bSMark J. Nelson fh.write("*** NO COMMENTS ***\n") 1219a70fc3bSMark J. Nelson fh.write('\n') 122cdf0c1d5Smjnelson 123cdf0c1d5Smjnelsonif __name__ == '__main__': 124cdf0c1d5Smjnelson try: 125cdf0c1d5Smjnelson main(sys.argv[1:]) 126cdf0c1d5Smjnelson except KeyboardInterrupt: 127cdf0c1d5Smjnelson sys.exit(1) 1289a70fc3bSMark J. Nelson except util.Abort, msg: 1299a70fc3bSMark J. Nelson sys.stderr.write("Abort: %s\n" % msg) 1309a70fc3bSMark J. Nelson sys.exit(1) 131