-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmake_versions_file
executable file
·96 lines (71 loc) · 2.23 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
89
90
91
92
93
94
95
96
#!/usr/bin/env python
"""
Aim:
Create a data file representing the version strings in /soft/ciao
Usage:
./make_versions_file
Output:
Screen
Will often 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_version.
"""
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(f"Expected 1 line for {fname} but read in:\n{cts}")
return cts[0]
def package_name(fname):
"""Return the package name for the given file name"""
if fname == "VERSION":
return "CIAO"
if fname == "VERSION.CIAO_scripts":
return "contrib"
# if fname.find("_") != -1:
# return fname.split("_")[-1]
raise ValueError(f"Unrecognized file name: {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
# The use of glob.glob now that we only have fixed names is a bit
# ugly, but it still works.
#
ciao = os.path.expandvars("$ASCDS_INSTALL")
vbase = glob.glob(ciao + "/VERSION")
if vbase == []:
raise IOError("Unable to find $ASCDS_INSTALL/VERSION")
# As of CIAO 4.16 it looks like we don't have the other "components"
# to worry about. Well, there's VERSION_obsvis but this is now
# part of CIAO so there is no need to include it.
#
# vfiles = glob.glob(ciao + "/VERSION_*")
# if vfiles == []:
# raise IOError("Unable to find $ASCDS_INSTALL/VERSION_*")
#
vfiles = []
# allow missing contrib file since we can always add this info in manually
# later
cfile = glob.glob(ciao + "/VERSION.CIAO_scripts")
if len(cfile) > 1:
raise IOError(f"Expected 1 entry for contrib VERSION file, found: {cfile}")
l = len(ciao) + 1
for vfile in vbase + vfiles + cfile:
v = read_vfile(vfile)
pname = package_name(vfile[l:])
print(f"{pname} {v}")
if __name__ == "__main__":
doit()