casaconfig 1.2.0__py3-none-any.whl → 1.3.1__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/private/measures_available.py +49 -24
- casaconfig/private/measures_update.py +64 -65
- {casaconfig-1.2.0.dist-info → casaconfig-1.3.1.dist-info}/METADATA +1 -1
- {casaconfig-1.2.0.dist-info → casaconfig-1.3.1.dist-info}/RECORD +7 -7
- {casaconfig-1.2.0.dist-info → casaconfig-1.3.1.dist-info}/WHEEL +1 -1
- {casaconfig-1.2.0.dist-info → casaconfig-1.3.1.dist-info}/licenses/LICENSE +0 -0
- {casaconfig-1.2.0.dist-info → casaconfig-1.3.1.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2023 AUI, Inc. Washington DC, USA
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,12 +15,11 @@
|
|
15
15
|
this module will be included in the api
|
16
16
|
"""
|
17
17
|
|
18
|
-
|
19
18
|
def measures_available():
|
20
19
|
"""
|
21
|
-
List available measures versions on
|
20
|
+
List available measures versions on ASTRON at https://www.astron.nl/iers/
|
22
21
|
|
23
|
-
This returns a list of the measures
|
22
|
+
This returns a list of the measures versions available on the ASTRON
|
24
23
|
server. The version parameter of measures_update must be one
|
25
24
|
of the values in that list if set (otherwise the most recent version
|
26
25
|
in this list is used).
|
@@ -29,16 +28,20 @@ def measures_available():
|
|
29
28
|
None
|
30
29
|
|
31
30
|
Returns
|
32
|
-
version names returned as list of strings
|
31
|
+
list - version names returned as list of strings
|
33
32
|
|
34
|
-
Raises
|
35
|
-
- casaconfig.NoNetwork -
|
36
|
-
- casaconfig.RemoteError -
|
37
|
-
- Exception
|
33
|
+
Raises
|
34
|
+
- casaconfig.NoNetwork - Raised where there is no network seen, can not continue
|
35
|
+
- casaconfig.RemoteError - Raised when there is an error fetching some remote content for some reason other than no network
|
36
|
+
- Exception - Unexpected exception while getting list of available measures versions
|
38
37
|
|
39
38
|
"""
|
40
|
-
|
41
|
-
import
|
39
|
+
|
40
|
+
import html.parser
|
41
|
+
import urllib.request
|
42
|
+
import urllib.error
|
43
|
+
import ssl
|
44
|
+
import certifi
|
42
45
|
|
43
46
|
from casaconfig import RemoteError
|
44
47
|
from casaconfig import NoNetwork
|
@@ -46,21 +49,43 @@ def measures_available():
|
|
46
49
|
from .have_network import have_network
|
47
50
|
|
48
51
|
if not have_network():
|
49
|
-
raise NoNetwork("can not find the list of available
|
52
|
+
raise NoNetwork("No network, can not find the list of available data.")
|
50
53
|
|
51
|
-
|
54
|
+
class LinkParser(html.parser.HTMLParser):
|
55
|
+
def reset(self):
|
56
|
+
super().reset()
|
57
|
+
self.rundataList = []
|
58
|
+
|
59
|
+
def handle_starttag(self, tag, attrs):
|
60
|
+
if tag == 'a':
|
61
|
+
for (name, value) in attrs:
|
62
|
+
# only care if this is an href and the value starts with
|
63
|
+
# WSRT_Measures and has 'tar' after character 15 to exclude the "WSRT_Measures.ztar" file
|
64
|
+
# without relying on the specific type of compression or nameing in more detail than that
|
65
|
+
if name == 'href' and (value.startswith('WSRT_Measures') and (value.rfind('tar')>15)):
|
66
|
+
# only add it to the list if it's not already there
|
67
|
+
if (value not in self.rundataList):
|
68
|
+
self.rundataList.append(value)
|
69
|
+
|
52
70
|
try:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
context = ssl.create_default_context(cafile=certifi.where())
|
72
|
+
with urllib.request.urlopen('https://www.astron.nl/iers', context=context, timeout=400) as urlstream:
|
73
|
+
parser = LinkParser()
|
74
|
+
encoding = urlstream.headers.get_content_charset() or 'UTF-8'
|
75
|
+
for line in urlstream:
|
76
|
+
parser.feed(line.decode(encoding))
|
77
|
+
|
78
|
+
# return the sorted list, earliest versions are first, newest is last
|
79
|
+
return sorted(parser.rundataList)
|
80
|
+
|
81
|
+
except urllib.error.URLError as urlerr:
|
82
|
+
raise RemoteError("Unable to retrieve list of available measures versions : " + str(urlerr)) from None
|
83
|
+
|
62
84
|
except Exception as exc:
|
63
85
|
msg = "Unexpected exception while getting list of available measures versions : " + str(exc)
|
64
86
|
raise Exception(msg)
|
65
|
-
|
66
|
-
return
|
87
|
+
|
88
|
+
# nothing to return if it got here, must have been an exception
|
89
|
+
return []
|
90
|
+
|
91
|
+
|
@@ -17,20 +17,23 @@ this module will be included in the api
|
|
17
17
|
|
18
18
|
def measures_update(path=None, version=None, force=False, 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 ASTRON into path.
|
21
21
|
|
22
22
|
Original data source used by ASTRON is here: https://www.iers.org/IERS/EN/DataProducts/data.html
|
23
23
|
|
24
24
|
If no update is necessary then this function will silently return.
|
25
25
|
|
26
|
-
The verbose argument controls the level of information provided
|
27
|
-
are unchanged for expected reasons. A level of 0
|
28
|
-
value of 1
|
26
|
+
The verbose argument controls the level of information provided by this function when the data
|
27
|
+
are unchanged for expected reasons. A level of 0 outputs nothing. A
|
28
|
+
value of 1 sends any output to the logger and a value of 2 logs and prints the information.
|
29
|
+
The default value of the verbose argument is taken from the casaconfig_verbose config
|
30
|
+
value (defaults to 1).
|
29
31
|
|
30
32
|
CASA maintains a separate Observatories table which is available in the casarundata
|
31
33
|
collection through pull_data and data_update. The Observatories table found at ASTRON
|
32
34
|
is not installed by measures_update and any Observatories file at path will not be changed
|
33
|
-
by using this function.
|
35
|
+
by using this function. This behavior can be changed by setting force and use_astron_obs_table
|
36
|
+
both to True (use_astron_obs_table is ignored when force is False).
|
34
37
|
|
35
38
|
A text file (readme.txt in the geodetic directory in path) records the measures version string
|
36
39
|
and the date when that version was installed in path.
|
@@ -43,9 +46,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
43
46
|
If a specific version is not requested (the default) and the modification time of that text
|
44
47
|
file is less than 24 hrs before now then this function does nothing unless force is True. When this
|
45
48
|
function checks for a more recent version and finds that the installed version is the most recent
|
46
|
-
then modification time of that text file is
|
47
|
-
changed in path. This limits the number of attempts to update the measures data (including checking
|
48
|
-
|
49
|
+
then the modification time of that text file is changed to the current time even though nothing has
|
50
|
+
changed in path. This limits the number of attempts to update the measures data (including checking
|
51
|
+
for more recent data) to once per day. When the force argument is True and a specific version is
|
49
52
|
not requested then this function always checks for the latest version.
|
50
53
|
|
51
54
|
When auto_update_rules is True then path must exist and contain the expected readme.txt file.
|
@@ -75,11 +78,11 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
75
78
|
especially if they may also be starting at that time. If a specific version is
|
76
79
|
requested or force is True there is a risk that the measures may be updated while
|
77
80
|
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
|
81
|
+
unpredictable results. The lock file will prevent simultaneous updates from
|
82
|
+
happening but if each simultaneous update eventually updates the same measures
|
80
83
|
location (because force is True or the updates are requesting different versions)
|
81
|
-
then the measures that any of those
|
82
|
-
unpredictable. Avoid multiple,
|
84
|
+
then the measures that any of those simultaneous casatools modules sees is
|
85
|
+
unpredictable. Avoid multiple, simultaneous updates outside of the automatic
|
83
86
|
update process.
|
84
87
|
|
85
88
|
**Note:** during auto updates, measures_update requires that the expected
|
@@ -91,10 +94,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
91
94
|
read and write permissions there). The version must then also be None and the force option
|
92
95
|
must be False.
|
93
96
|
|
94
|
-
**Note
|
97
|
+
**Note:** During use outside of auto updates, if path does not exist it will be created
|
95
98
|
by this function.
|
96
99
|
|
97
|
-
**
|
100
|
+
**Note:** During use outside of auto updates, if the readme.txt file exists but can not
|
98
101
|
be read as expected **OR** that file does not exist but the contents of path appear to
|
99
102
|
contain measures data (table names in the expected locations) then this function will
|
100
103
|
print messages describing that and exit without changing anything at path. Using
|
@@ -104,25 +107,26 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
104
107
|
|
105
108
|
Parameters
|
106
109
|
- 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
|
110
|
+
- 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
111
|
- 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.
|
109
112
|
- logger (casatools.logsink=None) - Instance of the casalogger to use for writing messages. Default None writes messages to the terminal
|
110
113
|
- 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.
|
114
|
+
- 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).
|
111
115
|
- verbose (int=None) - Level of output, 0 is none, 1 is to logger, 2 is to logger and terminal, defaults to casaconfig_verbose in config dictionary.
|
112
116
|
|
113
117
|
Returns
|
114
118
|
None
|
115
119
|
|
116
120
|
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
|
121
|
+
- casaconfig.AutoUpdatesNotAllowed - raised when path does not exists as a directory or is not owned by the user when auto_update_rules is True
|
122
|
+
- casaconfig.BadLock - raised when the lock file was not empty when found
|
123
|
+
- casaconfig.BadReadme - raised when something unexpected is found in the readme or the readme changed after an update is in progress
|
124
|
+
- casaconfig.NoReadme - raised when the readme.txt file is not found at path (path also may not exist)
|
125
|
+
- casaconfig.NotWritable - raised when the user does not have permission to write to path
|
126
|
+
- casaconfig.NoNetwork - raised by measuers_available or when getting the lock file if there is no network.
|
127
|
+
- casaconfig.RemoteError - raised by measures_available when the remote list of measures could not be fetched, not due to no network.
|
128
|
+
- casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
|
129
|
+
- Exception - raised when something unexpected happened while updating measures
|
126
130
|
|
127
131
|
"""
|
128
132
|
import os
|
@@ -130,13 +134,12 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
130
134
|
from datetime import datetime
|
131
135
|
import sys
|
132
136
|
|
133
|
-
from ftplib import FTP
|
134
137
|
import tarfile
|
135
138
|
import re
|
136
139
|
import ssl
|
137
140
|
import urllib.request
|
138
141
|
import certifi
|
139
|
-
import
|
142
|
+
import shutil
|
140
143
|
|
141
144
|
from casaconfig import measures_available
|
142
145
|
from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme, NoNetwork
|
@@ -248,7 +251,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
248
251
|
|
249
252
|
# lock the measures_update.lock file
|
250
253
|
lock_fd = None
|
251
|
-
clean_lock = True # set to false if the contents are actively being
|
254
|
+
clean_lock = True # set to false if the contents are actively being update and the lock file should not be cleaned one exception
|
252
255
|
try:
|
253
256
|
print_log_messages('measures_update ... acquiring the lock ... ', logger)
|
254
257
|
|
@@ -290,13 +293,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
290
293
|
if force:
|
291
294
|
print_log_messages('A measures update has been requested by the force argument', logger)
|
292
295
|
|
293
|
-
print_log_messages(' ...
|
296
|
+
print_log_messages(' ... finding available measures at www.astron.nl ...', logger)
|
294
297
|
|
295
|
-
|
296
|
-
ftp = FTP('ftp.astron.nl')
|
297
|
-
rc = ftp.login()
|
298
|
-
rc = ftp.cwd('outgoing/Measures')
|
299
|
-
files = sorted([ff for ff in ftp.nlst() if (len(ff) > 0) and (not ff.endswith('.dat')) and (ftp.size(ff) > 0)])
|
298
|
+
files = measures_available()
|
300
299
|
|
301
300
|
# target filename to download
|
302
301
|
# 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
|
@@ -306,51 +305,51 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
|
|
306
305
|
print_log_messages("measures_update can't find specified version %s" % target, logger, True)
|
307
306
|
|
308
307
|
else:
|
309
|
-
# there are files to extract
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
308
|
+
# there are files to extract
|
309
|
+
print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger)
|
310
|
+
|
311
|
+
astronURL = 'https://www.astron.nl/iers'
|
312
|
+
context = ssl.create_default_context(cafile=certifi.where())
|
313
|
+
# just in case there's a redirect at astron the way there is for the go.nrao.edu site and casarundata
|
314
|
+
measuresURLroot = urllib.request.urlopen(astronURL, context=context).url
|
315
|
+
measuresURL = os.path.join(measuresURLroot, target)
|
316
|
+
|
317
|
+
# it's at this point that this code starts modifying what's there so the lock file should
|
318
|
+
# not be removed on failure after this although it may leave that temp tar file around, but that's OK
|
319
|
+
clean_lock = False
|
320
320
|
# remove any existing measures readme.txt now in case something goes wrong during extraction
|
321
321
|
readme_path = os.path.join(path,'geodetic/readme.txt')
|
322
322
|
if os.path.exists(readme_path):
|
323
323
|
os.remove(readme_path)
|
324
324
|
|
325
|
-
#
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
325
|
+
# custom filter that incorporates data_filter to watch for dangerous members of the tar file and
|
326
|
+
# add filtering to remove the Observatories table (unless use_astron_obs_table is True) and
|
327
|
+
# the *.old tables that may be in the geodetic tree
|
328
|
+
def custom_filter(member, extractionPath):
|
329
|
+
# member is a TarInfo instance and extractionPath is the destination path
|
330
|
+
# use the 'data_filter' first to deal with dangerous members
|
331
|
+
member = tarfile.data_filter(member, extractionPath)
|
332
|
+
# always exclude *.old names in geodetic
|
333
|
+
if (member is not None) and (re.search('geodetic',member.name) and re.search('.old',member.name)):
|
334
|
+
member = None
|
335
|
+
# the use_astron_obs_table argumen only has weight if force is True
|
336
|
+
if (not (force and use_astron_obs_table)) and (member is not None) and (re.search('Observatories',member.name)):
|
337
|
+
member = None
|
338
|
+
return member
|
339
|
+
|
340
|
+
with urllib.request.urlopen(measuresURL, context=context, timeout=400) as tstream, tarfile.open(fileobj=tstream, mode='r|*') as tar :
|
339
341
|
# use the 'data' filter if available, revert to previous 'fully_trusted' behavior of not available
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
os.remove(ztarPath)
|
342
|
+
tar.extraction_filter = custom_filter
|
343
|
+
tar.extractall(path=path)
|
344
|
+
tar.close()
|
345
345
|
|
346
346
|
# create a new readme.txt file
|
347
347
|
with open(readme_path,'w') as fid:
|
348
348
|
fid.write("# measures data populated by casaconfig\nversion : %s\ndate : %s" % (target, datetime.today().strftime('%Y-%m-%d')))
|
349
349
|
|
350
|
+
clean_lock = True
|
350
351
|
print_log_messages(' ... measures data updated at %s' % path, logger)
|
351
352
|
|
352
|
-
clean_lock = True
|
353
|
-
|
354
353
|
# closing out the do_update
|
355
354
|
|
356
355
|
# closing out the try block
|
@@ -16,17 +16,17 @@ casaconfig/private/get_data_info.py,sha256=onOcl2f0qfxFpQ3DuATh97-Ixr4IcBGtlZzNs
|
|
16
16
|
casaconfig/private/get_data_lock.py,sha256=JysF75EHwP2FErjffMkfeV-9wy5wJJ9irPDrMvVzSIo,3809
|
17
17
|
casaconfig/private/have_network.py,sha256=zCIbABTG_9ew9Ac3eb8ggNaZ_H61m_G4LCXkFZe7q5M,1410
|
18
18
|
casaconfig/private/io_redirect.py,sha256=9mwl2siS3fFYCEi_u9Mojg7cBtBgzW00mc8H7V1NSEs,2879
|
19
|
-
casaconfig/private/measures_available.py,sha256=
|
20
|
-
casaconfig/private/measures_update.py,sha256=
|
19
|
+
casaconfig/private/measures_available.py,sha256=F4Yd6NLM2gkfXR-y_RZ6CcgOeB1TGF4TTnXwpMYDP5I,3554
|
20
|
+
casaconfig/private/measures_update.py,sha256=Brb_gDXpSw9QvcYywQT7CssPWWgUsVjI1TY5o81fcCY,21905
|
21
21
|
casaconfig/private/print_log_messages.py,sha256=mZNSxHBgrSz7KTkCEdRgxohSuAPWSgKpF_06sIuyft0,2204
|
22
22
|
casaconfig/private/pull_data.py,sha256=nYYQLxlf4F6_8uzchfmHn6WvYV4wzjOP58_kc8uZYXk,17385
|
23
23
|
casaconfig/private/read_readme.py,sha256=T9mcG5KhQIHM6N9AgW4XJ2nKsHtI1Fa3iDgr8xMABLM,2137
|
24
24
|
casaconfig/private/set_casacore_path.py,sha256=yLAh4tNoUbWczuCIVpIJx6nx8p9jRm0lUjexrpMhA-A,2240
|
25
25
|
casaconfig/private/summary.py,sha256=jUtc5uLnEk1kljPpZa3UimhJAqVnDzMPUCD7OOznohE,3448
|
26
26
|
casaconfig/private/update_all.py,sha256=57ynk0JJqyMpS1ABmma7F-kFSEnbhU4ZvoSuXQdEJrQ,5501
|
27
|
-
casaconfig-1.
|
27
|
+
casaconfig-1.3.1.dist-info/licenses/LICENSE,sha256=OMpzmn2zUn6I4jmVqs1Coa_0NJcoJC9eweZ2gx-u0oI,11358
|
28
28
|
tests/test_casaconfig.py,sha256=yeycDBOzwHsDeYAyIEmj1RNsZ3k6l7SYXFY-p2F1l7A,43963
|
29
|
-
casaconfig-1.
|
30
|
-
casaconfig-1.
|
31
|
-
casaconfig-1.
|
32
|
-
casaconfig-1.
|
29
|
+
casaconfig-1.3.1.dist-info/METADATA,sha256=pZOKoGOWD4xWblCCKsjUqayhEp2EaR3qLTtvKE_Ss-w,16981
|
30
|
+
casaconfig-1.3.1.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
31
|
+
casaconfig-1.3.1.dist-info/top_level.txt,sha256=Uay9WTPz644aHfLbmj47WXzue19HtKRueFFCXu1N1Co,17
|
32
|
+
casaconfig-1.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|