casaconfig 0.0.73__tar.gz → 0.0.75__tar.gz

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.
Files changed (33) hide show
  1. {casaconfig-0.0.73/casaconfig.egg-info → casaconfig-0.0.75}/PKG-INFO +1 -1
  2. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/__main__.py +18 -18
  3. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/config.py +1 -1
  4. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/data_update.py +78 -32
  5. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/do_pull_data.py +4 -2
  6. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/get_data_info.py +63 -29
  7. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/measures_update.py +9 -14
  8. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/pull_data.py +52 -26
  9. casaconfig-0.0.75/casaconfig/private/read_readme.py +60 -0
  10. {casaconfig-0.0.73 → casaconfig-0.0.75/casaconfig.egg-info}/PKG-INFO +1 -1
  11. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig.egg-info/SOURCES.txt +1 -0
  12. {casaconfig-0.0.73 → casaconfig-0.0.75}/setup.py +1 -1
  13. {casaconfig-0.0.73 → casaconfig-0.0.75}/LICENSE +0 -0
  14. {casaconfig-0.0.73 → casaconfig-0.0.75}/MANIFEST.in +0 -0
  15. {casaconfig-0.0.73 → casaconfig-0.0.75}/README.md +0 -0
  16. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/__init__.py +0 -0
  17. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/__init__.py +0 -0
  18. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/casasiteconfig.py +0 -0
  19. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/config_defaults.py +0 -0
  20. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/config_defaults_static.py +0 -0
  21. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/data_available.py +0 -0
  22. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/get_argparser.py +0 -0
  23. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/get_config.py +0 -0
  24. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/get_data_lock.py +0 -0
  25. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/io_redirect.py +0 -0
  26. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/measures_available.py +0 -0
  27. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/print_log_messages.py +0 -0
  28. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/set_casacore_path.py +0 -0
  29. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig/private/update_all.py +0 -0
  30. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig.egg-info/dependency_links.txt +0 -0
  31. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig.egg-info/requires.txt +0 -0
  32. {casaconfig-0.0.73 → casaconfig-0.0.75}/casaconfig.egg-info/top_level.txt +0 -0
  33. {casaconfig-0.0.73 → casaconfig-0.0.75}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: casaconfig
3
- Version: 0.0.73
3
+ Version: 0.0.75
4
4
  Summary: CASA Operational Configuration Package
5
5
  Home-page: https://github.com/casangi/casaconfig
6
6
  Author: National Radio Astronomy Observatory
@@ -41,17 +41,17 @@ if flags.measurespath is None:
41
41
  print("Either provide a measurespath on the casaconfig command line or edit casasiteconfig.py or other a user config.py to set measurespath to a location.")
42
42
  sys.exit(1)
43
43
 
44
- # do any expanduser and abspath
44
+ # do any expanduser and abspath - this is what should be used
45
45
  measurespath = os.path.abspath(os.path.expanduser(flags.measurespath))
46
46
 
47
47
  if flags.currentdata:
48
48
  if not os.path.exists(measurespath) or not os.path.isdir(measurespath):
49
- print("No data installed at %s. The measurespath does not exist or is not a directory." % flags.measurespath)
49
+ print("No data installed at %s. The measurespath does not exist or is not a directory." % measurespath)
50
50
  else:
51
51
  # casarundata
52
52
  datareadme = os.path.join(measurespath,'readme.txt')
53
53
  if not os.path.exists(datareadme):
54
- print("No casarundata installed in %s (missing readme.txt)." % flags.measurespath)
54
+ print("No casarundata installed in %s (missing readme.txt)." % measurespath)
55
55
  else:
56
56
  try:
57
57
  with open(datareadme, 'r') as fid:
@@ -60,14 +60,14 @@ if flags.currentdata:
60
60
  currentDate = readme[2].split(':')[1].strip()
61
61
  print('casarundata version %s installed on %s' % (currentVersion, currentDate))
62
62
  if (len(readme)<4):
63
- print(' casarundata appears to be too short, missing list of installed files, casarundata should be repopulated in %s' % flags.measurespath)
63
+ print(' casarundata appears to be too short, missing list of installed files, casarundata should be repopulated in %s' % measurespath)
64
64
  except:
65
- print('There was a problem reading the casarundata readme.txt, casarundata should be repopulated in %s' % flags.measurespath)
65
+ print('There was a problem reading the casarundata readme.txt, casarundata should be repopulated in %s' % measurespath)
66
66
 
67
67
  # measures
68
68
  measuresreadme = os.path.join(measurespath,'geodetic/readme.txt')
69
69
  if not os.path.exists(measuresreadme):
70
- print("No measures data installed in %s/geodetic (missing readme.txt)." % flags.measurespath)
70
+ print("No measures data installed in %s/geodetic (missing readme.txt)." % measurespath)
71
71
  else:
72
72
  try:
73
73
  with open(measuresreadme, 'r') as fid:
@@ -76,32 +76,32 @@ if flags.currentdata:
76
76
  currentDate = readme[2].split(':')[1].strip()
77
77
  print('measures version %s installed on %s' % (currentVersion, currentDate))
78
78
  except:
79
- print('There was a problem reading the measures readme.txt, measures should be repopulated in %s' % flags.measurespath)
79
+ print('There was a problem reading the measures readme.txt, measures should be repopulated in %s' % measurespath)
80
80
 
81
81
  # ignore any other arguments
82
82
 
83
83
  else:
84
84
  if flags.referencetesting:
85
- print("--reference-testing is not yet implemented, measurespath=%s" % flags.measurespath)
86
- # ignore any other arguments
87
-
85
+ print("reference testing using pull_data and 'release' version into %s" % measurespath)
86
+ casaconfig.pull_data(measurespath,'release')
87
+ # ignore all other options
88
88
  else:
89
89
  # the update options, update all does everything, no need to invoke anything else
90
90
  if flags.updateall:
91
- print("data_update then measures_update using path=%s" % flags.measurespath)
92
- casaconfig.update_all(flags.measurespath)
91
+ print("data_update then measures_update using path=%s" % measurespath)
92
+ casaconfig.update_all(measurespath)
93
93
  else:
94
94
  # do any pull_update first
95
95
  if flags.pulldata:
96
- print("pull_data using path=%s" % flags.measurespath)
97
- casaconfig.pull_data(flags.measurespath)
96
+ print("pull_data using path=%s" % measurespath)
97
+ casaconfig.pull_data(measurespath)
98
98
  # then data_update, not necessary if pull_data just happened
99
99
  if flags.dataupdate and not flags.pulldata:
100
- print("data_update using path=%s" % flags.measurespath)
101
- casaconfig.data_update(flags.measurespath)
100
+ print("data_update using path=%s" % measurespath)
101
+ casaconfig.data_update(measurespath)
102
102
  # then measures_update
103
103
  if flags.measuresupdate:
104
- print("measures_update using path=%s" % flags.measurespath)
105
- casaconfig.measures_update(flags.measurespath)
104
+ print("measures_update using path=%s" % measurespath)
105
+ casaconfig.measures_update(measurespath)
106
106
 
107
107
  sys.exit(0)
@@ -46,7 +46,7 @@ __defaults = [ x for x in dir(_config_defaults) if not x.startswith('_') ]
46
46
  __parser = __get_argparser()
47
47
  __flags,__args = __parser.parse_known_args(__sys.argv)
48
48
  __user_config = [ ] if __flags.noconfig else [ __flags.configfile ]
49
- __site_config = [ ] if __flags.nositeconfig else [ 'casaconfigsite' ]
49
+ __site_config = [ ] if __flags.nositeconfig else [ 'casasiteconfig' ]
50
50
 
51
51
  ## files to be evaluated/loaded
52
52
  __config_files = [ * __site_config , *__user_config ]
@@ -30,6 +30,11 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
30
30
  If the version is None (the default) then the most recent version returned by
31
31
  data_available is used.
32
32
 
33
+ If version is "release" then the version associated with the release in
34
+ the dictionary returned by get_data_info is used. If there is no release
35
+ version information known then an error message is printed and nothing is
36
+ updated.
37
+
33
38
  If the version requested matches the one in the readme.txt file at path then this function does
34
39
  nothing unless force is True.
35
40
 
@@ -94,6 +99,8 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
94
99
  from .print_log_messages import print_log_messages
95
100
  from .get_data_lock import get_data_lock
96
101
  from .do_pull_data import do_pull_data
102
+ from .get_data_info import get_data_info
103
+ from .read_readme import read_readme
97
104
 
98
105
  if path is None:
99
106
  from .. import config as _config
@@ -134,15 +141,12 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
134
141
  installed_files = []
135
142
  currentVersion = []
136
143
  currentDate = []
137
- try:
138
- with open(readme_path, 'r') as fid:
139
- readme = fid.readlines()
140
- currentVersion = readme[1].split(':')[1].strip()
141
- currentDate = readme[2].split(':')[1].strip()
142
- for readme_line in readme[3:]:
143
- if (readme_line[0] != '#'):
144
- installed_files.append(readme_line.strip())
145
- except:
144
+ dataReadmeInfo = read_readme(readme_path)
145
+ if dataReadmeInfo is not None:
146
+ currentVersion = dataReadmeInfo['version']
147
+ currentDate = dataReadmeInfo['date']
148
+ installed_files = dataReadmeInfo['extra']
149
+ else:
146
150
  print_log_messages('The readme.txt file at path could not be read as expected', logger, True)
147
151
  print_log_messages('choose a different path or empty this path and try again using pull_data', logger, True)
148
152
  # no lock has been set yet, safe to simply return here
@@ -164,9 +168,20 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
164
168
 
165
169
  available_data = data_available()
166
170
  requestedVersion = version
171
+
167
172
  if requestedVersion is None:
168
173
  requestedVersion = available_data[-1]
169
-
174
+
175
+ expectedMeasuresVersion = None
176
+ if requestedVersion is 'release':
177
+ # use the release version from get_data_info
178
+ releaseInfo = get_data_info()['release']
179
+ if releaseInfo is None:
180
+ print_log_messages('No release info found, pull_data can not continue', logger, True)
181
+ return
182
+ requestedVersion = releaseInfo['casarundata']
183
+ expectedMeasuresVersion = releaseInfo['measures']
184
+
170
185
  if requestedVersion not in available_data:
171
186
  print_log_messages('Requested casarundata version %s was not found. See available_data for a list of available casarundata versions.' % requestedVersion)
172
187
  # no lock has been set yet, safe to simply return here
@@ -174,9 +189,28 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
174
189
 
175
190
  # don't update if force is false and the requested version is already installed
176
191
  if force is False and (currentVersion == requestedVersion):
177
- print_log_messages('Requested casarundata is installed in %s, using version %s' % (path, currentVersion), logger)
178
- # no lock has been set yet, safe to simply return here
179
- return
192
+ if expectedMeasuresVersion is not None:
193
+ # the 'release' version has been requested, need to check the measures version
194
+ # assume a force is necessary until the measures version is known to be OK
195
+ force = True
196
+ measures_readme_path = os.path.join(path,'geodetic/readme.txt')
197
+ if os.path.exists(measures_readme_path):
198
+ measuresReadmeInfo = read_readme(measures_readme_path)
199
+ if measuresReadmeInfo is not None:
200
+ measuresVersion = measuresReadmeInfo['version']
201
+ if measuresVersion == expectedMeasuresVersion:
202
+ # it's OK, do not force
203
+ force = False
204
+ # if measuresReadmeInfo is None then that's a problem and force remains True
205
+ if not force:
206
+ print_log_messages('data_update requested "release" version of casarundata and measures are already installed.', logger)
207
+ # no lock has been set yet, safe to simply return here
208
+ return
209
+ else:
210
+ # normal usage, ok to return now
211
+ print_log_messages('Requested casarundata is installed in %s, using version %s' % (path, currentVersion), logger)
212
+ # no lock has been set yet, safe to simply return here
213
+ return
180
214
 
181
215
  # an update appears necessary
182
216
 
@@ -195,35 +229,47 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
195
229
 
196
230
  do_update = True
197
231
  # it's possible that another process had path locked and updated the readme with new information, re-read it
198
- try :
199
- readme = None
200
- with open(readme_path, 'r') as fid:
201
- readme = fid.readlines()
202
- currentVersion = readme[1].split(':')[-1].strip()
203
- currentDate = readme[2].split(':')[-1].strip()
232
+ dataReadmeInfo = read_readme(readme_path)
233
+ if dataReadmeInfo is not None:
234
+ currentVersion = dataReadmeInfo['version']
235
+ currentDate = dataReadmeInfo['date']
236
+ installedFiles = dataReadmeInfo['extra']
204
237
  if ((currentVersion == requestedVersion) and (not force)):
205
- # nothing to do here, already at the expected version and an update is not being forced
206
- do_update = False
207
- print_log_messages('data_update requested version is already installed.', logger)
208
- else:
209
- installed_files = []
210
- for readme_line in readme[3:]:
211
- installed_files.append(readme_line.strip())
238
+ if expectedMeasuresVersion is not None:
239
+ # this is a 'release' update request, need to check that the measures version is also now OK
240
+ measures_readme_path = os.path.update(path,'geodetic/readme.txt')
241
+ if os.path.exists(measures_readme_path):
242
+ measuresReadmeInfo = read_readme(measures_readme_path)
243
+ if measuresReadmeInfo is not None:
244
+ measuresVersion = measuresReadmeInfo['version']
245
+ if measuresVersion == expectedMeasuresVersion:
246
+ do_update = False
247
+ # if measuresReadmeInfo is None there was a problem which requires a full update so do_update remains True
248
+ if not do_update:
249
+ print_log_messages('data update requested "release" version of casarundata and measures are already installed.', logger)
250
+ else:
251
+ # nothing to do here, already at the expected version and an update is not being forced
252
+ do_update = False
253
+ print_log_messages('data_update requested version is already installed.', logger)
254
+
255
+ if do_update:
256
+ # update is still on, check the manifest
212
257
  if len(installed_files) == 0:
213
258
  # this shouldn't happen, do not do an update
214
259
  do_update = False
215
260
  print_log_messages('The readme.txt file read at path did not contain the expected list of installed files', logger, True)
216
261
  print_log_messages('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', logger, True)
217
- print_log_messages('Check for other updates in process or choose a different path or clear out this path and try again using pull', logger, True)
218
- except:
262
+ print_log_messages('Check for other updates in process or choose a different path or clear out this path and try again using pull_data or update_all', logger, True)
263
+ else:
219
264
  # this shouldn't happen, do not do an update
220
265
  do_update = False
221
- print_log_messages('Unexpected error reading readme.txt file during data_update, can not safely update to the requested version', logger, True)
266
+ print_log_messages('Unexpected problem reading readme.txt file during data_update, can not safely update to the requested version', logger, True)
222
267
  print_log_messages('This should not happen unless multiple sessions are trying to update at the same time and one experienced problems or was done out of sequence', logger, True)
268
+ print_log_messages('Check for other updates in process or choose a different path or clear out this path and try again using pull_data or update_all', logger, True)
223
269
 
224
270
 
225
271
  if do_update:
226
- do_pull_data(path, requestedVersion, installed_files, logger)
272
+ do_pull_data(path, requestedVersion, installed_files, currentVersion, currentDate, logger)
227
273
 
228
274
  # truncate the lock file
229
275
  lock_fd.truncate(0)
@@ -232,8 +278,8 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
232
278
  print_log_messages('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (requestedVersion, path), logger, True)
233
279
  print_log_messages('ERROR! : %s' % exc, logger, True)
234
280
  # leave the contents of the lock file as is to aid in debugging
235
- import traceback
236
- traceback.print_exc()
281
+ # import traceback
282
+ # traceback.print_exc()
237
283
 
238
284
  # if the lock file is not closed, do that now to release the lock
239
285
  if lock_fd is not None and not lock_fd.closed:
@@ -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.
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- def do_pull_data(path, version, installed_files, logger):
15
+ def do_pull_data(path, version, installed_files, currentVersion, currentDate, logger):
16
16
  """
17
17
  Pull the casarundata for the given version and install it in path, removing
18
18
  the isntalled files and updating the readme.txt file when done.
@@ -27,6 +27,8 @@ def do_pull_data(path, version, installed_files, logger):
27
27
  - path (str) - Folder path to place casadata contents.
28
28
  - version (str) - casadata version to retrieve.
29
29
  - installed_files (str list) - list of installed files from the version already installed. Set to an empty list if there is no previously installed version.
30
+ - currentVersion (str) - from the readme file if it already exists, or an empty string if there is no previously installed version.
31
+ - currentDate (str) - from the readme file if it already exists, or an empty string if there is no previously installed version.
30
32
  - logger (casatools.logsink) - Instance of the casalogger to use for writing messages. Messages are always written to the terminal. Set to None to skip writing messages to a logger.
31
33
 
32
34
  Returns
@@ -25,16 +25,16 @@ def get_data_info(path=None, logger=None):
25
25
  The path is the location to use to search for the installed release information.
26
26
  The path argument defaults to config.measurespath when not set.
27
27
 
28
- For each type the value is a dictionary of 'version' and 'date' where
29
- version is the version string and date is the date when it was installed.
30
- These values are taken from the readme.txt file for each type.
28
+ The casarundata and measures type value are each a dictionary of 'version'
29
+ and 'date' where version is the version string and date is the date when it
30
+ was installed These values are taken from the readme.txt file for each type.
31
31
 
32
32
  The 'release' type is from the release_data_readme.txt file which is copied
33
- into place when a modular CASA is built. It is the release.txt for the
34
- data appropriate for that module CASA release and it used by the "--reference-testing"
35
- command line option for casaconfig. That allows casaconfig to install that
33
+ into place when a modular CASA is built. It consists of a dictionary of
34
+ 'casarundata' and 'measures' where the values are the version strings for each
35
+ type of data for this release. That allows casaconfig to install that
36
36
  casarundata version for testing purposes. The release information does not depend
37
- on the path argument.
37
+ on the path argument since it is found in the casaconfig module.
38
38
 
39
39
  If path is empty or does not exist then the return value for the 'casarundata' and
40
40
  'measures' types is None.
@@ -51,7 +51,7 @@ def get_data_info(path=None, logger=None):
51
51
  a legacy installation of CASA data. CASA may be able to use any measures tables at this
52
52
  location by they can not be maintained by casaconfig.
53
53
 
54
- If no casadata release information is found the returned
54
+ If no casadata release information is found or the contents are unexpected the returned
55
55
  value for 'release' is None and the "--reference-testing" option will not do anything
56
56
  for this installation of casaconfig. This will be the case for a modular installation.
57
57
 
@@ -72,6 +72,7 @@ def get_data_info(path=None, logger=None):
72
72
  import os
73
73
  import importlib.resources
74
74
  from .print_log_messages import print_log_messages
75
+ from .read_readme import read_readme
75
76
 
76
77
  if path is None:
77
78
  from .. import config as _config
@@ -94,16 +95,14 @@ def get_data_info(path=None, logger=None):
94
95
  datareadme_path = os.path.join(path,'readme.txt')
95
96
  if os.path.exists(datareadme_path):
96
97
  # the readme exists, get the info
97
- try:
98
- with open(datareadme_path, 'r') as fid:
99
- readme = fid.readlines()
100
- currentVersion = readme[1].split(':')[1].strip()
101
- currentDate = readme[2].split(':')[1].strip()
102
- # this one is just a check that there's the manifest is probably also OK
103
- line4 = readme[4]
98
+ result['casarundata'] = {'version':'error', 'date':''}
99
+ readmeContents = read_readme(datareadme_path)
100
+ if readmeContents is not None:
101
+ currentVersion = readmeContents['version']
102
+ currentDate = readmeContents['date']
103
+ # this one is just a check that the manifest at least exists
104
+ if len(readmeContents['extra']) > 0:
104
105
  result['casarundata'] = {'version':currentVersion, 'date':currentDate}
105
- except:
106
- result['casarundata'] = {'version':'error', 'date':''}
107
106
  else:
108
107
  # does it look like it's probably casarundata?
109
108
  expected_dirs = ['alma','catalogs','demo','ephemerides','geodetic','gui','nrao']
@@ -121,14 +120,12 @@ def get_data_info(path=None, logger=None):
121
120
  measuresreadme_path = os.path.join(path,'geodetic/readme.txt')
122
121
  if os.path.exists(measuresreadme_path):
123
122
  # the readme exists, get the info
124
- try:
125
- with open(measuresreadme_path, 'r') as fid:
126
- readme = fid.readlines()
127
- currentVersion = readme[1].split(':')[1].strip()
128
- currentDate = readme[2].split(':')[1].strip()
129
- result['measures'] = {'version':currentVersion, 'date':currentDate}
130
- except:
131
- result['measures'] = {'version':'error', 'date':''}
123
+ result['measures'] = {'version':'error', 'date':''}
124
+ readmeContents = read_readme(measuresreadme_path)
125
+ if readmeContents is not None:
126
+ currentVersion = readmeContents['version']
127
+ currentDate = readmeContents['date']
128
+ result['measures'] = {'version':currentVersion,'date':currentDate}
132
129
  else:
133
130
  # does it look like it's probably measuresdata?
134
131
  # path should have ephemerides and geodetic directories
@@ -141,12 +138,49 @@ def get_data_info(path=None, logger=None):
141
138
  # release data versions
142
139
  if importlib.resources.is_resource('casaconfig','release_data_readme.txt'):
143
140
  try:
141
+ casarundataVersion = None
142
+ measuresVersion = None
143
+ ok = True
144
+ reason = None
144
145
  readme_lines = importlib.resources.read_text('casaconfig','release_data_readme.txt').split('\n')
145
- currentVersion = readme_lines[1].split(':')[1].strip()
146
- currentDate = readme_lines[2].split(':')[1].strip()
147
- result['release'] = {'version':currentVersion, 'date':currentDate}
146
+ for readmeLine in readme_lines:
147
+ # lines must contain something and not start with #
148
+ if len(readmeLine) > 0 and readmeLine[0] != '#':
149
+ splitLine = readmeLine.split(':')
150
+ if len(splitLine) == 2:
151
+ lineType = splitLine[0].strip()
152
+ lineVers = splitLine[1].strip()
153
+ if lineType == 'casarundata':
154
+ if casarundataVersion is not None:
155
+ ok = False
156
+ reason = "duplicate casarundata lines"
157
+ break
158
+ casarundataVersion = lineVers
159
+ elif lineType == 'measures':
160
+ if measuresVersion is not None:
161
+ ok = False
162
+ reason = "duplicate measures lins"
163
+ break
164
+ measuresVersion = lineVers
165
+ else:
166
+ ok = False
167
+ reason = "Unexpected type : %s" % lineType
168
+ break
169
+ else:
170
+ ok = False
171
+ reason = "Missing or too many ':' separators"
172
+ if (casarundataVersion is None or measuresVersion is None) and ok:
173
+ ok = False
174
+ reason = "missing one or more version strings for expected casarundata and measures types"
175
+
176
+ if not ok:
177
+ print_log_messages("Incorrectly formatted release_data_readme.txt. %s" % reason, logger, True)
178
+ # leave 'release' as None
179
+ else:
180
+ result['release'] = {'casarundata':casarundataVersion, 'measures':measuresVersion}
148
181
  except:
149
- result['release'] = {'version':'error', 'date':''}
182
+ print("Unexpected error reading release_data_readme.txt")
183
+ # leave 'release' as None
150
184
  else:
151
185
  # no release information available, probably a modular install only
152
186
  # leave 'release' as None
@@ -106,6 +106,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
106
106
 
107
107
  from .print_log_messages import print_log_messages
108
108
  from .get_data_lock import get_data_lock
109
+ from .read_readme import read_readme
109
110
 
110
111
  if path is None:
111
112
  from .. import config as _config
@@ -142,13 +143,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
142
143
  # if measures are already preset, get their version
143
144
  readme_path = os.path.join(path,'geodetic/readme.txt')
144
145
  if os.path.exists(readme_path):
145
- try:
146
- with open(readme_path, 'r') as fid:
147
- readme = fid.readlines()
148
- current = readme[1].split(':')[-1].strip()
149
- updated = readme[2].split(':')[-1].strip()
150
- except:
151
- pass
146
+ readmeInfo = read_readme(readme_path)
147
+ if readmeInfo is not None:
148
+ current = readmeInfo['version']
149
+ updated = readmeInfo['date']
152
150
 
153
151
  # don't re-download the same data
154
152
  if not force:
@@ -184,13 +182,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
184
182
  current = None
185
183
  updated = None
186
184
  if os.path.exists(readme_path):
187
- try:
188
- with open(readme_path, 'r') as fid:
189
- readme = fid.readlines()
190
- current = readme[1].split(':')[-1].strip()
191
- updated = readme[2].split(':')[-1].strip()
192
- except:
193
- pass
185
+ readmeInfo = read_readme(readme_path)
186
+ if readmeInfo is not None:
187
+ current = readmeInfo['version']
188
+ updated = readmeInfo['date']
194
189
 
195
190
  if ((version is not None) and (version == current)) or ((version is None) and (updated == today_string)):
196
191
  # no update will be done, version is as requested or it's already been updated today
@@ -26,6 +26,11 @@ def pull_data(path=None, version=None, force=False, logger=None):
26
26
 
27
27
  If version is None (the default) then the most recent version is pulled.
28
28
 
29
+ If version is "release" then the version associated with the release in
30
+ the dictionary returned by get_data_info is used. If there is no release
31
+ version information known then an error message is printed and nothing is
32
+ updated.
33
+
29
34
  A text file (readme.txt at path) records the version string, the date
30
35
  when that version was installed in path, and the files installed into path.
31
36
  This file is used to determine if the contents are a previously installed
@@ -78,6 +83,8 @@ def pull_data(path=None, version=None, force=False, logger=None):
78
83
  from .print_log_messages import print_log_messages
79
84
  from .get_data_lock import get_data_lock
80
85
  from .do_pull_data import do_pull_data
86
+ from .get_data_info import get_data_info
87
+ from .read_readme import read_readme
81
88
 
82
89
  if path is None:
83
90
  from .. import config as _config
@@ -101,15 +108,12 @@ def pull_data(path=None, version=None, force=False, logger=None):
101
108
  if not do_pull:
102
109
  # if the readme_path exists, find the current version, install date, and installed files
103
110
  if os.path.exists(readme_path):
104
- try:
105
- with open(readme_path,'r') as fid:
106
- readme = fid.readlines()
107
- currentVersion = readme[1].split(':')[1].strip()
108
- currentDate = readme[2].split(':')[1].strip()
109
- for readme_line in readme[3:]:
110
- if (readme_line[0] != "#"):
111
- installed_files.append(readme_line.strip())
112
- except:
111
+ readmeInfo = read_readme(readme_path)
112
+ if readmeInfo is not None:
113
+ currentVersion = readmeInfo['version']
114
+ currentDate = readmeInfo['date']
115
+ installed_files = readmeInfo['extra']
116
+ else:
113
117
  print_log_messages('destination path is not empty and the readme.txt file found there could not be read as expected', logger, True)
114
118
  print_log_messages('choose a different path or empty this path and try again', logger, True)
115
119
  # no lock has been set yet, safe to simply return here
@@ -149,6 +153,16 @@ def pull_data(path=None, version=None, force=False, logger=None):
149
153
  # need a version, use most recent available
150
154
  version = available_data[-1]
151
155
 
156
+ expectedMeasuresVersion = None
157
+ if version is 'release':
158
+ # use the release version from get_data_info
159
+ releaseInfo = get_data_info()['release']
160
+ if releaseInfo is None:
161
+ print_log_messages('No release info found, pull_data can not continue', logger, True)
162
+ return
163
+ version = releaseInfo['casarundata']
164
+ expectedMeasuresVersion = releaseInfo['measures']
165
+
152
166
  if version not in available_data:
153
167
  print_log_messages('version %s not found on CASA server, use casaconfig.data_available for a list of casarundata versions' % version, logger, True)
154
168
  return
@@ -175,35 +189,47 @@ def pull_data(path=None, version=None, force=False, logger=None):
175
189
  if not force and os.path.exists(readme_path):
176
190
  # the readme file needs to be reread here
177
191
  # it's possible that another process had path locked and updated the readme file with new information
178
- try :
179
- readme = None
180
- with open(readme_path, 'r') as fid:
181
- readme = fid.readlines()
182
- currentVersion = readme[1].split(':')[-1].strip()
183
- currentDate = readme[2].split(':')[-1].strip()
192
+ readmeInfo = read_readme(readme_path)
193
+ if readmeInfo is not None:
194
+ currentVersion = readmeInfo['version']
195
+ currentDate = readmeInfo['date']
184
196
  if ((currentVersion == version) and (not force)):
185
- # nothing to do here, already at the expected version a pull is not being forced
186
- do_pull = False
187
- print_log_messages('pull_data requested version is already installed.', logger)
188
- else:
197
+ if expectedMeasuresVersion is not None:
198
+ # this is a release pull and the measures version must also match
199
+ # start off assuming a pull is necessary
200
+ do_pull = True
201
+ measures_readme_path = os.path.join(path,'geodetic/readme.txt')
202
+ if os.path.exists(measures_readme_path):
203
+ measuresReadmeInfo = read_readme(measures_readme_path)
204
+ if measuresReadmeInfo is not None:
205
+ measuresVersion = measuresReadmeInfo['version']
206
+ if measuresVersion == expectedMeasuresVersion:
207
+ # no pull is necessary
208
+ do_pull = False
209
+ print_log_messages('pull_data requested "release" versions of casarundata and measures are already installed.', logger)
210
+ # otherwise the measures readme info is suspect and the pull should happen
211
+ else:
212
+ # nothing to do here, already at the expected version and a pull is not being forced
213
+ do_pull = False
214
+ print_log_messages('pull_data requested version is already installed.', logger)
215
+
216
+ if do_pull:
189
217
  # make sure the copy of installed_files is the correct one
190
- installed_files = []
191
- for readme_line in readme[3:]:
192
- installed_files.append(readme_line.strip())
218
+ installed_files = readmeInfo['extra']
193
219
  if len(installed_files) == 0:
194
220
  # this shoudn't happen, do not do a pull
195
221
  do_pull = False
196
222
  print_log_messages('destination path is not empty and the readme.txt file found there did not contain the expected list of installed files', logger, True)
197
223
  print_log_messages('This should not happen unless multiple sessions are trying to pull_data at the same time and one experienced problems or was done out of sequence', logger, True)
198
224
  print_log_messages('Check for other updates in process or choose a different path or clear out this path and try again', logger, True)
199
- except:
225
+ else:
200
226
  # this shouldn't happen, do not do a pull
201
227
  do_pull = False
202
228
  print_log_messages('Unexpected error reading readme.txt file during pull_data, can not safely pull the requested version', logger, True)
203
229
  print_log_messages('This should not happen unless multiple sessions are trying to pull_data at the same time and one experienced problems or was done out of sequence', logger, True)
204
230
 
205
231
  if do_pull:
206
- do_pull_data(path, version, installed_files, logger)
232
+ do_pull_data(path, version, installed_files, currentVersion, currentDate, logger)
207
233
 
208
234
  # truncate the lock file
209
235
  lock_fd.truncate(0)
@@ -212,8 +238,8 @@ def pull_data(path=None, version=None, force=False, logger=None):
212
238
  print_log_messages('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (version, path), logger, True)
213
239
  print_log_messages('ERROR! : %s' % exc, logger, True)
214
240
  # leave the contents of the lock file as is to aid in debugging
215
- import traceback
216
- traceback.print_exc()
241
+ # import traceback
242
+ # traceback.print_exc()
217
243
 
218
244
  # if the lock file is not closed, do that now to release the lock
219
245
  if lock_fd is not None and not lock_fd.closed:
@@ -0,0 +1,60 @@
1
+ # Copyright 2023 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
+ def read_readme(path):
16
+ """
17
+ Read and parse the contents of a readme.txt file used by casaconfig.
18
+
19
+ A dictionary containing the 'version', 'date', and 'extra' (containing
20
+ a list of optional extra lines found). On error, the return values is None.
21
+
22
+ The extra lines are stripped and do not include lines begining with '#'
23
+
24
+ The format is assumed to be:
25
+ a line begining with #, which is ignored.
26
+ a line "version : the versions string"
27
+ a line "date : the date"
28
+ optional extra lines (the manifest of installed files for the main readme)
29
+
30
+ The version string and date are stripped of leading and trailing whitespace.
31
+
32
+ Parameters
33
+ - path (str) - the path to the file to be read
34
+
35
+ Returns
36
+ Dictionary of 'version' (the version string), 'date' (the date string),
37
+ 'extra' (a list of any extra lines found). The return value is None on error.
38
+ """
39
+
40
+ import os
41
+
42
+ version = ""
43
+ date = ""
44
+ extra = []
45
+ result = None
46
+
47
+ try:
48
+ with open(path, 'r') as fid:
49
+ readmeLines = fid.readlines()
50
+ version = readmeLines[1].split(':')[1].strip()
51
+ date = readmeLines[2].split(':')[1].strip()
52
+ if len(readmeLines) > 3:
53
+ for extraLine in readmeLines[3:]:
54
+ if (extraLine[0] != '#'):
55
+ extra.append(extraLine.strip())
56
+ result = {'version':version, 'date':date, 'extra':extra}
57
+ except:
58
+ pass
59
+
60
+ return result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: casaconfig
3
- Version: 0.0.73
3
+ Version: 0.0.75
4
4
  Summary: CASA Operational Configuration Package
5
5
  Home-page: https://github.com/casangi/casaconfig
6
6
  Author: National Radio Astronomy Observatory
@@ -26,5 +26,6 @@ casaconfig/private/measures_available.py
26
26
  casaconfig/private/measures_update.py
27
27
  casaconfig/private/print_log_messages.py
28
28
  casaconfig/private/pull_data.py
29
+ casaconfig/private/read_readme.py
29
30
  casaconfig/private/set_casacore_path.py
30
31
  casaconfig/private/update_all.py
@@ -6,7 +6,7 @@ with open('README.md', "r") as fid: #encoding='utf-8'
6
6
 
7
7
  setup(
8
8
  name='casaconfig',
9
- version='0.0.73',
9
+ version='0.0.75',
10
10
  description='CASA Operational Configuration Package',
11
11
  long_description=long_description,
12
12
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes