-
Notifications
You must be signed in to change notification settings - Fork 6
/
make_versions_file
executable file
·88 lines (62 loc) · 1.96 KB
/
make_versions_file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
"""
Aim:
Create a data file representing the version strings in /soft/ciao
Usage:
./make_versions_file
Output:
Screen
Will oftern be used
./make_versions_file > ciao_versions.dat
"""
import os
import glob
from optparse import OptionParser
help_str = """
Create the data file used by check_ciao_caldb.
"""
def read_vfile(fname):
fh = open(fname, "r")
cts = fh.readlines()
fh.close()
# may have blank lines
cts = [l.strip() for l in cts if l.strip() != ""]
if len(cts) != 1:
raise IOError("Expected 1 line for {0} but read in:\n{1}".format(fname, cts))
return cts[0]
def package_name(fname):
"""Return the package name for the given file name"""
if fname == "VERSION":
return "CIAO"
elif fname == "contrib/VERSION.CIAO_scripts":
return "contrib"
elif fname.find("_") != -1:
return fname.split("_")[-1]
else:
raise ValueError("Unrecognized file name: {0}".format(fname))
def doit():
"""Run the code."""
opts = OptionParser(usage="%prog",
description=help_str)
(options, args) = opts.parse_args()
if len(args) != 0:
opts.print_help()
return
ciao = os.path.expandvars("$ASCDS_INSTALL")
vbase = glob.glob(ciao + "/VERSION")
if vbase == []:
raise IOError("Unable to find $ASCDS_INSTALL/VERSION")
vfiles = glob.glob(ciao + "/VERSION_*")
if vfiles == []:
raise IOError("Unable to find $ASCDS_INSTALL/VERSION_*")
# allow missing contrib file since we can always add this info in manually
# later
cfile = glob.glob(ciao + "/contrib/VERSION*")
if len(cfile) > 1:
raise IOError("Expected 1 entry for contrib VERSION file, found: {0}".format(cfile))
l = len(ciao) + 1
for vfile in vbase + vfiles + cfile:
v = read_vfile(vfile)
print("{0} {1}".format(package_name(vfile[l:]), v))
if __name__ == "__main__":
doit()