casaconfig 1.0.2__py3-none-any.whl → 1.2.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/__main__.py CHANGED
@@ -131,6 +131,10 @@ 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
+
134
138
  except casaconfig.BadLock as exc:
135
139
  # the output produced by the update functions is sufficient, just re-echo the exception text itself
136
140
  print(str(exc))
@@ -36,7 +36,12 @@ class RemoteError(Exception):
36
36
 
37
37
  class NotWritable(Exception):
38
38
  """Raised when the path is not writable by the user"""
39
+ pass
39
40
 
40
41
  class UnsetMeasurespath(Exception):
41
42
  """Raised when a path argument is None"""
42
43
  pass
44
+
45
+ class NoNetwork(Exception):
46
+ """Raised when there is no network connection."""
47
+ pass
@@ -36,7 +36,8 @@ def data_available():
36
36
  list - version names returned as list of strings
37
37
 
38
38
  Raises
39
- - casaconfig.RemoteError - Raised when there is an error fetching some remote content
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
40
41
  - Exception - Unexpected exception while getting list of available casarundata versions
41
42
 
42
43
  """
@@ -48,6 +49,12 @@ def data_available():
48
49
  import certifi
49
50
 
50
51
  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.")
51
58
 
52
59
  class LinkParser(html.parser.HTMLParser):
53
60
  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:
@@ -330,7 +330,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
330
330
 
331
331
  except BadLock as exc:
332
332
  # the path is known to exist so this means that the lock file was not empty and it's not locked
333
- msgs = str(exc)
333
+ msgs = [str(exc)]
334
334
  msgs.append('data_update: the lock file at %s is not empty.' % path)
335
335
  msgs.append('A previous attempt to update path may have failed or exited prematurely.')
336
336
  msgs.append('Remove the lock file and set force to True with the desired version (default to most recent).')
@@ -341,7 +341,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
341
341
 
342
342
  except BadReadme as exc:
343
343
  # something is wrong in the readme after an update was triggered, this shouldn't happen, print more context reraise this
344
- msgs = str(exc)
344
+ msgs = [str(exc)]
345
345
  msgs.append('This should not happen unless multiple sessions are trying to update data at the same time and one experienced problems or was done out of sequence')
346
346
  msgs.append('Check for other updates in progress or choose a different path or clear out this path and try again using pull_data or update_all')
347
347
  print_log_messages(msgs, logger, True)
@@ -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,6 +29,9 @@ 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
+
32
35
  Parameters
33
36
  - path (str) - The location where 'data_update.log' is to be found.
34
37
  - fn_name (str) - A string giving the name of the calling function to be recorded in the lock file.
@@ -37,6 +40,7 @@ def get_data_lock(path, fn_name):
37
40
  - the open file descriptor holding the lock. Close this file descriptor to release the lock.
38
41
 
39
42
  Raises:
43
+ - casaconfig.NoNetwork - raised wheren there is no network, nothing can be downloaded so nothing should be locked.
40
44
  - casaconfig.BadLock - raised when the path to the lock file does not exist or the lock file is not empty as found
41
45
  - Exception - an unexpected exception was seen while writing the lock information to the file
42
46
 
@@ -48,6 +52,11 @@ def get_data_lock(path, fn_name):
48
52
  from datetime import datetime
49
53
 
50
54
  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.")
51
60
 
52
61
  if not os.path.exists(path):
53
62
  raise BadLock("path to contain lock file does not exist : %s" % path)
@@ -0,0 +1,40 @@
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
@@ -32,7 +32,8 @@ def measures_available():
32
32
  version names returned as list of strings
33
33
 
34
34
  Raises:
35
- - casaconfig.RemoteError - raised when when a socket.gaierror is seen, likely due to no network connection
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
36
37
  - Exception: raised when any unexpected exception happens
37
38
 
38
39
  """
@@ -40,7 +41,13 @@ def measures_available():
40
41
  import socket
41
42
 
42
43
  from casaconfig import RemoteError
44
+ from casaconfig import NoNetwork
43
45
 
46
+ from .have_network import have_network
47
+
48
+ if not have_network():
49
+ raise NoNetwork("can not find the list of available measures data")
50
+
44
51
  files = []
45
52
  try:
46
53
  ftp = FTP('ftp.astron.nl')
@@ -119,7 +119,8 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
119
119
  casaconfig.BadReadme - raised when something unexpected is found in the readme or the readme changed after an update is in progress
120
120
  casaconfig.NoReadme - raised when the readme.txt file is not found at path (path also may not exist)
121
121
  casaconfig.NotWritable - raised when the user does not have permission to write to path
122
- casaconfig.RemoteError - raised by measures_available when the remote list of measures could not be fetched
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.
123
124
  casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
124
125
  Exception - raised when something unexpected happened while updating measures
125
126
 
@@ -138,7 +139,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
138
139
  import fcntl
139
140
 
140
141
  from casaconfig import measures_available
141
- from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme
142
+ from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme, NoNetwork
142
143
 
143
144
  from .print_log_messages import print_log_messages
144
145
  from .get_data_lock import get_data_lock
@@ -208,8 +209,11 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
208
209
  # get the current most recent version
209
210
  try:
210
211
  checkVersion = measures_available()[-1]
211
- except RemoteError as exc:
212
+ except NoNetwork as exc:
212
213
  # no network, no point in continuing, just reraise
214
+ raise exc
215
+ except RemoteError as exc:
216
+ # bad network?, no point in continuing, just reraise
213
217
  raise exc
214
218
  except:
215
219
  # unsure what happened, leave it at none, which will trigger an update attempt, which might work
@@ -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,8 +96,9 @@ 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
99
100
  - casaconfig.NotWritable - raised when the user does not have write permission to path
100
- - casaconfig.RemoteError - raised by data_available when the list of available data versions could not be fetched
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
101
102
  - casaconfig.UnsetMeasurespath - raised when path is None and and measurespath has not been set in config.
102
103
 
103
104
  """
@@ -131,7 +132,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
131
132
  available_data = None
132
133
  currentVersion = None
133
134
  currentDate = None
134
-
135
+
135
136
  # attempt a pull if path does not exist or is empty (except for any lock file, handled later)
136
137
  readmeInfo = get_data_info(path, logger, type='casarundata')
137
138
  do_pull = readmeInfo is None
@@ -164,11 +165,11 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
164
165
  # this shouldn't happen
165
166
  # no lock has been set yet, safe to raise this exception without worrying about the lock
166
167
  raise BadReadme('pull_data: the readme.txt file at path did not contain the expected list of installed files')
167
-
168
+
168
169
  # the readme file looks as expected, pull if the version is different or force is true
169
170
  if version is None:
170
171
  # use most recent available
171
- # this may raise a RemoteError, no need to catch that here but it may need to be caught upstream
172
+ # this may raise RemoteError or NoNetwork, no need to catch that here but it may need to be caught upstream
172
173
  available_data = data_available()
173
174
  version = available_data[-1]
174
175
 
@@ -179,16 +180,16 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
179
180
  # safe to return here, no lock has been set
180
181
  print_log_messages('pull_data: version is already at the expected version and force is False. Nothing was changed', logger, verbose=verbose)
181
182
  return
182
-
183
+
183
184
  # a pull will happen, unless the version string is not available
184
185
 
185
186
  if version is None:
186
187
  # need a version, use most recent available
187
-
188
+
188
189
  if available_data is None:
189
- # this may raise a RemoteError, no need to catch that here but it may need to be caught upstream
190
+ # this may raise RemoteError or NoNetwork, no need to catch that here but it may need to be caught upstream
190
191
  available_data = data_available()
191
-
192
+
192
193
  version = available_data[-1]
193
194
 
194
195
  expectedMeasuresVersion = None
@@ -203,9 +204,9 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
203
204
  else:
204
205
  # requested version must be available
205
206
  if available_data is None:
206
- # this may raise a RemoteError, no need to catch that here but it may need to be caught upstream
207
+ # this may raise RemoteError or NoNetwork, no need to catch that here but it may need to be caught upstream
207
208
  available_data = data_available()
208
-
209
+
209
210
  if version not in available_data:
210
211
  print_log_messages('version %s not found on CASA server, use casaconfig.data_available() for a list of casarundata versions' % version, logger, True)
211
212
  return
@@ -224,9 +225,10 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
224
225
  try:
225
226
  print_log_messages('pull_data using version %s, acquiring the lock ... ' % version, logger)
226
227
 
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
227
229
  lock_fd = get_data_lock(path, 'pull_data')
228
230
  # the BadLock exception that may happen here is caught below
229
-
231
+
230
232
  do_pull = True
231
233
  if not force:
232
234
  # need to recheck any readme file that may be present here
@@ -283,7 +285,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
283
285
 
284
286
  except BadLock as exc:
285
287
  # the path is known to exist so this means that the lock file was not empty and it's not locked
286
- msgs = str(exc)
288
+ msgs = [str(exc)]
287
289
  msgs.append('The lock file at %s is not empty.' % path)
288
290
  msgs.append('A previous attempt to update path may have failed or exited prematurely.')
289
291
  msgs.append('It may be best to completely repopulated path using pull_data and measures_update.')
@@ -292,12 +294,16 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
292
294
  raise
293
295
  except BadReadme as exc:
294
296
  # something is wrong in the readme after an update was triggered and locked, this shouldn't happen, print more context and reraise this
295
- msgs = str(exc)
297
+ msgs = [str(exc)]
296
298
  msgs.append('This should not happen unless multiple sessions are trying to update data at the same time and one experienced problems or was done out of sequence')
297
299
  msgs.append('Check for other updates in progress or choose a different path or clear out this path and try again')
298
300
  print_log_messages(msgs, logger, True)
299
301
  raise
300
-
302
+
303
+ except NoNetwork as exc:
304
+ # there is no network, it should be self explanatory so just re-raise it
305
+ raise
306
+
301
307
  except Exception as exc:
302
308
  msgs = []
303
309
  msgs.append('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (version, path))
@@ -311,5 +317,5 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
311
317
  if clean_lock:
312
318
  lock_fd.truncate(0)
313
319
  lock_fd.close()
314
-
320
+
315
321
  return
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: casaconfig
3
- Version: 1.0.2
3
+ Version: 1.2.0
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,3 +265,29 @@ dist
264
265
  ├── casaconfig-[VERSION]-py3-none-any.whl
265
266
  └── casaconfig-[VERSION].tar.gz
266
267
  ```
268
+
269
+ ### Setting up CASA branches for casaconfig development
270
+
271
+ The casaconfig build process publishes test wheels to test.pypi.org
272
+
273
+ In order to test these with Casa packages, two changes are needed in the casa6 repository branch.
274
+
275
+ 1) Add a line to casa6/build.conf with the appropriate wheel version. For example:
276
+
277
+ ```
278
+ casaconfig==1.0.3.dev2
279
+ ```
280
+ 2) Add the following line with the apppropriate branch name to casa6/casatools/setup.py
281
+
282
+ ```
283
+ META_DATA["install_requires"] = "casaconfig@git+https://github.com/casangi/casaconfig@CAS-14512"
284
+ ```
285
+
286
+ 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.
287
+
288
+
289
+ ### Preparing the casa6 branch for merge
290
+
291
+ 1) Merge the casaconfig branch to main and create a wheel
292
+ 2) Update casa6/build.conf to use that wheel
293
+ 3) Comment out the extra "install_requires" line from setup.py
@@ -1,31 +1,32 @@
1
1
  casaconfig/__init__.py,sha256=T-XMwDexm45ndO5gNlpg3kSJoi2EG7TM5VlHHjs70UU,646
2
- casaconfig/__main__.py,sha256=pcuffTdiKEjAkhbQlxGnZzGYf3dSy7CEvWD0kwh7cyU,7440
2
+ casaconfig/__main__.py,sha256=rmkK1hRFQSwNoVDJ3AV8Ht_36VY4DAceglevbcBNHcA,7541
3
3
  casaconfig/config.py,sha256=yIB7h5xwAbK40o7lIAAkXnvmLO_IU9km1XMwdvFx-tg,7172
4
- casaconfig/private/CasaconfigErrors.py,sha256=21T38zLkoCXz0AYx9liVVffjFPDaV5tBLEn9AcDz4uc,1418
4
+ casaconfig/private/CasaconfigErrors.py,sha256=5jgBGiFSussmC7tUAA-w0awYx-7hC6Dhv_OXNihJkkY,1519
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=GNGUgg2V5Y5s2IZWQKaw7zjOFnCi4rEahhH7NI3gaXw,3453
10
- casaconfig/private/data_update.py,sha256=3oqyQab8aqcp2GGTBYBEZ0pBKTGeapU2Uq6BXMxznPg,20623
9
+ casaconfig/private/data_available.py,sha256=hvQGFix5G4C6iJ3_6v05OqHxqMxzecZwAR0-t9Jlhh0,3768
10
+ casaconfig/private/data_update.py,sha256=Ot9SY4249rfU3CMnyg5LFdB5KfnAZsJoGEuHIT5DGZA,20545
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=r2sju4havqRRDaLRbD6aHAKulemuVWH0D16r77xTYjQ,3347
16
+ casaconfig/private/get_data_lock.py,sha256=JysF75EHwP2FErjffMkfeV-9wy5wJJ9irPDrMvVzSIo,3809
17
+ casaconfig/private/have_network.py,sha256=zCIbABTG_9ew9Ac3eb8ggNaZ_H61m_G4LCXkFZe7q5M,1410
17
18
  casaconfig/private/io_redirect.py,sha256=9mwl2siS3fFYCEi_u9Mojg7cBtBgzW00mc8H7V1NSEs,2879
18
- casaconfig/private/measures_available.py,sha256=rTvwuuTrF8hbevvuhzPHqraXJSIZCzsYZvXU9PeLE7A,2061
19
- casaconfig/private/measures_update.py,sha256=diH-GNn87wTlPmXaBbPk-1qv9qY-bnaEO8un8KCr47g,20738
19
+ casaconfig/private/measures_available.py,sha256=OWYmSSUhDqeOGHXBBd6Fwb74O0iJdq8LZx3vIjQNjq4,2343
20
+ casaconfig/private/measures_update.py,sha256=xs84pMWG2263qLlz1y4cFTdUH32QR7ZYxJM3TdhiyRk,21018
20
21
  casaconfig/private/print_log_messages.py,sha256=mZNSxHBgrSz7KTkCEdRgxohSuAPWSgKpF_06sIuyft0,2204
21
- casaconfig/private/pull_data.py,sha256=3_aFBweGbNLSFDm2jS-7TuL32OZFP17_xKaefCAx0OM,17059
22
+ casaconfig/private/pull_data.py,sha256=nYYQLxlf4F6_8uzchfmHn6WvYV4wzjOP58_kc8uZYXk,17385
22
23
  casaconfig/private/read_readme.py,sha256=T9mcG5KhQIHM6N9AgW4XJ2nKsHtI1Fa3iDgr8xMABLM,2137
23
24
  casaconfig/private/set_casacore_path.py,sha256=yLAh4tNoUbWczuCIVpIJx6nx8p9jRm0lUjexrpMhA-A,2240
24
25
  casaconfig/private/summary.py,sha256=jUtc5uLnEk1kljPpZa3UimhJAqVnDzMPUCD7OOznohE,3448
25
26
  casaconfig/private/update_all.py,sha256=57ynk0JJqyMpS1ABmma7F-kFSEnbhU4ZvoSuXQdEJrQ,5501
26
- tests/test_casaconfig.py,sha256=Xmn2hbw0SQ2PJ9BzQCg33EKB4413jvs0qHj5k4Rmfnk,42214
27
- casaconfig-1.0.2.dist-info/LICENSE,sha256=OMpzmn2zUn6I4jmVqs1Coa_0NJcoJC9eweZ2gx-u0oI,11358
28
- casaconfig-1.0.2.dist-info/METADATA,sha256=c_3LjyPjNmd8064vIT-gYdBiHtrbaErmBNYRt-oMwxA,15799
29
- casaconfig-1.0.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
30
- casaconfig-1.0.2.dist-info/top_level.txt,sha256=Uay9WTPz644aHfLbmj47WXzue19HtKRueFFCXu1N1Co,17
31
- casaconfig-1.0.2.dist-info/RECORD,,
27
+ casaconfig-1.2.0.dist-info/licenses/LICENSE,sha256=OMpzmn2zUn6I4jmVqs1Coa_0NJcoJC9eweZ2gx-u0oI,11358
28
+ tests/test_casaconfig.py,sha256=yeycDBOzwHsDeYAyIEmj1RNsZ3k6l7SYXFY-p2F1l7A,43963
29
+ casaconfig-1.2.0.dist-info/METADATA,sha256=FgH21gS9u3DnuaBmrv73BT5loG6czZM224FHqUyqdK8,16981
30
+ casaconfig-1.2.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
31
+ casaconfig-1.2.0.dist-info/top_level.txt,sha256=Uay9WTPz644aHfLbmj47WXzue19HtKRueFFCXu1N1Co,17
32
+ casaconfig-1.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
tests/test_casaconfig.py CHANGED
@@ -750,6 +750,44 @@ 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
+
753
791
  # BadReadme
754
792
 
755
793
  # create a bad data readme.txt file from the valid one