casaconfig 1.2.0__py3-none-any.whl → 1.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- casaconfig/__init__.py +7 -0
- casaconfig/config.py +34 -21
- casaconfig/private/config_defaults.py +4 -2
- casaconfig/private/config_defaults_static.py +22 -0
- casaconfig/private/data_available.py +17 -37
- casaconfig/private/data_update.py +22 -26
- casaconfig/private/do_auto_updates.py +4 -3
- casaconfig/private/do_pull_data.py +7 -27
- casaconfig/private/do_untar_url.py +94 -0
- casaconfig/private/get_available_files.py +94 -0
- casaconfig/private/get_data_info.py +35 -20
- casaconfig/private/measures_available.py +212 -36
- casaconfig/private/measures_update.py +179 -126
- casaconfig/private/print_log_messages.py +7 -3
- casaconfig/private/pull_data.py +11 -6
- casaconfig/private/read_readme.py +57 -13
- casaconfig/private/set_casacore_path.py +2 -2
- casaconfig/private/summary.py +3 -0
- casaconfig/private/update_all.py +6 -5
- casaconfig-1.4.0.dist-info/METADATA +92 -0
- casaconfig-1.4.0.dist-info/RECORD +34 -0
- {casaconfig-1.2.0.dist-info → casaconfig-1.4.0.dist-info}/WHEEL +1 -1
- tests/test_casaconfig.py +190 -17
- casaconfig-1.2.0.dist-info/METADATA +0 -293
- casaconfig-1.2.0.dist-info/RECORD +0 -32
- {casaconfig-1.2.0.dist-info → casaconfig-1.4.0.dist-info}/licenses/LICENSE +0 -0
- {casaconfig-1.2.0.dist-info → casaconfig-1.4.0.dist-info}/top_level.txt +0 -0
@@ -15,25 +15,29 @@
|
|
15
15
|
this module will be included in the api
|
16
16
|
"""
|
17
17
|
|
18
|
-
def measures_update(path=None, version=None, force=False, logger=None, auto_update_rules=False, use_astron_obs_table=False, verbose=None):
|
18
|
+
def measures_update(path=None, version=None, force=False, measures_site=None, logger=None, auto_update_rules=False, use_astron_obs_table=False, verbose=None):
|
19
19
|
"""
|
20
|
-
Update or install the IERS data used for measures calculations from
|
20
|
+
Update or install the IERS data used for measures calculations from measures_site into path.
|
21
21
|
|
22
|
-
Original data source used by
|
22
|
+
Original IERS data source used by each of the recommended measures sites
|
23
|
+
is here: https://www.iers.org/IERS/EN/DataProducts/data.html
|
23
24
|
|
24
25
|
If no update is necessary then this function will silently return.
|
25
26
|
|
26
|
-
The verbose argument controls the level of information provided
|
27
|
-
are unchanged for expected reasons. A level of 0
|
28
|
-
value of 1
|
27
|
+
The verbose argument controls the level of information provided by this function when the data
|
28
|
+
are unchanged for expected reasons. A level of 0 outputs nothing. A
|
29
|
+
value of 1 sends any output to the logger and a value of 2 logs and prints the information.
|
30
|
+
The default value of the verbose argument is taken from the casaconfig_verbose config
|
31
|
+
value (defaults to 1). Error messages are always logged and printed.
|
29
32
|
|
30
33
|
CASA maintains a separate Observatories table which is available in the casarundata
|
31
|
-
collection through pull_data and data_update. The Observatories table found at
|
34
|
+
collection through pull_data and data_update. The Observatories table found at measures_site
|
32
35
|
is not installed by measures_update and any Observatories file at path will not be changed
|
33
|
-
by using this function.
|
36
|
+
by using this function. This behavior can be changed by setting force and use_astron_obs_table
|
37
|
+
both to True (use_astron_obs_table is ignored when force is False).
|
34
38
|
|
35
|
-
A text file (readme.txt in the geodetic directory in path) records the measures version string
|
36
|
-
and the date when that version was installed in path.
|
39
|
+
A text file (readme.txt in the geodetic directory in path) records the measures version string,
|
40
|
+
the measures site that was used and the date when that version was installed in path.
|
37
41
|
|
38
42
|
If path is None then config.measurespath is used.
|
39
43
|
|
@@ -41,12 +45,26 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
41
45
|
nothing unless force is True.
|
42
46
|
|
43
47
|
If a specific version is not requested (the default) and the modification time of that text
|
44
|
-
file is less than
|
45
|
-
function checks for a more recent version and finds
|
46
|
-
|
47
|
-
changed
|
48
|
-
|
49
|
-
|
48
|
+
file is less than the measures_update_interval config value (days) before now then this function
|
49
|
+
does nothing unless force is True. When this function checks for a more recent version and finds
|
50
|
+
that the installed version is the most recent one then the modification time of that text file
|
51
|
+
is changed to the current time even though nothing has changed in path. This limits the
|
52
|
+
number of attempts to update the measures data (including checking
|
53
|
+
for more recent data) to once every measures_update_interval days. When the force argument
|
54
|
+
is True and a specific version is not requested then this function always checks for the
|
55
|
+
latest version. The measures_update_interval is always used as an int type (including
|
56
|
+
any truncation of the actual value in config if not an integer).
|
57
|
+
|
58
|
+
The measures_site is a single URL or a list of URLs to use to find the measures tar file
|
59
|
+
to use in the update. See measures_available for more details on how that parameter
|
60
|
+
is used.
|
61
|
+
|
62
|
+
If a specific version is requested then that must match a file in the list returned
|
63
|
+
by measures_available. The version is usually unique at each measures_site and so care
|
64
|
+
may need to be taken when requesting a specific version to ensure that it's available at
|
65
|
+
measures_site. If measures_site is a list and a specific version is requested then
|
66
|
+
measures_update will try and find that version in each measures_site in that list, using
|
67
|
+
the first site that has that version.
|
50
68
|
|
51
69
|
When auto_update_rules is True then path must exist and contain the expected readme.txt file.
|
52
70
|
Path must be owned by the user, force must be False, and the version must be None. This
|
@@ -75,11 +93,11 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
75
93
|
especially if they may also be starting at that time. If a specific version is
|
76
94
|
requested or force is True there is a risk that the measures may be updated while
|
77
95
|
one of those other sessions are trying to load the same measures data, leading to
|
78
|
-
unpredictable results. The lock file will prevent
|
79
|
-
happening but if each
|
96
|
+
unpredictable results. The lock file will prevent simultaneous updates from
|
97
|
+
happening but if each simultaneous update eventually updates the same measures
|
80
98
|
location (because force is True or the updates are requesting different versions)
|
81
|
-
then the measures that any of those
|
82
|
-
unpredictable. Avoid multiple,
|
99
|
+
then the measures that any of those simultaneous casatools modules sees is
|
100
|
+
unpredictable. Avoid multiple, simultaneous updates outside of the automatic
|
83
101
|
update process.
|
84
102
|
|
85
103
|
**Note:** during auto updates, measures_update requires that the expected
|
@@ -91,10 +109,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
91
109
|
read and write permissions there). The version must then also be None and the force option
|
92
110
|
must be False.
|
93
111
|
|
94
|
-
**Note
|
112
|
+
**Note:** During use outside of auto updates, if path does not exist it will be created
|
95
113
|
by this function.
|
96
114
|
|
97
|
-
**
|
115
|
+
**Note:** During use outside of auto updates, if the readme.txt file exists but can not
|
98
116
|
be read as expected **OR** that file does not exist but the contents of path appear to
|
99
117
|
contain measures data (table names in the expected locations) then this function will
|
100
118
|
print messages describing that and exit without changing anything at path. Using
|
@@ -104,39 +122,35 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
104
122
|
|
105
123
|
Parameters
|
106
124
|
- path (str=None) - Folder path to place updated measures data. Must contain a valid geodetic/readme.txt. If not set then config.measurespath is used.
|
107
|
-
- version (str=None) - Version of measures data to retrieve (usually in the form of
|
125
|
+
- version (str=None) - Version of measures data to retrieve (usually in the form of WSRT_Measures_yyyymmdd-160001.ztar, see measures_available). Default None retrieves the latest.
|
108
126
|
- force (bool=False) - If True, always re-download the measures data. Default False will not download measures data if updated within the past day unless the version parameter is specified and different from what was last downloaded.
|
127
|
+
- measures_site(str or list of str = None) - Each value is a URL where measures tar files are found. If measures_site is a list then the elements are used in order until a list can be assembled. Default None uses config.measures_site.
|
109
128
|
- logger (casatools.logsink=None) - Instance of the casalogger to use for writing messages. Default None writes messages to the terminal
|
110
129
|
- auto_update_rules (bool=False) - If True then the user must be the owner of path, version must be None, and force must be False.
|
111
|
-
-
|
130
|
+
- use_astron_obs_table (bool=False) - If True and force is also True then keep the Observatories table found in the Measures tar tarball (possibly overwriting the Observatories table from casarundata).
|
131
|
+
- verbose (int=None) - Level of output, 0 is none, 1 is to logger, 2 is to logger and terminal, defaults to config.casaconfig_verbose.
|
112
132
|
|
113
133
|
Returns
|
114
134
|
None
|
115
135
|
|
116
136
|
Raises
|
117
|
-
casaconfig.AutoUpdatesNotAllowed - raised when path does not exists as a directory or is not owned by the user when auto_update_rules is True
|
118
|
-
casaconfig.BadLock - raised when the lock file was not empty when found
|
119
|
-
casaconfig.BadReadme - raised when something unexpected is found in the readme or the readme changed after an update is in progress
|
120
|
-
casaconfig.NoReadme - raised when the readme.txt file is not found at path (path also may not exist)
|
121
|
-
casaconfig.NotWritable - raised when the user does not have permission to write to path
|
122
|
-
casaconfig.NoNetwork - raised by measuers_available or when getting the lock file if there is no network.
|
123
|
-
casaconfig.RemoteError - raised by measures_available when the remote list of measures could not be fetched, not due to no network.
|
124
|
-
casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
|
125
|
-
Exception - raised when something unexpected happened while updating measures
|
137
|
+
- casaconfig.AutoUpdatesNotAllowed - raised when path does not exists as a directory or is not owned by the user when auto_update_rules is True
|
138
|
+
- casaconfig.BadLock - raised when the lock file was not empty when found
|
139
|
+
- casaconfig.BadReadme - raised when something unexpected is found in the readme or the readme changed after an update is in progress
|
140
|
+
- casaconfig.NoReadme - raised when the readme.txt file is not found at path (path also may not exist)
|
141
|
+
- casaconfig.NotWritable - raised when the user does not have permission to write to path
|
142
|
+
- casaconfig.NoNetwork - raised by measuers_available or when getting the lock file if there is no network.
|
143
|
+
- casaconfig.RemoteError - raised by measures_available when the remote list of measures could not be fetched, not due to no network.
|
144
|
+
- casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
|
145
|
+
- Exception - raised when something unexpected happened while updating measures
|
126
146
|
|
127
147
|
"""
|
128
148
|
import os
|
129
|
-
import pkg_resources
|
130
149
|
from datetime import datetime
|
131
150
|
import sys
|
132
151
|
|
133
|
-
from ftplib import FTP
|
134
152
|
import tarfile
|
135
153
|
import re
|
136
|
-
import ssl
|
137
|
-
import urllib.request
|
138
|
-
import certifi
|
139
|
-
import fcntl
|
140
154
|
|
141
155
|
from casaconfig import measures_available
|
142
156
|
from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme, NoNetwork
|
@@ -145,16 +159,20 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
145
159
|
from .get_data_lock import get_data_lock
|
146
160
|
from .get_data_info import get_data_info
|
147
161
|
from .measures_available import measures_available
|
148
|
-
|
162
|
+
from .do_untar_url import do_untar_url
|
163
|
+
|
164
|
+
from .. import config as _config
|
165
|
+
|
149
166
|
if path is None:
|
150
|
-
from .. import config as _config
|
151
167
|
path = _config.measurespath
|
152
168
|
|
153
169
|
if path is None:
|
154
170
|
raise UnsetMeasurespath('measures_update: path is None and has not been set in config.measurespath. Provide a valid path and retry.')
|
155
171
|
|
172
|
+
if measures_site is None:
|
173
|
+
measures_site = _config.measures_site
|
174
|
+
|
156
175
|
if verbose is None:
|
157
|
-
from .. import config as _config
|
158
176
|
verbose = _config.casaconfig_verbose
|
159
177
|
|
160
178
|
path = os.path.expanduser(path)
|
@@ -173,42 +191,52 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
173
191
|
# make dirs all the way down, if possible
|
174
192
|
os.makedirs(path)
|
175
193
|
|
176
|
-
|
194
|
+
currentVersion = None
|
177
195
|
ageRecent = False
|
196
|
+
currentSite = None
|
178
197
|
|
179
198
|
# first, does this look like it needs to be updated
|
180
199
|
|
181
200
|
# get any existing measures readme information
|
182
201
|
readmeInfo = get_data_info(path, logger, type='measures')
|
183
202
|
if readmeInfo is not None:
|
184
|
-
|
203
|
+
currentVersion = readmeInfo['version']
|
204
|
+
currentSite = readmeInfo['site']
|
185
205
|
if readmeInfo['age'] is not None:
|
186
|
-
ageRecent = readmeInfo['age'] <
|
206
|
+
ageRecent = readmeInfo['age'] < int(_config.measures_update_interval)
|
187
207
|
|
188
208
|
if not force:
|
189
|
-
# don't check for new version if the age is less than
|
209
|
+
# don't check for new version if the age is less than measures_update_interval days
|
190
210
|
if version is None and ageRecent:
|
191
|
-
|
192
|
-
print_log_messages('measures_update: version installed or checked less than 1 day ago, nothing updated or checked', logger, verbose=verbose)
|
211
|
+
print_log_messages('measures_update: version installed or checked less than %s day(s) ago, nothing updated or checked' % int(_config.measures_update_interval), logger, verbose=verbose)
|
193
212
|
return
|
194
213
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
214
|
+
if currentVersion is not None:
|
215
|
+
# don't overwrite something that looks bad unless forced to do so
|
216
|
+
if 'invalid' in currentVersion:
|
217
|
+
raise NoReadme('measures_update: no measures readme.txt file found at %s. Nothing updated or checked.' % path)
|
218
|
+
|
219
|
+
if 'error' in currentVersion:
|
220
|
+
msg = "measures_update: the measures readme.txt file at %s could not be read as expected, an update can not proceed unless force is True" % path
|
221
|
+
# add any additional error message, anything after the first ":" if is found
|
222
|
+
colonIndex = currentVersion.find(":")
|
223
|
+
if colonIndex != -1:
|
224
|
+
msg += "; " + currentVersion[colonIndex+1:]
|
225
|
+
raise BadReadme(msg)
|
226
|
+
|
227
|
+
# don't overwrite something that looks like valid measures data unless forced to do so
|
228
|
+
if 'unknown' in currentVersion:
|
229
|
+
print_log_messages('measures_update: the measures data at %s is not maintained by casaconfig and so it can not be updated unless force is True' % path, logger, True)
|
230
|
+
return
|
206
231
|
|
207
232
|
checkVersion = version
|
208
233
|
if checkVersion is None:
|
209
234
|
# get the current most recent version
|
210
235
|
try:
|
211
|
-
|
236
|
+
# if measures_site is a list, measures_available will return the list from the appropriate site in that list
|
237
|
+
# that might not be the same site recorded with currentVersion, but that's OK for this update step
|
238
|
+
# the currentVersion is already old enough to trigger this check for a more recent version
|
239
|
+
checkVersion = measures_available(measures_site=measures_site)[-1]
|
212
240
|
except NoNetwork as exc:
|
213
241
|
# no network, no point in continuing, just reraise
|
214
242
|
raise exc
|
@@ -217,12 +245,14 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
217
245
|
raise exc
|
218
246
|
except:
|
219
247
|
# unsure what happened, leave it at none, which will trigger an update attempt, which might work
|
248
|
+
print("unexpected excption in measuress_available")
|
249
|
+
import traceback
|
250
|
+
traceback.print_exc()
|
220
251
|
pass
|
221
252
|
|
222
253
|
# don't re-download the same data
|
223
|
-
if (checkVersion is not None) and (checkVersion ==
|
224
|
-
|
225
|
-
print_log_messages('measures_update: requested version already installed in %s' % path, logger, verbose=verbose)
|
254
|
+
if (checkVersion is not None) and (checkVersion == currentVersion):
|
255
|
+
print_log_messages('measures_update: requested version already installed in %s' % path, logger, verbose=verbose)
|
226
256
|
# update the age of the readme to now
|
227
257
|
readme_path = os.path.join(path,'geodetic/readme.txt')
|
228
258
|
# readme_path should already exist if it's here
|
@@ -236,7 +266,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
236
266
|
msgs = []
|
237
267
|
msgs.append("Error: the Observatories table was not found as expected in %s" % path)
|
238
268
|
msgs.append("Either install casarundata first or set use_astron_obs_table and force to be True when using measures_update.")
|
239
|
-
msgs.append("Note that the Observatories table provided in the
|
269
|
+
msgs.append("Note that the Observatories table provided in the measures tarfile is not the same as that maintained by CASA")
|
240
270
|
print_log_messages(msgs, logger, True)
|
241
271
|
return
|
242
272
|
|
@@ -248,9 +278,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
248
278
|
|
249
279
|
# lock the measures_update.lock file
|
250
280
|
lock_fd = None
|
251
|
-
clean_lock = True # set to false if the contents are actively being
|
281
|
+
clean_lock = True # set to false if the contents are actively being update and the lock file should not be cleaned one exception
|
252
282
|
try:
|
253
|
-
print_log_messages('measures_update ... acquiring the lock ... ', logger)
|
283
|
+
print_log_messages('measures_update ... acquiring the lock ... ', logger, verbose=verbose)
|
254
284
|
|
255
285
|
# the BadLock exception that may happen here is caught below
|
256
286
|
lock_fd = get_data_lock(path, 'measures_update')
|
@@ -259,21 +289,19 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
259
289
|
|
260
290
|
if not do_update:
|
261
291
|
# recheck the readme file, another update may have already happened before the lock was obtained
|
262
|
-
|
292
|
+
currentVersion = None
|
263
293
|
ageRecent = False
|
264
294
|
|
265
295
|
readmeInfo = get_data_info(path, logger, type='measures')
|
266
296
|
if readmeInfo is not None:
|
267
|
-
|
297
|
+
currentVersion = readmeInfo['version']
|
268
298
|
if readmeInfo['age'] is not None:
|
269
|
-
ageRecent = readmeInfo['age'] <
|
299
|
+
ageRecent = readmeInfo['age'] < int(_config.measures_update_interval)
|
270
300
|
|
271
|
-
if (version is not None) and (version ==
|
272
|
-
|
273
|
-
print_log_messages('The requested measures version is already installed in %s, using version %s' % (path, current), logger)
|
301
|
+
if (version is not None) and (version == currentVersion):
|
302
|
+
print_log_messages('The requested measures version is already installed in %s, using version %s' % (path, currentVersion), logger, verbose=verbose)
|
274
303
|
elif (version is None) and ageRecent:
|
275
|
-
|
276
|
-
print_log_messages('The latest measures version was checked recently in %s, using version %s' % (path, current), logger)
|
304
|
+
print_log_messages('The latest measures version was checked recently in %s, using version %s' % (path, currentVersion), logger, verbose=verbose)
|
277
305
|
else:
|
278
306
|
# final check for problems before updating
|
279
307
|
if not force and readmeInfo is not None and (version=='invalid' or version=='unknown'):
|
@@ -288,69 +316,86 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
288
316
|
|
289
317
|
if do_update:
|
290
318
|
if force:
|
291
|
-
print_log_messages('A measures update has been requested by the force argument', logger)
|
292
|
-
|
293
|
-
print_log_messages(' ...
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
319
|
+
print_log_messages('A measures update has been requested by the force argument', logger, verbose=verbose)
|
320
|
+
|
321
|
+
print_log_messages(' ... finding available measures ...', logger, verbose=verbose)
|
322
|
+
|
323
|
+
target = None
|
324
|
+
site = None
|
325
|
+
|
326
|
+
# if a specific version has been request AND measures_site is a list with more than one value
|
327
|
+
# then find the site with that version in it. Turn off logging in measures_available calls
|
328
|
+
# here as the age of the site doesn't matter
|
329
|
+
if version is not None and isinstance(measures_site, list) and len(measures_site) > 1:
|
330
|
+
target = version
|
331
|
+
for this_site in measures_site:
|
332
|
+
files = measures_available(measures_site=this_site, logger=None)
|
333
|
+
# make sure that site is excluded from files before target is checked
|
334
|
+
files = files[1:]
|
335
|
+
if target in files:
|
336
|
+
site = this_site
|
337
|
+
break
|
338
|
+
if site is None:
|
339
|
+
print_log_messages("measures_update can't find specfied version %s at any of the sites in the measures_site list" % target, logger, True)
|
340
|
+
# else site and target are set
|
308
341
|
else:
|
309
|
-
#
|
310
|
-
|
311
|
-
if
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
342
|
+
# if measure_available sorts out what site to use if it's a list with more than one element
|
343
|
+
# a specific version probably needs to use a specific site to make it work
|
344
|
+
# if a specific version has been requested then the age of the site isn't an issue, turn logging off
|
345
|
+
this_logger = logger if version is None else None
|
346
|
+
files = measures_available(measures_site=measures_site, logger=this_logger)
|
347
|
+
site = files[0]
|
348
|
+
# this makes sure that the site is exclude from files before target is checked.
|
349
|
+
files = files[1:]
|
350
|
+
|
351
|
+
# target filename to download
|
352
|
+
# for the non-force unspecified version case this can only get here if the age is > 1 day so there should be a newer version
|
353
|
+
# but that isn't checked - this could install a version that's already installed
|
354
|
+
target = files[-1] if version is None else version
|
355
|
+
if target not in files:
|
356
|
+
print_log_messages("measures_update can't find specified version %s at site %s" % (target,site), logger, True)
|
357
|
+
# unset site here to signal nothing to extract
|
358
|
+
site = None
|
359
|
+
|
360
|
+
if site is not None:
|
361
|
+
# there are files to extract
|
362
|
+
print_log_messages(' ... downloading %s from %s to %s ...' % (target, site, path), logger, verbose=verbose)
|
363
|
+
|
364
|
+
# it's at this point that this code starts modifying what's there so the lock file should
|
365
|
+
# not be removed on failure from here on (until it succeeds)
|
366
|
+
clean_lock = False
|
367
|
+
|
320
368
|
# remove any existing measures readme.txt now in case something goes wrong during extraction
|
321
369
|
readme_path = os.path.join(path,'geodetic/readme.txt')
|
322
370
|
if os.path.exists(readme_path):
|
323
371
|
os.remove(readme_path)
|
324
372
|
|
325
|
-
#
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
ztar.close()
|
343
|
-
|
344
|
-
os.remove(ztarPath)
|
373
|
+
# custom filter that incorporates 'data_filter' to watch for dangerous members of the tar file
|
374
|
+
# this adds filtering to remove the Observatories table (unless use_astron_obs_table is True) and
|
375
|
+
# the *.old tables that may be in the geodetic tree
|
376
|
+
def custom_filter(member, extractionPath):
|
377
|
+
# member is a TarInfo instance and extractionPath is the destination path
|
378
|
+
# use the 'data_filter' first to deal with dangerous members
|
379
|
+
member = tarfile.data_filter(member, extractionPath)
|
380
|
+
# always exclude *.old names in geodetic
|
381
|
+
if (member is not None) and (re.search('geodetic',member.name) and re.search('.old',member.name)):
|
382
|
+
member = None
|
383
|
+
# the use_astron_obs_table argumen only has weight if force is True
|
384
|
+
if (not (force and use_astron_obs_table)) and (member is not None) and (re.search('Observatories',member.name)):
|
385
|
+
member = None
|
386
|
+
return member
|
387
|
+
|
388
|
+
# untar the target at site to path using the custom filter, do not be verbose
|
389
|
+
do_untar_url(site, target, path, custom_filter)
|
345
390
|
|
346
391
|
# create a new readme.txt file
|
347
392
|
with open(readme_path,'w') as fid:
|
348
|
-
|
349
|
-
|
350
|
-
print_log_messages(' ... measures data updated at %s' % path, logger)
|
393
|
+
# site added last to not break past readers of the measures readme
|
394
|
+
fid.write("# measures data populated by casaconfig\nversion : %s\ndate : %s\nsite : %s" % (target, datetime.today().strftime('%Y-%m-%d'),site))
|
351
395
|
|
352
396
|
clean_lock = True
|
353
|
-
|
397
|
+
print_log_messages(' ... measures data updated at %s' % path, logger, verbose=verbose)
|
398
|
+
|
354
399
|
# closing out the do_update
|
355
400
|
|
356
401
|
# closing out the try block
|
@@ -373,6 +418,14 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
373
418
|
msgs.append('Check for other updates in progress or choose a different path or clear out this path and reinstall the casarundata as well as the measures data')
|
374
419
|
print_log_messages(msgs, logger, True)
|
375
420
|
raise
|
421
|
+
|
422
|
+
except RemoteError as exc:
|
423
|
+
# probably an empty site
|
424
|
+
msgs = [str(exc)]
|
425
|
+
msgs.append('There was a remote error while attempting to update measures at %s' % path)
|
426
|
+
msgs.append('Check the value of measures_site and try again')
|
427
|
+
print_log_messages(msgs, logger, True)
|
428
|
+
raise
|
376
429
|
|
377
430
|
except Exception as exc:
|
378
431
|
msgs = []
|
@@ -30,13 +30,17 @@ def print_log_messages(msg, logger, is_err=False, verbose=2):
|
|
30
30
|
- msg (str) - The message to print and optionally log.
|
31
31
|
- logger (casatools.logsink) - Instance of the casalogger to use. Not used if None.
|
32
32
|
- is_err (bool=False) - When False, output goes to sys.stdout and logged as INFO level. When True, output goes to sys.stderr and logged as SEVERE
|
33
|
-
- verbose (int=2) -
|
33
|
+
- verbose (int=2) - 0 - do nothing, 1 log unless there is no logger, then print, 2 log and print
|
34
34
|
|
35
35
|
Returns
|
36
36
|
None
|
37
37
|
|
38
38
|
"""
|
39
39
|
|
40
|
+
if verbose == 0:
|
41
|
+
# do nothing
|
42
|
+
return
|
43
|
+
|
40
44
|
import sys
|
41
45
|
fileout = sys.stdout
|
42
46
|
loglevel = 'INFO'
|
@@ -48,8 +52,8 @@ def print_log_messages(msg, logger, is_err=False, verbose=2):
|
|
48
52
|
if type(msg) is not list:
|
49
53
|
msg = [msg]
|
50
54
|
|
51
|
-
#
|
52
|
-
if (logger is None) or (
|
55
|
+
# print if there is no logger or verbose >= 2
|
56
|
+
if (logger is None) or (verbose >= 2):
|
53
57
|
for m_msg in msg:
|
54
58
|
print(m_msg,file=fileout)
|
55
59
|
|
casaconfig/private/pull_data.py
CHANGED
@@ -22,6 +22,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
|
|
22
22
|
The verbose argument controls the level of information provided when this function when the data
|
23
23
|
are unchanged for expected reasons. A level of 0 prints and logs nothing. A
|
24
24
|
value of 1 logs the information and a value of 2 logs and prints the information.
|
25
|
+
Error messages are always logged and printed.
|
25
26
|
|
26
27
|
The path must either contain a previously installed version of casarundata
|
27
28
|
or it must not exist or be empty.
|
@@ -107,19 +108,23 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
|
|
107
108
|
|
108
109
|
from casaconfig import data_available
|
109
110
|
from casaconfig import get_data_info
|
110
|
-
from casaconfig import UnsetMeasurespath, BadLock, BadReadme, NotWritable
|
111
|
+
from casaconfig import UnsetMeasurespath, BadLock, BadReadme, NoNetwork, NotWritable, RemoteError
|
111
112
|
|
112
113
|
from .print_log_messages import print_log_messages
|
113
114
|
from .get_data_lock import get_data_lock
|
114
115
|
from .do_pull_data import do_pull_data
|
115
116
|
|
117
|
+
from .. import config as _config
|
118
|
+
|
116
119
|
if path is None:
|
117
|
-
from .. import config as _config
|
118
120
|
path = _config.measurespath
|
119
121
|
|
120
122
|
if path is None:
|
121
123
|
raise UnsetMeasurespath('path is None and has not been set in config.measurespath. Provide a valid path and retry.')
|
122
124
|
|
125
|
+
if verbose is None:
|
126
|
+
verbose = _config.casaconfig_verbose
|
127
|
+
|
123
128
|
# when a specific version is requested then the measures readme.txt that is part of that version
|
124
129
|
# will get a timestamp of now so that default measures updates won't happen for a day unless the
|
125
130
|
# force argument is used for measures_update
|
@@ -223,7 +228,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
|
|
223
228
|
lock_fd = None
|
224
229
|
clean_lock = True # set to False if the contents are actively being update and the lock file should not be cleaned on exception
|
225
230
|
try:
|
226
|
-
print_log_messages('pull_data using version %s, acquiring the lock ... ' % version, logger)
|
231
|
+
print_log_messages('pull_data using version %s, acquiring the lock ... ' % version, logger, verbose=verbose)
|
227
232
|
|
228
233
|
# attempting to get the lock will raise NoNetwork if there is no network and the lock will not be set, catch and reemit that in this try block
|
229
234
|
lock_fd = get_data_lock(path, 'pull_data')
|
@@ -248,13 +253,13 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
|
|
248
253
|
if measuresVersion == expectedMeasuresVersion:
|
249
254
|
# no pull is necessary
|
250
255
|
do_pull = False
|
251
|
-
print_log_messages('pull_data requested "release" versions of casarundata and measures are already installed.', logger)
|
256
|
+
print_log_messages('pull_data requested "release" versions of casarundata and measures are already installed.', logger, verbose=verbose)
|
252
257
|
# otherwise this is a release pull and even if the measuresVersion is 'unknown' or 'invalid' we should proceed with a pull at this point
|
253
258
|
# problems with casarundata path will have been caught before
|
254
259
|
else:
|
255
260
|
# nothing to do here, already at the expected casarundata version and a pull is not being forced and this is not a release pull
|
256
261
|
do_pull = False
|
257
|
-
print_log_messages('pull_data requested version is already installed.', logger)
|
262
|
+
print_log_messages('pull_data requested version is already installed.', logger, verbose=verbose)
|
258
263
|
|
259
264
|
# a version of 'invalid', 'error', or 'unknown' is a surprise here, likely caused by something else doing something
|
260
265
|
# incompatible with this attempt
|
@@ -274,7 +279,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
|
|
274
279
|
if do_pull:
|
275
280
|
# do not clean the lock file contents at this point unless do_pull_data returns normally
|
276
281
|
clean_lock = False
|
277
|
-
do_pull_data(path, version, installed_files, currentVersion, currentDate, logger)
|
282
|
+
do_pull_data(path, version, installed_files, currentVersion, currentDate, logger, verbose)
|
278
283
|
clean_lock = True
|
279
284
|
if namedVersion:
|
280
285
|
# a specific version has been requested, set the times on the measures readme.txt to now to avoid
|