Repository navigation
Expand file tree
/
Copy pathcheck_libs.py
More file actions
executable file
·173 lines (135 loc) · 5.29 KB
/
Copy pathcheck_libs.py
File metadata and controls
executable file
·173 lines (135 loc) · 5.29 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
#===========================================================================
#
# Check that all libs are installed
#
#===========================================================================
from __future__ import print_function
import os
import time
import sys
import shutil
from optparse import OptionParser
from datetime import datetime
def main():
global options
global requiredLibs
global requiredLibsLine
global missingLibs
global oldLibs
global thisScriptName
thisScriptName = os.path.basename(__file__)
# parse the command line
usage = "usage: %prog [options]"
# homeDir = os.environ['HOME']
parser = OptionParser(usage)
parser.add_option('--debug',
dest='debug', default=False,
action="store_true",
help='Set debugging on')
parser.add_option('--libDir',
dest='libDir', default='.',
help='Dir with installed libs')
parser.add_option('--listPath',
dest='listPath', default='.',
help='Path with requried list')
parser.add_option('--label',
dest='label', default="LROSE",
help='Label for messages')
parser.add_option('--maxAge',
dest='maxAge', default=900,
help='Max file age in secs')
(options, args) = parser.parse_args()
if (options.debug == True):
print("Running %s:" % thisScriptName, file=sys.stderr)
print(" libDir:", options.libDir, file=sys.stderr)
print(" listPath:", options.listPath, file=sys.stderr)
print(" label:", options.label, file=sys.stderr)
print(" maxAge:", options.maxAge, file=sys.stderr)
# read in required list
if (readRequiredList(options.listPath) != 0):
sys.exit(255)
# check required files exist
checkForLibs()
if (len(missingLibs) > 0):
print("==================>> ERROR <<====================", file=sys.stderr)
print("=====>> INCOMPLETE " + options.label + " LIBS INSTALLATION <<====", file=sys.stderr)
print(" n libraries missing: " + str(len(missingLibs)), file=sys.stderr)
for index, lib in enumerate(missingLibs):
print(" missing lib: " + requiredLibsLine[lib], file=sys.stderr)
else:
print("=================>> SUCCESS <<===================", file=sys.stderr)
print("=========>> ALL " + options.label + " LIBS INSTALLED <<========", file=sys.stderr)
if (len(oldLibs) > 0):
print("=================>> WARNING <<===================", file=sys.stderr)
print("===========>> SOME " + options.label + " LIBS ARE OLD <<=========", file=sys.stderr)
print(" n old libs: " + str(len(oldLibs)), file=sys.stderr)
print(" These libs may not have been built", file=sys.stderr)
for lib in oldLibs:
print(" lib out-of-date: " + lib, file=sys.stderr)
print("=================================================", file=sys.stderr)
sys.exit(0)
########################################################################
# read in required list
def readRequiredList(path):
global requiredLibs
global requiredLibsLine
requiredLibs = []
requiredLibsLine = {}
try:
fp = open(path, 'r')
except IOError as e:
print("ERROR - ", thisScriptName, file=sys.stderr)
print(" Cannot open lib list file:", path, file=sys.stderr)
return -1
lines = fp.readlines()
fp.close()
for line in lines:
line = line.strip()
if (len(line) < 1):
continue
if (line[0] == '#'):
continue
toks = line.split(" ")
if (len(toks) > 0):
libName = toks[0]
requiredLibs.append(libName)
requiredLibsLine[libName] = line
if (options.debug == True):
print("Required libs:", file=sys.stderr)
for name in requiredLibs:
print(" ", requiredLibsLine[name], file=sys.stderr)
return 0
########################################################################
# check that the lib list is installed
def checkForLibs():
global missingLibs
global oldLibs
missingLibs = []
oldLibs = []
for name in requiredLibs:
path = os.path.join(options.libDir, name)
if (options.debug == True):
print("Checking for installed lib: ", path, file=sys.stderr)
if (os.path.isfile(path) == False):
if (options.debug == True):
print(" .... missing", file=sys.stderr)
missingLibs.append(name)
else:
if (options.debug == True):
print(" .... found", file=sys.stderr)
age = getFileAge(path)
if (age > float(options.maxAge)):
oldLibs.append(name)
if (options.debug == True):
print(" file is old, age: ", age, file=sys.stderr)
########################################################################
# get file age
def getFileAge(path):
stats = os.stat(path)
age = (time.time() - stats.st_mtime)
return age
########################################################################
# Run - entry point
if __name__ == "__main__":
main()