casaconfig 1.0.3__py3-none-any.whl → 1.1.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/__main__.py CHANGED
@@ -131,10 +131,6 @@ except casaconfig.RemoteError as exc:
131
131
  print("This is likely due to no network connection or bad connectivity to a remote site, wait and try again")
132
132
  sys.exit(1)
133
133
 
134
- except casaconfig.NoNetwork as exc:
135
- print("No network seen, can not continue.")
136
- sys.exit(1)
137
-
138
134
  except casaconfig.BadLock as exc:
139
135
  # the output produced by the update functions is sufficient, just re-echo the exception text itself
140
136
  print(str(exc))
@@ -36,12 +36,7 @@ class RemoteError(Exception):
36
36
 
37
37
  class NotWritable(Exception):
38
38
  """Raised when the path is not writable by the user"""
39
- pass
40
39
 
41
40
  class UnsetMeasurespath(Exception):
42
41
  """Raised when a path argument is None"""
43
42
  pass
44
-
45
- class NoNetwork(Exception):
46
- """Raised when there is no network connection."""
47
- pass
@@ -36,8 +36,7 @@ def data_available():
36
36
  list - version names returned as list of strings
37
37
 
38
38
  Raises
39
- - casaconfig.NoNetwork - Raised where there is no network seen, can not continue
40
- - casaconfig.RemoteError - Raised when there is an error fetching some remote content for some reason other than no network
39
+ - casaconfig.RemoteError - Raised when there is an error fetching some remote content
41
40
  - Exception - Unexpected exception while getting list of available casarundata versions
42
41
 
43
42
  """
@@ -49,12 +48,6 @@ def data_available():
49
48
  import certifi
50
49
 
51
50
  from casaconfig import RemoteError
52
- from casaconfig import NoNetwork
53
-
54
- from .have_network import have_network
55
-
56
- if not have_network():
57
- raise NoNetwork("No network, can not find the list of available data.")
58
51
 
59
52
  class LinkParser(html.parser.HTMLParser):
60
53
  def reset(self):
@@ -17,7 +17,7 @@ this module will be included in the api
17
17
 
18
18
  def data_update(path=None, version=None, force=False, logger=None, auto_update_rules=False, verbose=None):
19
19
  """
20
- Check for updates to the installed casarundata and install the update or change to
20
+ Check for updates to the installed casarundata and install the update or change to
21
21
  the requested version when appropriate.
22
22
 
23
23
  The verbose argument controls the level of information provided when this function when the data
@@ -26,19 +26,19 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
26
26
 
27
27
  The path must contain a previously installed version of casarundata.
28
28
  Use pull_data to install casarundata into a new path (empty or does not exist).
29
-
29
+
30
30
  If path is None then config.measurespath is used.
31
31
 
32
- If the version is None (the default) then the most recent version returned by
32
+ If the version is None (the default) then the most recent version returned by
33
33
  data_available is used.
34
34
 
35
- If version is "release" then the version associated with the release in
35
+ If version is "release" then the version associated with the release in
36
36
  the dictionary returned by get_data_info is used. If there is no release
37
- version information available to casaconfig then an error message is printed
37
+ version information available to casaconfig then an error message is printed
38
38
  and nothing is updated. Release version information is only available in
39
39
  monolithic CASA installations.
40
40
 
41
- If a specific version is not requested (the default) and a check for the
41
+ If a specific version is not requested (the default) and a check for the
42
42
  versions available for installation at path has been done within the past
43
43
  24 hours then this function does nothing even if there is a more
44
44
  recent version available from the CASA server unless force is True.
@@ -47,7 +47,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
47
47
  now) is installed even if that version is already installed or a check for the
48
48
  latest version has been done within the past 24 hours.
49
49
 
50
- A text file (readme.txt at path) records the version string, the date
50
+ A text file (readme.txt at path) records the version string, the date
51
51
  when that version was installed in path, and the files installed into path. That file
52
52
  must already exist in path in order to use this function. Use pull_data to install
53
53
  casarundata into a new location.
@@ -57,31 +57,31 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
57
57
  data_auto_update is True. Automatic updating happens during casatools initialization
58
58
  so that the updated casarundata and measures are in place before any tool needs to use them.
59
59
 
60
- If an update is to be installed the previously installed files, as listed in the
61
- readme.txt file at path, are removed before the contents of the version
60
+ If an update is to be installed the previously installed files, as listed in the
61
+ readme.txt file at path, are removed before the contents of the version
62
62
  being installed are unpacked. If the measures contents of path have been updated since
63
63
  the previously installed version of casarundata then those updates will also be removed
64
64
  by this data update while preparing to install the requested version of casarundata (which
65
- includes a copy of the measures data that is likely older than today). A data update is
66
- typically followed by a measures_update to ensure that the most recent measures data
65
+ includes a copy of the measures data that is likely older than today). A data update is
66
+ typically followed by a measures_update to ensure that the most recent measures data
67
67
  are installed.
68
68
 
69
69
  A file lock is used to prevent more that one data update (pull_data, measures_update,
70
- or data_update) from updating any files in path at the same time. When locked, the
70
+ or data_update) from updating any files in path at the same time. When locked, the
71
71
  lock file (data_update.lock in path) contains information about the process that
72
72
  has the lock. When data_update gets the lock it checks the readme.txt file in path
73
- to make sure that an update is still necessary (if force is True then an update
73
+ to make sure that an update is still necessary (if force is True then an update
74
74
  always happens). If the lock file is not empty then a previous update of path (pull_data,
75
75
  data_update, or measures_update) did not exit as expected or is still in process (via a
76
- separate instance of CASA) and the contents of path may be suspect. In that case,
77
- an error will be reported and nothing will be updated. The lock file can be checked to
78
- see the details of when that file was locked. The lock file can be removed and data_update
76
+ separate instance of CASA) and the contents of path may be suspect. In that case,
77
+ an error will be reported and nothing will be updated. The lock file can be checked to
78
+ see the details of when that file was locked. The lock file can be removed and data_update
79
79
  can be tried again. It may be safest in that case to remove path completely or use a
80
80
  different path and use pull_data to install a fresh copy of the desired version.
81
81
 
82
- Some of the tables installed by data_update are only read when casatools starts. Use of
83
- data_update except during CASA startup by the auto update proess should typically be
84
- followed by a restart of CASA so that any changes are seen by the tools and tasks that
82
+ Some of the tables installed by data_update are only read when casatools starts. Use of
83
+ data_update except during CASA startup by the auto update proess should typically be
84
+ followed by a restart of CASA so that any changes are seen by the tools and tasks that
85
85
  use this data.
86
86
 
87
87
  **Note:** data_update requires that the expected readme.txt file already exists at the top-level
@@ -101,10 +101,10 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
101
101
  - logger (casatools.logsink=None) - Instance of the casalogger to use for writing messages. Default None writes messages to the terminal.
102
102
  - 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.
103
103
  - verbose (int) - Level of output, 0 is none, 1 is to logger, 2 is to logger and terminal, defaults to casaconfig_verbose in the config dictionary.
104
-
104
+
105
105
  Returns
106
106
  None
107
-
107
+
108
108
  Raises
109
109
  - casaconfig.AutoUpdatesNotAllowed - raised when path does not exist as a directory or is not owned by the user
110
110
  - casaconfig.BadLock - raised when the lock file was not empty when an attempt was made to obtain the lock
@@ -167,7 +167,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
167
167
  # path must be writable with execute bit set
168
168
  if (not os.access(path, os.W_OK | os.X_OK)) :
169
169
  raise NotWritable('data_update: No permission to write to %s, cannot update.' % path)
170
-
170
+
171
171
  # try and digest the readme file
172
172
 
173
173
  installed_files = []
@@ -177,7 +177,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
177
177
 
178
178
  # already checked that path is OK, type is OK here, no need to trap for exceptions here
179
179
  dataReadmeInfo = get_data_info(path, logger, type='casarundata')
180
-
180
+
181
181
  if dataReadmeInfo is None or dataReadmeInfo['version'] == 'invalid':
182
182
  msgs = []
183
183
  msgs.append('The readme.txt file at path could not be read as expected')
@@ -262,7 +262,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
262
262
  else:
263
263
  if verbose > 0:
264
264
  print_log_messages('Requested casarundata version is already installed in %s, %s' % (path, currentVersion), logger, verbose=verbose)
265
-
265
+
266
266
  # no lock has been set yet, safe to simply return here
267
267
  return
268
268
 
@@ -307,7 +307,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
307
307
  # always verbose here because the lock file is in use
308
308
  print_log_messages('requested version is already installed.', logger)
309
309
  do_update = False
310
-
310
+
311
311
  if do_update:
312
312
  # update is still on, check the manifest
313
313
  if len(installed_files) == 0:
@@ -360,5 +360,5 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
360
360
  if clean_lock:
361
361
  lock_fd.truncate(0)
362
362
  lock_fd.close()
363
-
363
+
364
364
  return
@@ -29,9 +29,6 @@ def get_data_lock(path, fn_name):
29
29
 
30
30
  This function is intended for internal casaconfig use.
31
31
 
32
- If there is not network (have_network returns False) then the lock file is not
33
- set or initialized and a NoNetwork exception is raised.
34
-
35
32
  Parameters
36
33
  - path (str) - The location where 'data_update.log' is to be found.
37
34
  - fn_name (str) - A string giving the name of the calling function to be recorded in the lock file.
@@ -40,7 +37,6 @@ def get_data_lock(path, fn_name):
40
37
  - the open file descriptor holding the lock. Close this file descriptor to release the lock.
41
38
 
42
39
  Raises:
43
- - casaconfig.NoNetwork - raised wheren there is no network, nothing can be downloaded so nothing should be locked.
44
40
  - casaconfig.BadLock - raised when the path to the lock file does not exist or the lock file is not empty as found
45
41
  - Exception - an unexpected exception was seen while writing the lock information to the file
46
42
 
@@ -52,11 +48,6 @@ def get_data_lock(path, fn_name):
52
48
  from datetime import datetime
53
49
 
54
50
  from casaconfig import BadLock
55
- from casaconfig import NoNetwork
56
- from .have_network import have_network
57
-
58
- if not have_network():
59
- raise NoNetwork("No network, lock file has not been set, unable to continue.")
60
51
 
61
52
  if not os.path.exists(path):
62
53
  raise BadLock("path to contain lock file does not exist : %s" % path)
@@ -1,4 +1,4 @@
1
- # Copyright 2020 AUI, Inc. Washington DC, USA
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 the ASTRON server
20
+ List available measures versions on ASTRON at https://www.astron.nl/iers/
22
21
 
23
- This returns a list of the measures files available on the ASTRON
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,38 +28,57 @@ 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 - raised when there is no network (have_data returns False)
36
- - casaconfig.RemoteError - raised when when a socket.gaierror is seen, unlikely due to the have_network check
37
- - Exception: raised when any unexpected exception happens
33
+ Raises
34
+ - casaconfig.RemoteError - Raised when there is an error fetching some remote content
35
+ - Exception - Unexpected exception while getting list of available measures versions
38
36
 
39
37
  """
40
- from ftplib import FTP
41
- import socket
38
+
39
+ import html.parser
40
+ import urllib.request
41
+ import urllib.error
42
+ import ssl
43
+ import certifi
42
44
 
43
45
  from casaconfig import RemoteError
44
- from casaconfig import NoNetwork
45
46
 
46
- from .have_network import have_network
47
+ class LinkParser(html.parser.HTMLParser):
48
+ def reset(self):
49
+ super().reset()
50
+ self.rundataList = []
51
+
52
+ def handle_starttag(self, tag, attrs):
53
+ if tag == 'a':
54
+ for (name, value) in attrs:
55
+ # only care if this is an href and the value starts with
56
+ # WSRT_Measures and has 'tar' after character 15 to exclude the "WSRT_Measures.ztar" file
57
+ # without relying on the specific type of compression or nameing in more detail than that
58
+ if name == 'href' and (value.startswith('WSRT_Measures') and (value.rfind('tar')>15)):
59
+ # only add it to the list if it's not already there
60
+ if (value not in self.rundataList):
61
+ self.rundataList.append(value)
47
62
 
48
- if not have_network():
49
- raise NoNetwork("can not find the list of available measures data")
50
-
51
- files = []
52
63
  try:
53
- ftp = FTP('ftp.astron.nl')
54
- rc = ftp.login()
55
- rc = ftp.cwd('outgoing/Measures')
56
- files = ftp.nlst()
57
- ftp.quit()
58
- #files = [ff.replace('WSRT_Measures','').replace('.ztar','').replace('_','') for ff in files]
59
- files = [ff for ff in files if (len(ff) > 0) and (not ff.endswith('.dat'))]
60
- except socket.gaierror as gaierr:
61
- raise RemoteError("Unable to retrieve list of available measures versions : " + str(gaierr)) from None
64
+ context = ssl.create_default_context(cafile=certifi.where())
65
+ with urllib.request.urlopen('https://www.astron.nl/iers', context=context, timeout=400) as urlstream:
66
+ parser = LinkParser()
67
+ encoding = urlstream.headers.get_content_charset() or 'UTF-8'
68
+ for line in urlstream:
69
+ parser.feed(line.decode(encoding))
70
+
71
+ # return the sorted list, earliest versions are first, newest is last
72
+ return sorted(parser.rundataList)
73
+
74
+ except urllib.error.URLError as urlerr:
75
+ raise RemoteError("Unable to retrieve list of available measures versions : " + str(urlerr)) from None
76
+
62
77
  except Exception as exc:
63
78
  msg = "Unexpected exception while getting list of available measures versions : " + str(exc)
64
79
  raise Exception(msg)
65
-
66
- return files
80
+
81
+ # nothing to return if it got here, must have been an exception
82
+ return []
83
+
84
+
@@ -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 the ASTRON server at path.
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 when this function when the data
27
- are unchanged for expected reasons. A level of 0 prints and logs nothing. A
28
- value of 1 logs the information and a value of 2 logs and prints the information.
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 checked to the current time even though nothing has
47
- changed in path. This limits the number of attempts to update the measures data (including checking f\
48
- or more recent data) to once per day. When the force argument is True and a specific version is
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 simulateous updates from
79
- happening but if each simultanous update eventually updates the same measures
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 simultanous casatools modules sees is
82
- unpredictable. Avoid multiple, simultanous updates outside of the automatic
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::** During use outside of auto updates, if path does not exist it will be created
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
- **Notes::** During use outside of auto updates, if the readme.txt file exists but can not
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,25 @@ 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 yyyymmdd-160001.ztar, see measures_available()). Default None retrieves the latest.
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.RemoteError - raised by measures_available when the remote list of measures could not be fetched
127
+ - casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
128
+ - Exception - raised when something unexpected happened while updating measures
126
129
 
127
130
  """
128
131
  import os
@@ -130,16 +133,15 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
130
133
  from datetime import datetime
131
134
  import sys
132
135
 
133
- from ftplib import FTP
134
136
  import tarfile
135
137
  import re
136
138
  import ssl
137
139
  import urllib.request
138
140
  import certifi
139
- import fcntl
141
+ import shutil
140
142
 
141
143
  from casaconfig import measures_available
142
- from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme, NoNetwork
144
+ from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme
143
145
 
144
146
  from .print_log_messages import print_log_messages
145
147
  from .get_data_lock import get_data_lock
@@ -209,11 +211,8 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
209
211
  # get the current most recent version
210
212
  try:
211
213
  checkVersion = measures_available()[-1]
212
- except NoNetwork as exc:
213
- # no network, no point in continuing, just reraise
214
- raise exc
215
214
  except RemoteError as exc:
216
- # bad network?, no point in continuing, just reraise
215
+ # no network, no point in continuing, just reraise
217
216
  raise exc
218
217
  except:
219
218
  # unsure what happened, leave it at none, which will trigger an update attempt, which might work
@@ -248,7 +247,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
248
247
 
249
248
  # lock the measures_update.lock file
250
249
  lock_fd = None
251
- clean_lock = True # set to false if the contents are actively being u pdate and the lock file should not be cleaned one exception
250
+ clean_lock = True # set to false if the contents are actively being update and the lock file should not be cleaned one exception
252
251
  try:
253
252
  print_log_messages('measures_update ... acquiring the lock ... ', logger)
254
253
 
@@ -290,13 +289,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
290
289
  if force:
291
290
  print_log_messages('A measures update has been requested by the force argument', logger)
292
291
 
293
- print_log_messages(' ... connecting to ftp.astron.nl ...', logger)
292
+ print_log_messages(' ... finding available measures at www.astron.nl ...', logger)
294
293
 
295
- clean_lock = False
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)])
294
+ files = measures_available()
300
295
 
301
296
  # target filename to download
302
297
  # 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 +301,51 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
306
301
  print_log_messages("measures_update can't find specified version %s" % target, logger, True)
307
302
 
308
303
  else:
309
- # there are files to extract, make sure there's no past measures.ztar from a failed previous install
310
- ztarPath = os.path.join(path,'measures.ztar')
311
- if os.path.exists(ztarPath):
312
- os.remove(ztarPath)
313
-
314
- with open(ztarPath, 'wb') as fid:
315
- print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger)
316
- ftp.retrbinary('RETR ' + target, fid.write)
317
-
318
- ftp.close()
319
-
304
+ # there are files to extract
305
+ print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger)
306
+
307
+ astronURL = 'https://www.astron.nl/iers'
308
+ context = ssl.create_default_context(cafile=certifi.where())
309
+ # just in case there's a redirect at astron the way there is for the go.nrao.edu site and casarundata
310
+ measuresURLroot = urllib.request.urlopen(astronURL, context=context).url
311
+ measuresURL = os.path.join(measuresURLroot, target)
312
+
313
+ # it's at this point that this code starts modifying what's there so the lock file should
314
+ # not be removed on failure after this although it may leave that temp tar file around, but that's OK
315
+ clean_lock = False
320
316
  # remove any existing measures readme.txt now in case something goes wrong during extraction
321
317
  readme_path = os.path.join(path,'geodetic/readme.txt')
322
318
  if os.path.exists(readme_path):
323
319
  os.remove(readme_path)
324
320
 
325
- # extract from the fetched tarfile
326
- with tarfile.open(ztarPath, mode='r:gz') as ztar:
327
- # the list of members to extract
328
- x_list = []
329
- for m in ztar.getmembers() :
330
- if force and use_astron_obs_table:
331
- # exclude the *.old names in geodetic
332
- if not(re.search('geodetic',m.name) and re.search('.old',m.name)):
333
- x_list.append(m)
334
- else:
335
- # exclude the Observatories table and *.old names in geodetic
336
- if not((re.search('geodetic',m.name) and re.search('.old',m.name)) or re.search('Observatories',m.name)):
337
- x_list.append(m)
338
-
321
+ # custom filter that incorporates data_filter to watch for dangerous members of the tar file and
322
+ # add filtering to remove the Observatories table (unless use_astron_obs_table is True) and
323
+ # the *.old tables that may be in the geodetic tree
324
+ def custom_filter(member, extractionPath):
325
+ # member is a TarInfo instance and extractionPath is the destination path
326
+ # use the 'data_filter' first to deal with dangerous members
327
+ member = tarfile.data_filter(member, extractionPath)
328
+ # always exclude *.old names in geodetic
329
+ if (member is not None) and (re.search('geodetic',member.name) and re.search('.old',member.name)):
330
+ member = None
331
+ # the use_astron_obs_table argumen only has weight if force is True
332
+ if (not (force and use_astron_obs_table)) and (member is not None) and (re.search('Observatories',member.name)):
333
+ member = None
334
+ return member
335
+
336
+ with urllib.request.urlopen(measuresURL, context=context, timeout=400) as tstream, tarfile.open(fileobj=tstream, mode='r|*') as tar :
339
337
  # use the 'data' filter if available, revert to previous 'fully_trusted' behavior of not available
340
- ztar.extraction_filter = getattr(tarfile, 'data_filter', (lambda member, path: member))
341
- ztar.extractall(path=path,members=x_list)
342
- ztar.close()
343
-
344
- os.remove(ztarPath)
338
+ tar.extraction_filter = custom_filter
339
+ tar.extractall(path=path)
340
+ tar.close()
345
341
 
346
342
  # create a new readme.txt file
347
343
  with open(readme_path,'w') as fid:
348
344
  fid.write("# measures data populated by casaconfig\nversion : %s\ndate : %s" % (target, datetime.today().strftime('%Y-%m-%d')))
349
345
 
346
+ clean_lock = True
350
347
  print_log_messages(' ... measures data updated at %s' % path, logger)
351
348
 
352
- clean_lock = True
353
-
354
349
  # closing out the do_update
355
350
 
356
351
  # closing out the try block
@@ -22,15 +22,15 @@ 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
-
26
- The path must either contain a previously installed version of casarundata
25
+
26
+ The path must either contain a previously installed version of casarundata
27
27
  or it must not exist or be empty.
28
28
 
29
29
  If path is None then config.measurespath will be used.
30
30
 
31
31
  If version is None (the default) then the most recent version is pulled.
32
32
 
33
- If version is "release" then the version associated with the release in
33
+ If version is "release" then the version associated with the release in
34
34
  the dictionary returned by get_data_info is used. If there is no release
35
35
  version information known then an error message is printed and nothing is
36
36
  checked or installed.
@@ -43,20 +43,20 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
43
43
 
44
44
  A text file (readme.txt at path) records the version string, the date
45
45
  when that version was installed in path, and the files installed into path.
46
- This file is used to determine if the contents are a previously installed
46
+ This file is used to determine if the contents are a previously installed
47
47
  version. If path is not empty then this file must exist with the expected
48
48
  contents in order for pull_data to proceed.
49
49
 
50
- If the version to be pulled matches the version in the readme.txt file then
50
+ If the version to be pulled matches the version in the readme.txt file then
51
51
  pull_data does nothing unless force is True. No error messages will result when the
52
52
  version already matches what was previously installed (no installation is then
53
53
  necessary unless force is True).
54
54
 
55
- The measures tables included in casarundata will typically not be the most
55
+ The measures tables included in casarundata will typically not be the most
56
56
  recent version. To get the most recent measures data, measures_update
57
57
  should be used after pull_data.
58
58
 
59
- If path contains a previously installed version then all of the files listed in
59
+ If path contains a previously installed version then all of the files listed in
60
60
  the manifest part of the readme.txt file are first removed from path. This ensures
61
61
  that files not present in the version being installed are removed in moving to the
62
62
  other version.
@@ -65,23 +65,23 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
65
65
  or data_update) from updating any files in path at the same time. When locked, the
66
66
  lock file (data_update.lock in path) contains information about the process that
67
67
  has the lock. When pull_data gets the lock it checks the readme.txt file in path
68
- to make sure that a copy of the data should still be pulled (the version doesn't
68
+ to make sure that a copy of the data should still be pulled (the version doesn't
69
69
  match what was requested, or force is True). If the lock file is not
70
70
  empty then a previous update of path (pull_data, data_update, or measures_update)
71
71
  did not exit as expected and the contents of path are suspect. In that case, pull_data
72
72
  will report that as an error and nothing will be updated. The lock file can be checked
73
73
  to see the details of when that file was locked. The lock file can be removed and
74
74
  pull_data can then be used to install the desired version. It may be safest in that case
75
- to remove path completely or use a different path and run pull_data to install
75
+ to remove path completely or use a different path and run pull_data to install
76
76
  a fresh copy of the desired version.
77
77
 
78
- Some of the tables installed by pull_data are only read when casatools starts. Use of
79
- pull_data should typically be followed by a restart of CASA so that
78
+ Some of the tables installed by pull_data are only read when casatools starts. Use of
79
+ pull_data should typically be followed by a restart of CASA so that
80
80
  any changes are seen by the tools and tasks that use this data.
81
81
 
82
82
  **Note:** When version is None (the default), data_available is always used to find out
83
83
  what versions are available. There is no check on when the data were last updated before
84
- calling data_available (as there is in the two update functions).
84
+ calling data_available (as there is in the two update functions).
85
85
 
86
86
  Parameters
87
87
  - path (str) - Folder path to place casarundata contents. It must be empty or not exist or contain a valid, previously installed version. If not set then config.measurespath is used.
@@ -96,9 +96,8 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
96
96
  Raises
97
97
  - casaconfig.BadLock - raised when the lock file is not empty when a lock is requested
98
98
  - casaconfig.BadReadme - raised when the readme.txt file found at path does not contain the expected list of installed files or there was an unexpected change while the data lock is on
99
- - casaconfig.NoNetwork - raised where this is no network
100
99
  - casaconfig.NotWritable - raised when the user does not have write permission to path
101
- - casaconfig.RemoteError - raised by data_available when the list of available data versions could not be fetched for some reason other than no network
100
+ - casaconfig.RemoteError - raised by data_available when the list of available data versions could not be fetched
102
101
  - casaconfig.UnsetMeasurespath - raised when path is None and and measurespath has not been set in config.
103
102
 
104
103
  """
@@ -132,7 +131,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
132
131
  available_data = None
133
132
  currentVersion = None
134
133
  currentDate = None
135
-
134
+
136
135
  # attempt a pull if path does not exist or is empty (except for any lock file, handled later)
137
136
  readmeInfo = get_data_info(path, logger, type='casarundata')
138
137
  do_pull = readmeInfo is None
@@ -165,11 +164,11 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
165
164
  # this shouldn't happen
166
165
  # no lock has been set yet, safe to raise this exception without worrying about the lock
167
166
  raise BadReadme('pull_data: the readme.txt file at path did not contain the expected list of installed files')
168
-
167
+
169
168
  # the readme file looks as expected, pull if the version is different or force is true
170
169
  if version is None:
171
170
  # use most recent available
172
- # this may raise RemoteError or NoNetwork, no need to catch that here but it may need to be caught upstream
171
+ # this may raise a RemoteError, no need to catch that here but it may need to be caught upstream
173
172
  available_data = data_available()
174
173
  version = available_data[-1]
175
174
 
@@ -180,16 +179,16 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
180
179
  # safe to return here, no lock has been set
181
180
  print_log_messages('pull_data: version is already at the expected version and force is False. Nothing was changed', logger, verbose=verbose)
182
181
  return
183
-
182
+
184
183
  # a pull will happen, unless the version string is not available
185
184
 
186
185
  if version is None:
187
186
  # need a version, use most recent available
188
-
187
+
189
188
  if available_data is None:
190
- # this may raise RemoteError or NoNetwork, no need to catch that here but it may need to be caught upstream
189
+ # this may raise a RemoteError, no need to catch that here but it may need to be caught upstream
191
190
  available_data = data_available()
192
-
191
+
193
192
  version = available_data[-1]
194
193
 
195
194
  expectedMeasuresVersion = None
@@ -204,9 +203,9 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
204
203
  else:
205
204
  # requested version must be available
206
205
  if available_data is None:
207
- # this may raise RemoteError or NoNetwork, no need to catch that here but it may need to be caught upstream
206
+ # this may raise a RemoteError, no need to catch that here but it may need to be caught upstream
208
207
  available_data = data_available()
209
-
208
+
210
209
  if version not in available_data:
211
210
  print_log_messages('version %s not found on CASA server, use casaconfig.data_available() for a list of casarundata versions' % version, logger, True)
212
211
  return
@@ -225,10 +224,9 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
225
224
  try:
226
225
  print_log_messages('pull_data using version %s, acquiring the lock ... ' % version, logger)
227
226
 
228
- # 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
227
  lock_fd = get_data_lock(path, 'pull_data')
230
228
  # the BadLock exception that may happen here is caught below
231
-
229
+
232
230
  do_pull = True
233
231
  if not force:
234
232
  # need to recheck any readme file that may be present here
@@ -299,11 +297,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
299
297
  msgs.append('Check for other updates in progress or choose a different path or clear out this path and try again')
300
298
  print_log_messages(msgs, logger, True)
301
299
  raise
302
-
303
- except NoNetwork as exc:
304
- # there is no network, it should be self explanatory so just re-raise it
305
- raise
306
-
300
+
307
301
  except Exception as exc:
308
302
  msgs = []
309
303
  msgs.append('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (version, path))
@@ -317,5 +311,5 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
317
311
  if clean_lock:
318
312
  lock_fd.truncate(0)
319
313
  lock_fd.close()
320
-
314
+
321
315
  return
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: casaconfig
3
- Version: 1.0.3
3
+ Version: 1.1.1
4
4
  Summary: CASA Operational Configuration Package
5
5
  Author-email: National Radio Astronomy Observatory <casa-feedback@nrao.edu>
6
6
  License: Apache License
@@ -212,6 +212,7 @@ Requires-Python: >=3.8
212
212
  Description-Content-Type: text/markdown
213
213
  License-File: LICENSE
214
214
  Requires-Dist: certifi>=2023.5.7
215
+ Dynamic: license-file
215
216
 
216
217
  # casaconfig
217
218
  Runtime data necessary for CASA operation.
@@ -264,29 +265,3 @@ dist
264
265
  ├── casaconfig-[VERSION]-py3-none-any.whl
265
266
  └── casaconfig-[VERSION].tar.gz
266
267
  ```
267
-
268
- ### Setting up CASA branches for casaconfig development
269
-
270
- The casaconfig build process publishes test wheels to test.pypi.org
271
-
272
- In order to test these with Casa packages, two changes are needed in the casa6 repository branch.
273
-
274
- 1) Add a line to casa6/build.conf with the appropriate wheel version. For example:
275
-
276
- ```
277
- casaconfig==1.0.3.dev2
278
- ```
279
- 2) Add the following line with the apppropriate branch name to casa6/casatools/setup.py
280
-
281
- ```
282
- META_DATA["install_requires"] = "casaconfig@git+https://github.com/casangi/casaconfig@CAS-14512"
283
- ```
284
-
285
- This adds the casaconfig branch as a casatools install time dependency. It will not use the wheel, but rather build the branch in place. This is required in order to avoid adding test.pypi.org as a pip extra-index-url, which might cause other development packages to be installed inadvertently. Note that casaconfig dependency is typically defined in setup.cfg, but the syntax above does not work with setup.cfg.
286
-
287
-
288
- ### Preparing the casa6 branch for merge
289
-
290
- 1) Merge the casaconfig branch to main and create a wheel
291
- 2) Update casa6/build.conf to use that wheel
292
- 3) Comment out the extra "install_requires" line from setup.py
@@ -1,32 +1,31 @@
1
1
  casaconfig/__init__.py,sha256=T-XMwDexm45ndO5gNlpg3kSJoi2EG7TM5VlHHjs70UU,646
2
- casaconfig/__main__.py,sha256=rmkK1hRFQSwNoVDJ3AV8Ht_36VY4DAceglevbcBNHcA,7541
2
+ casaconfig/__main__.py,sha256=pcuffTdiKEjAkhbQlxGnZzGYf3dSy7CEvWD0kwh7cyU,7440
3
3
  casaconfig/config.py,sha256=yIB7h5xwAbK40o7lIAAkXnvmLO_IU9km1XMwdvFx-tg,7172
4
- casaconfig/private/CasaconfigErrors.py,sha256=5jgBGiFSussmC7tUAA-w0awYx-7hC6Dhv_OXNihJkkY,1519
4
+ casaconfig/private/CasaconfigErrors.py,sha256=21T38zLkoCXz0AYx9liVVffjFPDaV5tBLEn9AcDz4uc,1418
5
5
  casaconfig/private/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  casaconfig/private/casasiteconfig_example.py,sha256=J5C9an1iVhxqSbtYT_FiopDXx8SZDcVQkLWKufA_fnc,653
7
7
  casaconfig/private/config_defaults.py,sha256=I-bY_rJqP_asidNgdKj4MkPHaY6oQFxgENLsw81mdBw,2054
8
8
  casaconfig/private/config_defaults_static.py,sha256=2XwR6FPBMgMVw8hbw-S6OGSlIa3HC4ejyeC1FvIBDAE,2137
9
- casaconfig/private/data_available.py,sha256=hvQGFix5G4C6iJ3_6v05OqHxqMxzecZwAR0-t9Jlhh0,3768
10
- casaconfig/private/data_update.py,sha256=Ot9SY4249rfU3CMnyg5LFdB5KfnAZsJoGEuHIT5DGZA,20545
9
+ casaconfig/private/data_available.py,sha256=GNGUgg2V5Y5s2IZWQKaw7zjOFnCi4rEahhH7NI3gaXw,3453
10
+ casaconfig/private/data_update.py,sha256=k3Of7ooftbQUGJZPCL1OzsBn_5AIP8WdKhrG-A6PZ-8,20627
11
11
  casaconfig/private/do_auto_updates.py,sha256=sYO5PVG34BXwtHNb8Tawop1Okwt9OTjbSTIwzf0skbs,3418
12
12
  casaconfig/private/do_pull_data.py,sha256=F7AXX0py2gNWhCAiOrMUPU5n9gQUACjiyYhdlRp5igM,6574
13
13
  casaconfig/private/get_argparser.py,sha256=-pwPMplwBJssSiEOVte89MqBRuxbZ3jLNVluQrv_eGc,1670
14
14
  casaconfig/private/get_config.py,sha256=R_6lZ3hp9NNbfBBhrOBBieXDFhR6Q3MdGHSgUwICbzk,1590
15
15
  casaconfig/private/get_data_info.py,sha256=onOcl2f0qfxFpQ3DuATh97-Ixr4IcBGtlZzNspROtPQ,12467
16
- casaconfig/private/get_data_lock.py,sha256=JysF75EHwP2FErjffMkfeV-9wy5wJJ9irPDrMvVzSIo,3809
17
- casaconfig/private/have_network.py,sha256=zCIbABTG_9ew9Ac3eb8ggNaZ_H61m_G4LCXkFZe7q5M,1410
16
+ casaconfig/private/get_data_lock.py,sha256=r2sju4havqRRDaLRbD6aHAKulemuVWH0D16r77xTYjQ,3347
18
17
  casaconfig/private/io_redirect.py,sha256=9mwl2siS3fFYCEi_u9Mojg7cBtBgzW00mc8H7V1NSEs,2879
19
- casaconfig/private/measures_available.py,sha256=OWYmSSUhDqeOGHXBBd6Fwb74O0iJdq8LZx3vIjQNjq4,2343
20
- casaconfig/private/measures_update.py,sha256=xs84pMWG2263qLlz1y4cFTdUH32QR7ZYxJM3TdhiyRk,21018
18
+ casaconfig/private/measures_available.py,sha256=wUJtbQLecdLCtq3x-HMjjOpwu7Fl4Nwp41R7-Uj0zVQ,3235
19
+ casaconfig/private/measures_update.py,sha256=sidF8nNqoHNXTFPgiBQujqM9iwPNqVkiLsbAsD6VJWc,21623
21
20
  casaconfig/private/print_log_messages.py,sha256=mZNSxHBgrSz7KTkCEdRgxohSuAPWSgKpF_06sIuyft0,2204
22
- casaconfig/private/pull_data.py,sha256=nYYQLxlf4F6_8uzchfmHn6WvYV4wzjOP58_kc8uZYXk,17385
21
+ casaconfig/private/pull_data.py,sha256=vqL607amPiAK2fOvG14wVrxFXZYaWUw3TqbMSOWstC4,17063
23
22
  casaconfig/private/read_readme.py,sha256=T9mcG5KhQIHM6N9AgW4XJ2nKsHtI1Fa3iDgr8xMABLM,2137
24
23
  casaconfig/private/set_casacore_path.py,sha256=yLAh4tNoUbWczuCIVpIJx6nx8p9jRm0lUjexrpMhA-A,2240
25
24
  casaconfig/private/summary.py,sha256=jUtc5uLnEk1kljPpZa3UimhJAqVnDzMPUCD7OOznohE,3448
26
25
  casaconfig/private/update_all.py,sha256=57ynk0JJqyMpS1ABmma7F-kFSEnbhU4ZvoSuXQdEJrQ,5501
27
- tests/test_casaconfig.py,sha256=yeycDBOzwHsDeYAyIEmj1RNsZ3k6l7SYXFY-p2F1l7A,43963
28
- casaconfig-1.0.3.dist-info/LICENSE,sha256=OMpzmn2zUn6I4jmVqs1Coa_0NJcoJC9eweZ2gx-u0oI,11358
29
- casaconfig-1.0.3.dist-info/METADATA,sha256=X4RtDt_jfWAxgdJeUB8mpHOY2YCt0FTPWtoaal2xC2A,16959
30
- casaconfig-1.0.3.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
31
- casaconfig-1.0.3.dist-info/top_level.txt,sha256=Uay9WTPz644aHfLbmj47WXzue19HtKRueFFCXu1N1Co,17
32
- casaconfig-1.0.3.dist-info/RECORD,,
26
+ casaconfig-1.1.1.dist-info/licenses/LICENSE,sha256=OMpzmn2zUn6I4jmVqs1Coa_0NJcoJC9eweZ2gx-u0oI,11358
27
+ tests/test_casaconfig.py,sha256=Xmn2hbw0SQ2PJ9BzQCg33EKB4413jvs0qHj5k4Rmfnk,42214
28
+ casaconfig-1.1.1.dist-info/METADATA,sha256=O5HBW6FR3CJKfep0piHJjLLom-9KtUjNxXtotlk3tZA,15821
29
+ casaconfig-1.1.1.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
30
+ casaconfig-1.1.1.dist-info/top_level.txt,sha256=Uay9WTPz644aHfLbmj47WXzue19HtKRueFFCXu1N1Co,17
31
+ casaconfig-1.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (79.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
tests/test_casaconfig.py CHANGED
@@ -750,44 +750,6 @@ class casaconfig_test(unittest.TestCase):
750
750
  # these tests requires an already installed set of data
751
751
  self.populate_testrundata()
752
752
 
753
- # BadLock
754
- print("\nTesting for BadLock in test_exceptions_with_data")
755
- # insert a non-empty lock file
756
- exceptionSeen = False
757
- lockPath = os.path.join(self.testRundataPath,'data_update.lock')
758
- with open(lockPath,'w') as f:
759
- f.write("test lock file, not empty")
760
-
761
- # with measures_update
762
- try:
763
- exceptionSeen = False
764
- # try to install an older measures, should fail because of the lock file
765
- ma = casaconfig.measures_available()
766
- casaconfig.measures_update(self.testRundataPath, version=ma[0])
767
- except casaconfig.BadLock as exc:
768
- exceptionSeen = True
769
- except Exception as exc:
770
- print("unexepected exception seen while testing for expected BadLock exception in measures_update")
771
- print(str(exc))
772
- self.assertTrue(exceptionSeen, "BadLock not seen as expected in measures_update with existing data test in")
773
-
774
- # with data_update
775
- try:
776
- exceptionSeen = False
777
- # try to install an older measures, should fail because of the lock file
778
- da = casaconfig.data_available()
779
- casaconfig.data_update(self.testRundataPath, version=da[0])
780
- except casaconfig.BadLock as exc:
781
- exceptionSeen = True
782
- except Exception as exc:
783
- print("unexepected exception seen while testing for expected BadLock exception in data_update")
784
- print(str(exc))
785
- self.assertTrue(exceptionSeen, "BadLock not seen as expected in data_update with existing data test")
786
- # remove the lock file
787
- os.remove(lockPath)
788
- print("BadLock test passed in test_exceptions_with_data\n")
789
-
790
-
791
753
  # BadReadme
792
754
 
793
755
  # create a bad data readme.txt file from the valid one
@@ -1,40 +0,0 @@
1
- # Copyright 2025 AUI, Inc. Washington DC, USA
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- import urllib.request
16
- import urllib.error
17
-
18
- def have_network():
19
- """
20
- check to see if an active network with general internet connectivity
21
- is available. returns True if we have internet connectivity and
22
- False if we do not.
23
- """
24
- ###
25
- ### see: https://stackoverflow.com/questions/50558000/test-internet-connection-for-python3
26
- ###
27
- ### copied from in casagui/utils/__init__.py
28
- ###
29
- try:
30
- with urllib.request.urlopen('http://clients3.google.com/generate_204') as response:
31
- return response.status == 204
32
- except urllib.error.HTTPError:
33
- ### http error
34
- return False
35
- except urllib.error.ContentTooShortError:
36
- return False
37
- except urllib.error.URLError:
38
- return False
39
- except Exception:
40
- return False