Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/scripts/hg-active.py
+++ new/usr/src/tools/scripts/hg-active.py
1 -#!/usr/bin/python2.4
1 +#!/usr/bin/python2.6
2 2 #
3 3 # This program is free software; you can redistribute it and/or modify
4 4 # it under the terms of the GNU General Public License version 2
5 5 # as published by the Free Software Foundation.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU General Public License
13 13 # along with this program; if not, write to the Free Software
14 14 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 15 #
16 16
17 17 #
18 18 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
19 19 #
20 20
21 21 '''
22 22 Create a wx-style active list on stdout based on a Mercurial
23 23 workspace in support of webrev's Mercurial support.
24 24 '''
25 25
26 26 #
27 27 # NB: This assumes the normal onbld directory structure
28 28 #
29 29 import sys, os
30 30
31 31 sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
32 32 "python%d.%d" % sys.version_info[:2]))
33 33
34 34 # Allow running from the source tree, using the modules in the source tree
35 35 sys.path.insert(2, os.path.join(os.path.dirname(__file__), ".."))
36 36
37 37 from onbld.Scm import Version
38 38
39 39 try:
40 40 Version.check_version()
41 41 except Version.VersionMismatch, versionerror:
42 42 sys.stderr.write("Error: %s\n" % versionerror)
43 43 sys.exit(1)
44 44
45 45
46 46 import getopt, binascii
47 47 from mercurial import error, hg, ui, util
48 48 from onbld.Scm.WorkSpace import WorkSpace
49 49
50 50
51 51 def usage():
52 52 sys.stderr.write("usage: %s [-p parent] -w workspace\n" %
53 53 os.path.basename(__file__))
54 54 sys.exit(2)
55 55
56 56
57 57 def main(argv):
58 58 try:
59 59 opts = getopt.getopt(argv, 'w:o:p:')[0]
60 60 except getopt.GetoptError, e:
61 61 sys.stderr.write(str(e) + '\n')
62 62 usage()
63 63
64 64 parentpath = None
65 65 wspath = None
66 66 outputfile = None
67 67
68 68 for opt, arg in opts:
69 69 if opt == '-w':
70 70 wspath = arg
71 71 elif opt == '-o':
72 72 outputfile = arg
73 73 elif opt == '-p':
74 74 parentpath = arg
75 75
76 76 if not wspath:
77 77 usage()
78 78
79 79 try:
80 80 repository = hg.repository(ui.ui(), wspath)
81 81 except error.RepoError, e:
82 82 sys.stderr.write("failed to open repository: %s\n" % e)
83 83 sys.exit(1)
84 84
85 85 ws = WorkSpace(repository)
86 86 act = ws.active(parentpath)
87 87
88 88 node = act.parenttip.node()
89 89 parenttip = binascii.hexlify(node)
90 90
91 91 fh = None
92 92 if outputfile:
93 93 try:
94 94 fh = open(outputfile, 'w')
95 95 except EnvironmentError, e:
96 96 sys.stderr.write("could not open output file: %s\n" % e)
97 97 sys.exit(1)
98 98 else:
99 99 fh = sys.stdout
100 100
101 101 fh.write("HG_PARENT=%s\n" % parenttip)
102 102
103 103 entries = [i for i in act]
104 104 entries.sort()
105 105
106 106 for entry in entries:
107 107 if entry.is_renamed() or entry.is_copied():
108 108 fh.write("%s %s\n" % (entry.name, entry.parentname))
109 109 else:
110 110 fh.write("%s\n" % entry.name)
111 111
112 112 # Strip blank lines.
113 113 comments = filter(lambda x: x and not x.isspace(),
114 114 entry.comments)
115 115
116 116 fh.write('\n')
117 117 if comments:
118 118 fh.write('%s\n' % '\n'.join(comments))
119 119 else:
120 120 fh.write("*** NO COMMENTS ***\n")
121 121 fh.write('\n')
122 122
123 123 if __name__ == '__main__':
124 124 try:
125 125 main(sys.argv[1:])
126 126 except KeyboardInterrupt:
127 127 sys.exit(1)
128 128 except util.Abort, msg:
129 129 sys.stderr.write("Abort: %s\n" % msg)
130 130 sys.exit(1)
↓ open down ↓ |
119 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX