1 |
|
#!/home/jsoc/bin/linux_x86_64/activepython |
2 |
+ |
|
3 |
+ |
# Run like this: |
4 |
+ |
# CM/tagRelease.py -t /home/jsoc/cvs/Development/waystation/JSOC_9.4.1_beta -v 9.41 |
5 |
+ |
# |
6 |
+ |
# -t is a HEAD check-out of the CVS tree; the file jsoc_version.h will be edited, and the tree will then be tagged with the release version specified in the `-v` argument |
7 |
+ |
# -v is a version string with a single '.' |
8 |
|
import sys, getopt |
9 |
|
import re |
10 |
|
import os |
25 |
|
|
26 |
|
# Classes |
27 |
|
|
28 |
< |
# This class changes the current working directory, and restores the original working directory when |
28 |
> |
# This class changes the current working directory, and restores the original working directory when |
29 |
|
# the context is left. |
30 |
|
class Chdir: |
31 |
|
"""Context manager for changing the current working directory""" |
32 |
|
def __init__(self, newPath): |
33 |
|
self.newPath = os.path.realpath(newPath) |
34 |
< |
|
34 |
> |
|
35 |
|
def __enter__(self): |
36 |
|
self.savedPath = os.path.realpath(os.getcwd()) |
37 |
|
os.chdir(self.newPath) |
40 |
|
return 0 |
41 |
|
else: |
42 |
|
return 1 |
43 |
< |
|
43 |
> |
|
44 |
|
def __exit__(self, etype, value, traceback): |
45 |
|
os.chdir(self.savedPath) |
46 |
|
cdir = os.path.realpath(os.getcwd()) |
56 |
|
|
57 |
|
# tag by defuault |
58 |
|
optD['untag'] = 0 |
59 |
< |
|
59 |
> |
|
60 |
|
try: |
61 |
|
opts, remainder = getopt.getopt(args,"ht:uv:",["tree=", "version="]) |
62 |
|
except getopt.GetoptError: |
94 |
|
return optD |
95 |
|
|
96 |
|
# Create version strings for jsoc_version.h and CVS, returns a tuple |
97 |
< |
# containing either the two release strings (e.g., ("V8R1", "(801)", "8-1")), |
97 |
> |
# containing either the two release strings (e.g., ("V8R1", "(801)", "8-1")), |
98 |
|
# or the two development strings (e.g., ("V8R1X", "(-801)", "8-1")). The |
99 |
< |
# third member of the tuple is always "8-1". Which |
99 |
> |
# third member of the tuple is always "8-1". Which |
100 |
|
# tuple is returned is controlled by the 'dev' argument |
101 |
|
def CreateVersString(versin, dev): |
102 |
|
regexp = re.compile(r"(\d+)\.(\d+)") |
103 |
|
matchobj = regexp.match(versin) |
104 |
< |
|
104 |
> |
|
105 |
|
if not(matchobj is None): |
106 |
|
try: |
107 |
|
maj = matchobj.group(1) |
109 |
|
except IndexError: |
110 |
|
print('Invalid regexp group number.') |
111 |
|
return None |
112 |
< |
|
112 |
> |
|
113 |
|
tagstring = maj + "-" + min |
114 |
< |
|
114 |
> |
|
115 |
|
if dev == 0: |
116 |
|
return ("V" + maj + "R" + min, "(" + maj + "{0:02d}".format(int(min)) + ")", tagstring) |
117 |
|
else: |
121 |
|
|
122 |
|
def EditVersionFile(versfile, verstuple): |
123 |
|
rv = kRetSuccess |
124 |
< |
|
124 |
> |
|
125 |
|
try: |
126 |
< |
with open(versfile, 'r') as fin, open(kTmpFile, 'w') as fout: |
126 |
> |
with open(versfile, 'r') as fin, open(kTmpFile, 'w') as fout: |
127 |
|
regexp1 = re.compile(r"#define\s+jsoc_version\s+\"\w+\"") |
128 |
|
regexp2 = re.compile(r"#define\s+jsoc_vers_num\s+\(\-?\d+\)") |
129 |
< |
|
129 |
> |
|
130 |
|
for line in fin: |
131 |
|
matchobj1 = regexp1.match(line) |
132 |
|
matchobj2 = regexp2.match(line) |
167 |
|
|
168 |
|
if __name__ == "__main__": |
169 |
|
optD = GetArgs(sys.argv[1:]) |
170 |
< |
|
170 |
> |
|
171 |
|
if not(optD is None): |
172 |
|
if not(optD['version'] is None) and not(optD['untag'] is None): |
173 |
|
regexp = re.compile(r"(.+)/\s*$") |
176 |
|
tree = matchobj.group(1) |
177 |
|
else: |
178 |
|
tree = optD['tree'] |
179 |
+ |
|
180 |
+ |
# `tree` is used for editing jsoc_version.h only; the file in this tree is edited (twice - once for the release tag and once for the development tag) and then checked in; |
181 |
+ |
# `tree` should be a HEAD version CVS tree; the file is edited with the release-tag content, committed, tagged with the release tag, edited with the dev tag, and then checked in; |
182 |
|
version = optD['version'] |
183 |
|
untag = optD['untag'] |
184 |
|
versfile = tree + '/' + kVersFile |
185 |
|
verstuple = CreateVersString(version, 0) |
186 |
< |
|
186 |
> |
|
187 |
|
if verstuple is None: |
188 |
|
print('Invalid version string ' + version) |
189 |
|
rv = kRetArgs |
191 |
|
if rv == kRetSuccess: |
192 |
|
# Edit jsoc_version.h - set the release version of the version numbers. |
193 |
|
rv = EditVersionFile(versfile, verstuple) |
194 |
< |
|
194 |
> |
|
195 |
|
if rv == kRetSuccess: |
196 |
|
# Commit jsoc_version.h back to CVS |
197 |
|
try: |
208 |
|
except ValueError: |
209 |
|
print('Unable to run cvs cmd: ' + cmd + '.') |
210 |
|
rv = kRetOS |
211 |
< |
|
211 |
> |
|
212 |
|
if not(ret == 0): |
213 |
|
print('cvs command ' + cmd + ' ran improperly.') |
214 |
|
rv = kRetOS |
217 |
|
print('Successfully edited ' + versfile + '; set release version.') |
218 |
|
# Create the tags |
219 |
|
try: |
220 |
< |
# Untag existing tags (if they exist). If the tag does not exist, then |
221 |
< |
# no error is returned. Calling dlsource.pl is a bit inefficient since |
213 |
< |
# each time a new CVS tree is downloaded. |
214 |
< |
|
220 |
> |
# untag existing tags (if they exist); if the tag does not exist, then no error is returned; calling dlsource.pl is a bit inefficient since each time a new CVS tree is downloaded; dlsource.pl downloads the HEAD tree into a temp dir before untagging; |
221 |
> |
|
222 |
|
# Full DRMS-release tags |
223 |
|
cmd = '/home/jsoc/dlsource.pl -o untag -f sdp -t Ver_' + verstuple[2] |
224 |
|
ret = call(cmd, shell=True) |
231 |
|
if not(ret == 0): |
232 |
|
print('ERROR: Unable to delete tag Ver_LATEST') |
233 |
|
rv = kRetOS |
234 |
< |
|
234 |
> |
|
235 |
|
# NetDRMS-release tags |
236 |
|
if rv == kRetSuccess: |
237 |
|
cmd = '/home/jsoc/dlsource.pl -o untag -f net -t NetDRMS_Ver_' + verstuple[2] |
245 |
|
if not(ret == 0): |
246 |
|
print('ERROR: Unable to delete tag NetDRMS_Ver_LATEST') |
247 |
|
rv = kRetOS |
248 |
< |
|
248 |
> |
|
249 |
|
# Create new tags |
250 |
+ |
# dlsource.pl downloads the HEAD tree into a temp dir before tagging |
251 |
|
|
252 |
|
# Full DRMS-release tags |
253 |
|
if rv == kRetSuccess: |
292 |
|
if rv == kRetSuccess: |
293 |
|
# Edit jsoc_version.h - set the development version of the version numbers. |
294 |
|
rv = EditVersionFile(versfile, verstuple) |
295 |
< |
|
295 |
> |
|
296 |
|
if rv == kRetSuccess: |
297 |
|
# Commit jsoc_version.h back to CVS |
298 |
|
try: |