casaconfig 0.0.80__tar.gz → 0.0.81__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 (34) hide show
  1. {casaconfig-0.0.80/casaconfig.egg-info → casaconfig-0.0.81}/PKG-INFO +1 -1
  2. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/__main__.py +10 -5
  3. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/config.py +3 -8
  4. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/data_update.py +66 -28
  5. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/do_auto_updates.py +10 -7
  6. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/measures_update.py +98 -43
  7. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/print_log_messages.py +11 -2
  8. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/pull_data.py +44 -30
  9. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/update_all.py +9 -4
  10. {casaconfig-0.0.80 → casaconfig-0.0.81/casaconfig.egg-info}/PKG-INFO +1 -1
  11. {casaconfig-0.0.80 → casaconfig-0.0.81}/setup.py +1 -1
  12. {casaconfig-0.0.80 → casaconfig-0.0.81}/LICENSE +0 -0
  13. {casaconfig-0.0.80 → casaconfig-0.0.81}/MANIFEST.in +0 -0
  14. {casaconfig-0.0.80 → casaconfig-0.0.81}/README.md +0 -0
  15. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/__init__.py +0 -0
  16. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/__init__.py +0 -0
  17. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/casasiteconfig.py +0 -0
  18. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/config_defaults.py +0 -0
  19. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/config_defaults_static.py +0 -0
  20. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/data_available.py +0 -0
  21. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/do_pull_data.py +0 -0
  22. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/get_argparser.py +0 -0
  23. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/get_config.py +0 -0
  24. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/get_data_info.py +0 -0
  25. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/get_data_lock.py +0 -0
  26. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/io_redirect.py +0 -0
  27. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/measures_available.py +0 -0
  28. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/read_readme.py +0 -0
  29. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig/private/set_casacore_path.py +0 -0
  30. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig.egg-info/SOURCES.txt +0 -0
  31. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig.egg-info/dependency_links.txt +0 -0
  32. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig.egg-info/requires.txt +0 -0
  33. {casaconfig-0.0.80 → casaconfig-0.0.81}/casaconfig.egg-info/top_level.txt +0 -0
  34. {casaconfig-0.0.80 → casaconfig-0.0.81}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: casaconfig
3
- Version: 0.0.80
3
+ Version: 0.0.81
4
4
  Summary: CASA Operational Configuration Package
5
5
  Home-page: https://github.com/casangi/casaconfig
6
6
  Author: National Radio Astronomy Observatory
@@ -7,6 +7,8 @@ parser = get_argparser(add_help=True)
7
7
  # get_argparser supplies configfile, noconfig, nositeconfig
8
8
  # add measurespath, pull-data, data-update, measures-update, update-all, reference-testing, current-data
9
9
 
10
+ parser.prog = "casaconfig"
11
+
10
12
  # measurespath will default to the value in config if not set here
11
13
  parser.add_argument( "--measurespath", dest='measurespath', default=None,
12
14
  help="location of casarundata")
@@ -23,6 +25,8 @@ parser.add_argument( "--reference-testing", action='store_const', const=True, de
23
25
  help="set measurespath to the casarundata when this version was produced, used for testing purposes")
24
26
  parser.add_argument( "--current-data", dest='currentdata', action='store_const', const=True, default=False,
25
27
  help="print out a summary of the current casarundata and measures data installed in measurespath and then exit")
28
+ parser.add_argument("--force", dest='force', action='store_const', const=True, default=False,
29
+ help="force an update using the force=True option to update_all, data_update, and measures_update")
26
30
 
27
31
  # initialize the configuration to be used
28
32
  flags,args = parser.parse_known_args(sys.argv)
@@ -65,8 +69,8 @@ if flags.currentdata:
65
69
 
66
70
  # measures
67
71
  measuresInfo = dataInfo['measures']
68
- if measuresInfo is None or casarunInfo['version'] == "invalid":
69
- print("No measures data found (missing or unexpected readme.txt, not obviously legaca measures data).")
72
+ if measuresInfo is None or measuresInfo['version'] == "invalid":
73
+ print("No measures data found (missing or unexpected readme.txt, not obviously legacy measures data).")
70
74
  elif measuresInfo['version'] == "unknown":
71
75
  print("measures version is unknown (probably legacy measures data not maintained by casaconfig).")
72
76
  else:
@@ -83,17 +87,18 @@ else:
83
87
  # ignore all other options
84
88
  else:
85
89
  # the update options, update all does everything, no need to invoke anything else
90
+ print("Checking for updates into %s" % measurespath)
86
91
  if flags.updateall:
87
- casaconfig.update_all(measurespath)
92
+ casaconfig.update_all(measurespath,force=flags.force)
88
93
  else:
89
94
  # do any pull_update first
90
95
  if flags.pulldata:
91
96
  casaconfig.pull_data(measurespath)
92
97
  # then data_update, not necessary if pull_data just happened
93
98
  if flags.dataupdate and not flags.pulldata:
94
- casaconfig.data_update(measurespath)
99
+ casaconfig.data_update(measurespath, force=flags.force)
95
100
  # then measures_update
96
101
  if flags.measuresupdate:
97
- casaconfig.measures_update(measurespath)
102
+ casaconfig.measures_update(measurespath, force=flags.force)
98
103
 
99
104
  sys.exit(0)
@@ -124,14 +124,9 @@ for __v in __defaults:
124
124
  if globals()[__v] is not None:
125
125
  globals()[__v] = __os.path.abspath(__os.path.expanduser(globals()[__v]))
126
126
  else:
127
- # debugging for now
128
- print("None value seen while expanding path-like fields for config parameter %s" % __v)
129
- print("__loaded_config_files : ")
130
- for __f in __loaded_config_files:
131
- print(" %s" % __f)
132
- print("__config_files : ")
133
- for __f in __config_files:
134
- print(" %s" % __f)
127
+ pass
128
+ # debugging
129
+ # print("None value seen while expanding path-like fields for config parameter %s" % __v)
135
130
 
136
131
  def load_success( ):
137
132
  return __loaded_config_files
@@ -20,6 +20,8 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
20
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
+ If no update is necessary then this function will silently return.
24
+
23
25
  The path must contain a previously installed version of casarundata.
24
26
  Use pull_data to install casarundata into a new path (empty or does not exist).
25
27
 
@@ -108,6 +110,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
108
110
  from .data_available import data_available
109
111
  from .print_log_messages import print_log_messages
110
112
  from .get_data_lock import get_data_lock
113
+ from .pull_data import pull_data
111
114
  from .do_pull_data import do_pull_data
112
115
  from .get_data_info import get_data_info
113
116
 
@@ -120,6 +123,11 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
120
123
  print_log_messages('path is None and has not been set in config.measurespath (probably casasiteconfig.py). Provide a valid path and retry.', logger, True)
121
124
  return
122
125
 
126
+ # when a specific version is requested then the measures readme.txt that is part of that version
127
+ # will get a timestamp of now so that default measures updates won't happen for a day unless the
128
+ # force argument is used for measures_update
129
+ namedVersion = version is not None
130
+
123
131
  path = os.path.expanduser(path)
124
132
  readme_path = os.path.join(path, 'readme.txt')
125
133
 
@@ -131,12 +139,19 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
131
139
  print_log_messages('force must be False when auto_update_rules is True', logger, True)
132
140
  return
133
141
  if (not os.path.isdir(path)) or (os.stat(path).st_uid != os.getuid()):
134
- print_log_messages('path must exist as a directory and it must be owned by the user when auto_update_rules is True', logger, True)
142
+ msgs = []
143
+ msgs.append("Warning: path must exist as a directory and it must be owned by the user, path = %s" % path)
144
+ msgs.append("Warning: no data updates are possible on this path by this user.")
145
+ print_log_messages(msgs, logger, False)
135
146
  return
136
147
 
137
148
  if not os.path.exists(readme_path):
138
- print_log_messages('No readme.txt file found at path. Nothing updated or checked.', logger, True);
139
- return
149
+ # path must exist and it must be empty in order to continue
150
+ if not os.path.exists(path) or (len(os.listdir(path)) > 0):
151
+ print_log_messages('No readme.txt file found at path. Nothing updated or checked.', logger, True);
152
+ return
153
+ # ok to install a fresh copy, use pull_data directly
154
+ return pull_data(path,version,force,logger)
140
155
 
141
156
  # path must be writable with execute bit set
142
157
  if (not os.access(path, os.W_OK | os.X_OK)) :
@@ -153,8 +168,10 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
153
168
  dataReadmeInfo = get_data_info(path, logger, type='casarundata')
154
169
 
155
170
  if dataReadmeInfo is None or dataReadmeInfo['version'] == 'invalid':
156
- print_log_messages('The readme.txt file at path could not be read as expected', logger, True)
157
- print_log_messages('choose a different path or empty this path and try again using pull_data', logger, True)
171
+ msgs = []
172
+ msgs.append('The readme.txt file at path could not be read as expected')
173
+ msgs.append('choose a different path or empty this path and try again using pull_data')
174
+ print_log_messages(msgs, logger, True)
158
175
  # no lock has been set yet, safe to simply return here
159
176
  return
160
177
 
@@ -165,20 +182,25 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
165
182
  ageRecent = dataReadmeInfo['age'] < 1.0
166
183
 
167
184
  if currentVersion is 'unknown':
168
- print_log_messages('The data update path appears to be casarundata but no readme.txt file was found', logger, False)
169
- print_log_messages('A data update is not possible but CASA use of this data may be OK.', logger, False)
170
- print_log_messages('casaconfig must first install the casarundata in path for data_update to run as expected on that path', logger, False)
185
+ msgs = []
186
+ msgs.append('The data update path appears to be casarundata but no readme.txt file was found')
187
+ msgs.append('A data update is not possible but CASA use of this data may be OK.')
188
+ msgs.append('casaconfig must first install the casarundata in path for data_update to run as expected on that path')
189
+ print_log_messages(msgs, logger, True)
171
190
 
172
191
  if (len(installed_files) == 0):
173
192
  # this shouldn't happen
174
- print_log_messages('The readme.txt file at path did not contain the expected list of installed files', logger, True)
175
- print_log_messages('choose a different path or empty this path and try again using pull_data', logger, True)
193
+ msgs = []
194
+ msgs.append('The readme.txt file at path did not contain the expected list of installed files')
195
+ msgs.append('choose a different path or empty this path and try again using pull_data')
196
+ print_log_messages(msgs, logger, True)
176
197
  # no lock has been set yet, safe to simply return here
177
198
  return
178
199
 
179
200
  if version is None and force is False and ageRecent:
180
201
  # if version is None, the readme is less than 1 day old and force is False then return without checking for any newer versions
181
- print_log_messages('data_update latest version checked recently in %s, using version %s' % (path, currentVersion), logger)
202
+ # normal use is silent, this line is useful during debugging
203
+ # print_log_messages('data_update latest version checked recently in %s, using version %s' % (path, currentVersion), logger)
182
204
  # no lock has been set yet, safe to simply return here
183
205
  return
184
206
 
@@ -195,7 +217,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
195
217
  # use the release version from get_data_info
196
218
  releaseInfo = get_data_info()['release']
197
219
  if releaseInfo is None:
198
- print_log_messages('No release info found, pull_data can not continue', logger, True)
220
+ print_log_messages('No release info found, data_update can not continue', logger, True)
199
221
  return
200
222
  requestedVersion = releaseInfo['casarundata']
201
223
  expectedMeasuresVersion = releaseInfo['measures']
@@ -218,17 +240,20 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
218
240
  force = False
219
241
  # if measuresReadmeInfo is None then that's a problem and force remains True, this also catches 'invalid' and 'unknown' measures versions, which should not happen here
220
242
  if not force:
221
- print_log_messages('data_update requested "release" version of casarundata and measures are already installed.', logger)
243
+ # normal use is silent, this line is useful during debugging
244
+ # print_log_messages('data_update requested "release" version of casarundata and measures are already installed.', logger)
222
245
  # no lock has been set yet, safe to simply return here
223
246
  return
224
247
  else:
225
248
  # normal usage, ok to return now
249
+ # normal use is silent, commented out lines are useful during debugging
226
250
  if latestVersion:
227
- print_log_messages('The latest version is already installed in %s, using version %s' % (path, currentVersion), logger)
251
+ # print_log_messages('The latest version is already installed in %s, using version %s' % (path, currentVersion), logger)
228
252
  # touch the dates of the readme to prevent a future check on available data for the next 24 hours
229
253
  os.utime(readme_path)
230
- else:
231
- print_log_messages('Requested casarundata is installed in %s, using version %s' % (path, currentVersion), logger)
254
+ #else:
255
+ # print_log_messages('Requested casarundata is installed in %s, using version %s' % (path, currentVersion), logger)
256
+
232
257
  # no lock has been set yet, safe to simply return here
233
258
  return
234
259
 
@@ -241,10 +266,12 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
241
266
  lock_fd = get_data_lock(path, 'data_update')
242
267
  # if lock_fd is None it means the lock file was not empty - because we know that path exists at this point
243
268
  if lock_fd is None:
244
- print_log_messages('The lock file at %s is not empty.' % path, logger, True)
245
- print_log_messages('A previous attempt to update path may have failed or exited prematurely.', logger, True)
246
- print_log_messages('Remove the lock file and set force to True with the desired version (default to most recent).', logger, True)
247
- print_log_messages('It may be best to completely repopulate path using pull_data and measures_update.', logger, True)
269
+ msgs = []
270
+ msgs.append('The lock file at %s is not empty.' % path)
271
+ msgs.append('A previous attempt to update path may have failed or exited prematurely.')
272
+ msgs.append('Remove the lock file and set force to True with the desired version (default to most recent).')
273
+ msgs.append('It may be best to completely repopulate path using pull_data and measures_update.')
274
+ print_log_messages(msgs, logger, True)
248
275
  return
249
276
 
250
277
  do_update = True
@@ -281,25 +308,36 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
281
308
  if len(installed_files) == 0:
282
309
  # this shouldn't happen, do not do an update
283
310
  do_update = False
284
- print_log_messages('The readme.txt file read at path did not contain the expected list of installed files', logger, True)
285
- 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)
286
- 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)
311
+ msgs = []
312
+ msgs.append('The readme.txt file read at path did not contain the expected list of installed files')
313
+ 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')
314
+ msgs.append('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')
315
+ print_log_messages(msgs, logger, True)
287
316
  else:
288
317
  # this shouldn't happen, do not do an update
289
318
  do_update = False
290
- print_log_messages('Unexpected problem reading readme.txt file during data_update, can not safely update to the requested version', logger, True)
291
- 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)
292
- 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)
319
+ msgs = []
320
+ msgs.append('Unexpected problem reading readme.txt file during data_update, can not safely update to the requested version')
321
+ msgs.append('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')
322
+ msgs.append('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')
323
+ print_log_messages(msgs, logger, True)
293
324
 
294
325
  if do_update:
295
326
  do_pull_data(path, requestedVersion, installed_files, currentVersion, currentDate, logger)
327
+ if namedVersion is not None:
328
+ # a specific version has been requested, set the times on the measures readme.txt to now to avoid
329
+ # a default update of the measures data without using the force argument
330
+ measuresReadmePath = os.path.join(path,'geodetic/readme.txt')
331
+ os.utime(measuresReadmePath)
296
332
 
297
333
  # truncate the lock file
298
334
  lock_fd.truncate(0)
299
335
 
300
336
  except Exception as exc:
301
- print_log_messages('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (requestedVersion, path), logger, True)
302
- print_log_messages('ERROR! : %s' % exc, logger, True)
337
+ msgs = []
338
+ msgs.append('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (requestedVersion, path))
339
+ msgs.append('ERROR! : %s' % exc)
340
+ print_log_messages(msgs, logger, True)
303
341
  # leave the contents of the lock file as is to aid in debugging
304
342
  # import traceback
305
343
  # traceback.print_exc()
@@ -45,20 +45,23 @@ def do_auto_updates(configDict, logger=None):
45
45
  from .print_log_messages import print_log_messages
46
46
  from .data_update import data_update
47
47
  from .measures_update import measures_update
48
-
48
+
49
49
  if configDict.measurespath is None:
50
50
  # likely still unset in casasiteconfig.py, suggest setting it in ~/.casa/config.py
51
51
  # or ask the site administrator (which may be the user) to edit casasiteconfig.py
52
52
  # point at the documentation
53
53
  # continue, because things still might work if there are measures in datapath
54
- print_log_messages('measurespath is None in config', logger, True)
55
- print_log_messages('this likely means a casasiteconfig.py was used and measurespath remains unset there.', logger, True)
56
- print_log_messages('Either set measurespath in your config file at ~/.casa/config.py', logger, True)
57
- print_log_messages('or ask the site manager to set that in casasiteconfig.py', logger, True)
58
- print_log_messages('visit https://casadocs.readthedocs.io/en/stable/notebooks/external-data.html for more information', logger, True)
54
+ msgs = []
55
+ msgs.append('measurespath is None in config')
56
+ msgs.append('this likely means a casasiteconfig.py was used and measurespath remains unset there.')
57
+ msgs.append('Either set measurespath in your config file at ~/.casa/config.py')
58
+ msgs.append('or ask the site manager to set that in casasiteconfig.py')
59
+ msgs.append('visit https://casadocs.readthedocs.io/en/stable/notebooks/external-data.html for more information')
59
60
 
60
61
  if (configDict.measures_auto_update or configDict.data_auto_update):
61
- print('\nAuto updates of measures path are not possible because measurespath is not set, skipping auto updates', logger, True)
62
+ msgs.append('Auto updates of measures path are not possible because measurespath is not set, skipping auto updates')
63
+
64
+ print_log_messages(msgs, logger, True)
62
65
 
63
66
  return
64
67
 
@@ -15,12 +15,14 @@
15
15
  this module will be included in the api
16
16
  """
17
17
 
18
- def measures_update(path=None, version=None, force=False, logger=None, auto_update_rules=False):
18
+ def measures_update(path=None, version=None, force=False, logger=None, auto_update_rules=False, use_astron_obs_table=False):
19
19
  """
20
- Retrieve IERS data used for measures calculations from the ASTRON server
20
+ Update or install the IERS data used for measures calculations from the ASTRON server at 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
+ If no update is necessary then this function will silently return.
25
+
24
26
  CASA maintains a separate Observatories table which is available in the casarundata
25
27
  collection through pull_data and data_update. The Observatories table found at ASTRON
26
28
  is not installed by measures_update and any Observatories file at path will not be changed
@@ -35,9 +37,12 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
35
37
  nothing unless force is True.
36
38
 
37
39
  If a specific version is not requested (the default) and the modification time of that text
38
- file is less than 24 hrs before now then this function does nothing unless force is True. This
39
- limits the number of attempts to update the measures data (including checking for more recent
40
- data) to once per day.
40
+ file is less than 24 hrs before now then this function does nothing unless force is True. When this
41
+ function checks for a more recent version and finds that the installed version is the most recent
42
+ then modification time of that text file is checked to the current time even though nothing has
43
+ changed in path. This limits the number of attempts to update the measures data (including checking f\
44
+ or more recent data) to once per day. When the force argument is True and a specific version is
45
+ not requested then this function always checks for the latest version.
41
46
 
42
47
  When auto_update_rules is True then path must exist and contain the expected readme.txt file.
43
48
  Path must be owned by the user, force must be False, and the version must be None. This
@@ -121,6 +126,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
121
126
  from .print_log_messages import print_log_messages
122
127
  from .get_data_lock import get_data_lock
123
128
  from .get_data_info import get_data_info
129
+ from .measures_available import measures_available
124
130
 
125
131
  if path is None:
126
132
  from .. import config as _config
@@ -141,7 +147,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
141
147
  print_log_messages('force must be False when auto_update_rules is True', logger, True)
142
148
  return
143
149
  if (not os.path.isdir(path)) or (os.stat(path).st_uid != os.getuid()):
144
- print_log_messages('path must exist as a directory and it must be owned by the user when auto_update_rules is True', logger, True)
150
+ msgs = []
151
+ msgs.append("Warning: path must exist as a directory and it must be owned by the user, path = %s" % path)
152
+ msgs.append("Warning: no measures auto update is possible on this path by this user.")
153
+ print_log_messages(msgs, logger, False)
145
154
  return
146
155
 
147
156
  if not os.path.exists(path):
@@ -161,19 +170,15 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
161
170
  ageRecent = readmeInfo['age'] < 1.0
162
171
 
163
172
  if not force:
164
- # don't re-download the same data
165
- if (version is not None) and (version == current):
166
- print_log_messages('measures_update requested version already installed in %s' % path, logger)
167
- return
168
-
169
173
  # don't check for new version if the age is less than 1 day
170
174
  if version is None and ageRecent:
171
- print_log_messages('measures_update latest version checked recently in %s, using version %s' % (path, current), logger)
175
+ # normal use is silent, this line is useful during debugging
176
+ # print_log_messages('measures_update latest version checked recently in %s, using version %s' % (path, current), logger)
172
177
  return
173
178
 
174
179
  # don't overwrite something that looks bad unless forced to do so
175
180
  if current == 'invalid':
176
- print_log_messages('the measures readme.txt file could not be read as expected, an update can not proceed unless force is True', logger, True)
181
+ print_log_messages('The measures readme.txt file could not be read as expected, an update can not proceed unless force is True', logger, True)
177
182
  return
178
183
 
179
184
  # don't overwrite something that looks like valid measures data unless forced to do so
@@ -181,6 +186,38 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
181
186
  print_log_messages('The measures data at %s is not maintained by casaconfig and so it can not be updated unless force is True' % path, logger, True)
182
187
  return
183
188
 
189
+ checkVersion = version
190
+ if checkVersion is None:
191
+ # get the current most recent version
192
+ try:
193
+ checkVersion = measures_available()[-1]
194
+ except:
195
+ # unsure what happened, leave it at none, which will trigger an update attempt, which might work
196
+ pass
197
+
198
+ # don't re-download the same data
199
+ if (checkVersion is not None) and (checkVersion == current):
200
+ # normal use is silent, this line is useful during debugging
201
+ # print_log_messages('measures_update requested version already installed in %s' % path, logger)
202
+ # update the age of the readme to now
203
+ try:
204
+ readme_path = os.path.join(path,'geodetic/readme.txt')
205
+ # readme_path should already exist if it's here
206
+ os.utime(readme_path)
207
+ except:
208
+ # unsure what happened, everything otherwise is fine if we got here, ignore this error
209
+ pass
210
+
211
+ return
212
+
213
+ # don't do anything unless the Observatories table is already installed as expected
214
+ obsTabPath = os.path.join(path,'geodetic/Observatories')
215
+ if not os.path.isdir(obsTabPath):
216
+ print("Error: the Observatories table was not found as expected in %s" % path, logger, True)
217
+ print("Either install casarundata first or set use_astron_obs_table and force to be True when using measures_update.", logger, True)
218
+ print("Note that the Observatories table provided in the Astron measures tarfile is not the same as that maintained by CASA", logger, True)
219
+ return
220
+
184
221
  # path must be writable with execute bit set
185
222
  if (not os.access(path, os.W_OK | os.X_OK)) :
186
223
  print_log_messages('No permission to write to the measures path, cannot update : %s' % path, logger, True)
@@ -191,15 +228,18 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
191
228
  # lock the measures_update.lock file
192
229
  lock_fd = None
193
230
  try:
194
- print_log_messages('measures_update measures need to be updated, acquiring the lock ... ', logger)
231
+ print_log_messages('measures_update ... acquiring the lock ... ', logger)
195
232
 
196
233
  lock_fd = get_data_lock(path, 'measures_update')
197
234
  # if lock_fd is None it means the lock file was not empty - because we know that path exists at this point
198
235
  if lock_fd is None:
199
- print_log_messages('The lock file at %s is not empty.' % path, logger, True)
200
- print_log_messages('A previous attempt to update path may have failed or exited prematurely.', logger, True)
201
- print_log_messages('Remove the lock file and set force to True with the desired version (default to most recent).', logger, True)
202
- print_log_messages('It may be best to completely repopulate path using pull_data and measures_update.', logger, True)
236
+ # using a list of messages results in a better printing if the logger is redirected to the terminal
237
+ msgs = []
238
+ msgs.append('The lock file at %s is not empty.' % path)
239
+ msgs.append('A previous attempt to update path may have failed or exited prematurely.')
240
+ msgs.append('Remove the lock file and set force to True with the desired version (default to most recent).')
241
+ msgs.append('It may be best to completely repopulate path using pull_data and measures_update.')
242
+ print_log_messages(msgs, logger, True)
203
243
  return
204
244
 
205
245
  do_update = force
@@ -216,18 +256,21 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
216
256
  ageRecent = readmeInfo['age'] < 1.0
217
257
 
218
258
  if (version is not None) and (version == current):
219
- # no update will be done, version is as requested
220
- print_log_messages('measures_update requested measures version detected in %s, using version %s' % (path, current), logger)
259
+ # no update will be done, version is as requested - not silent here because the lock is in use
260
+ print_log_messages('The requested measures version is already installed in %s, using version %s' % (path, current), logger)
221
261
  elif (version is None) and ageRecent:
222
- # no update will be done, it's already been checked or updated recently
223
- print_log_messages('measures_update latest measures version checked recently in %s, using version %s' % (path, current), logger)
262
+ # no update will be done, it's already been checked or updated recently - not silent here because the lock is in use
263
+ print_log_messages('The latest measures version was checked recently in %s, using version %s' % (path, current), logger)
224
264
  else:
225
265
  # final check for problems before updating
226
266
  if not force and readmeInfo is not None and (version=='invalid' or version=='unknown'):
227
267
  # at this point, this indicates something is unexpectedly wrong, do not continue
228
- print_log_messages('Something unexpected has changed in the measures path location, and measures_update can not continue', logger, True)
229
- print_log_messages('a previous measures_update may have exited unexpectedly', logger, True)
230
- print_log_messages('It may be necessary to reinstall the casarundata as well as the measures data if %s is the correct path' % path, logger, True)
268
+ # using a list of messages results in a better printing if the logger is redirected to the terminal
269
+ msgs = []
270
+ msgs.append('Something unexpected has changed in the measures path location, and measures_update can not continue')
271
+ msgs.append('A previous measures_update may have exited unexpectedly')
272
+ msgs.append('It may be necessary to reinstall the casarundata as well as the measures data if %s is the correct path' % path)
273
+ print_log_messages(msgs, logger, True)
231
274
  # update is already turned off, the lock file will be cleaned up on exit
232
275
  else:
233
276
  # an update is needed
@@ -235,9 +278,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
235
278
 
236
279
  if do_update:
237
280
  if force:
238
- print_log_messages('meaures_update a measures update has been requested by the force argument', logger)
281
+ print_log_messages('A measures update has been requested by the force argument', logger)
239
282
 
240
- print_log_messages('measures_update connecting to ftp.astron.nl ...', logger)
283
+ print_log_messages(' ... connecting to ftp.astron.nl ...', logger)
241
284
 
242
285
  ftp = FTP('ftp.astron.nl')
243
286
  rc = ftp.login()
@@ -252,38 +295,48 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
252
295
  print_log_messages('measures_update cant find specified version %s' % target, logger, True)
253
296
 
254
297
  else:
255
- # there are files to extract, remove the readme.txt file in case this dies unexpectedly
256
- readme_path = os.path.join(path,'geodetic/readme.txt')
257
- if os.path.exists(readme_path):
258
- os.remove(readme_path)
298
+ # there are files to extract, make sure there's no past measures.ztar from a failed previous install
299
+ ztarPath = os.path.join(path,'measures.ztar')
300
+ if os.path.exists(ztarPath):
301
+ os.remove(ztarPath)
259
302
 
260
- with open(os.path.join(path,'measures.ztar'), 'wb') as fid:
261
- print_log_messages('measures_update downloading %s from ASTRON server to %s ...' % (target, path), logger)
303
+ with open(ztarPath, 'wb') as fid:
304
+ print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger)
262
305
  ftp.retrbinary('RETR ' + target, fid.write)
263
306
 
264
307
  ftp.close()
265
-
308
+
309
+ # remove any existing measures readme.txt now in case something goes wrong during extraction
310
+ readme_path = os.path.join(path,'geodetic/readme.txt')
311
+ if os.path.exists(readme_path):
312
+ os.remove(readme_path)
313
+
266
314
  # extract from the fetched tarfile
267
- with tarfile.open(os.path.join(path,'measures.ztar'),mode='r:gz') as ztar:
315
+ with tarfile.open(ztarPath, mode='r:gz') as ztar:
268
316
  # the list of members to extract
269
317
  x_list = []
270
318
  for m in ztar.getmembers() :
271
- # always exclude the Observatories table and *.old names in geodetic
272
- if not((re.search('geodetic',m.name) and re.search('.old',m.name)) or re.search('Observatories',m.name)):
273
- x_list.append(m)
319
+ if force and use_astron_obs_table:
320
+ # exclude the *.old names in geodetic
321
+ if not(re.search('geodetic',m.name) and re.search('.old',m.name)):
322
+ x_list.append(m)
323
+ else:
324
+ # exclude the Observatories table and *.old names in geodetic
325
+ if not((re.search('geodetic',m.name) and re.search('.old',m.name)) or re.search('Observatories',m.name)):
326
+ x_list.append(m)
274
327
 
275
328
  # use the 'data' filter if available, revert to previous 'fully_trusted' behavior of not available
276
329
  ztar.extraction_filter = getattr(tarfile, 'data_filter', (lambda member, path: member))
277
330
  ztar.extractall(path=path,members=x_list)
278
331
  ztar.close()
279
332
 
280
- os.system("rm %s" % os.path.join(path, 'measures.ztar'))
333
+ os.remove(ztarPath)
281
334
 
282
- # update the readme.txt file
335
+ # create a new readme.txt file
283
336
  with open(readme_path,'w') as fid:
284
337
  fid.write("# measures data populated by casaconfig\nversion : %s\ndate : %s" % (target, datetime.today().strftime('%Y-%m-%d')))
285
338
 
286
- print_log_messages('measures_update updated measures data at %s' % path, logger)
339
+ print_log_messages(' ... measures data update at %s' % path, logger)
287
340
 
288
341
  # closing out the do_update
289
342
 
@@ -292,8 +345,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
292
345
  lock_fd.truncate(0)
293
346
 
294
347
  except Exception as exc:
295
- print_log_messages("ERROR! : Unexpected exception while updating measures at %s" % path, logger, True)
296
- print_log_messages("ERROR! : %s" % exc, logger, True)
348
+ msgs = []
349
+ msgs.append("ERROR! : Unexpected exception while updating measures at %s" % path)
350
+ msgs.append("ERROR! : %s" % exc)
351
+ print_log_messages(msgs, logger, True)
297
352
  # leave the contents of the lock file as is to aid in debugging
298
353
 
299
354
  # if the lock file is not closed, do that now to release the lock
@@ -16,6 +16,8 @@ def print_log_messages(msg, logger, is_err=False):
16
16
  """
17
17
  Print msg and optionally write it to an instance of the casalogger.
18
18
 
19
+ If msg is a list then the elements are each printed first followed by logging each element.
20
+
19
21
  Messages are normally printed to sys.stdout and logged as INFO to the casalogger.
20
22
 
21
23
  When is_err is True the message is printed sys.stderr and logged as SEVERE
@@ -39,5 +41,12 @@ def print_log_messages(msg, logger, is_err=False):
39
41
  fileout = sys.stderr
40
42
  loglevel = 'SEVERE'
41
43
 
42
- print(msg,file=fileout)
43
- if logger is not None: logger.post(msg, loglevel)
44
+ # this is rarely called and this should be a fast operation, it makes the code simpler
45
+ if type(msg) is not list:
46
+ msg = [msg]
47
+
48
+ for m_msg in msg:
49
+ print(m_msg,file=fileout)
50
+
51
+ for m_msg in msg:
52
+ if logger is not None: logger.post(m_msg, loglevel)
@@ -107,6 +107,11 @@ def pull_data(path=None, version=None, force=False, logger=None):
107
107
  print_log_messages('path is None and has not been set in config.measurespath (probably casasiteconfig.py). Provide a valid path and retry.', logger, True)
108
108
  return
109
109
 
110
+ # when a specific version is requested then the measures readme.txt that is part of that version
111
+ # will get a timestamp of now so that default measures updates won't happen for a day unless the
112
+ # force argument is used for measures_update
113
+ namedVersion = version is not None
114
+
110
115
  path = os.path.expanduser(path)
111
116
  readme_path = os.path.join(path, 'readme.txt')
112
117
 
@@ -125,26 +130,30 @@ def pull_data(path=None, version=None, force=False, logger=None):
125
130
  installed_files = readmeInfo['manifest']
126
131
 
127
132
  if currentVersion == 'invalid':
128
- print_log_messages('destination path is not empty and this does not appear to be casarundata OR the readme.txt file found there could not be read as expected', logger, True)
129
- print_log_messages('choose a different path or empty this path and try again', logger, True)
133
+ msgs = []
134
+ msgs.append('destination path is not empty and this does not appear to be casarundata OR the readme.txt file found there could not be read as expected')
135
+ msgs.append('choose a different path or empty this path and try again')
136
+ print_log_messages(msgs, logger, True)
130
137
  # no lock has been set yet, safe to simply return here
131
138
  return
132
139
 
133
140
  if currentVersion == 'unknown':
134
- print_log_messages('destination path appears to be casarundata but no readme.txt file was found', logger, False)
135
- print_log_messages('no data will be installed but CASA use of this data may be OK. Choose a different path or delete this path to install new casarundata.', logger, False)
141
+ msgs = []
142
+ msgs.append('destination path appears to be casarundata but no readme.txt file was found')
143
+ msgs.append('no data will be installed but CASA use of this data may be OK. Choose a different path or delete this path to install new casarundata.')
136
144
  if force:
137
- print_log_messages('force is True but there is no readme.txt found and the location is not empty, no data will be installed', logger, True)
138
- print_log_messages('Choose a different path or empty this path to install new casarundata', logger, True)
145
+ msgs.append('force is True but there is no readme.txt found and the location is not empty, no data will be installed')
146
+ msgs.append('Choose a different path or empty this path to install new casarundata')
147
+ print_log_messages(msgs, logger, True)
139
148
  # no lock as been set yet, safe to simply return here
140
149
  return
141
150
 
142
151
  if (installed_files is None or len(installed_files) == 0):
143
152
  # this shouldn't happen
144
- print('')
145
- 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)
146
- print_log_messages('choose a different path or empty this path and try again', logger, True)
147
- print('')
153
+ msgs = []
154
+ msgs.append('destination path is not empty and the readme.txt file found there did not contain the expected list of installed files')
155
+ msgs.append('choose a different path or empty this path and try again')
156
+ print_log_messages(msgs, logger, True)
148
157
  # no lock as been set yet, safe to simply return here
149
158
  return
150
159
 
@@ -196,12 +205,12 @@ def pull_data(path=None, version=None, force=False, logger=None):
196
205
  lock_fd = get_data_lock(path, 'pull_data')
197
206
  # if lock_fd is None it means the lock file was not empty - because we know that path exists at this point
198
207
  if lock_fd is None:
199
- print('')
200
- print_log_messages('The lock file at %s is not empty.' % path, logger, True)
201
- print_log_messages('A previous attempt to update path may have failed or exited prematurely.', logger, True)
202
- print_log_messages('Remove the lock file and set force to True with the desired version (default to the most recent).', logger, True)
203
- print_log_messages('It may be best to clean out that location and do a fresh pull_data.', logger, True)
204
- print('')
208
+ msgs = []
209
+ msgs.append('The lock file at %s is not empty.' % path)
210
+ msgs.append('A previous attempt to update path may have failed or exited prematurely.')
211
+ msgs.append('Remove the lock file and set force to True with the desired version (default to the most recent).')
212
+ msgs.append('It may be best to clean out that location and do a fresh pull_data.')
213
+ print_log_messages(msgs, logger, True)
205
214
  return
206
215
 
207
216
  do_pull = True
@@ -238,10 +247,10 @@ def pull_data(path=None, version=None, force=False, logger=None):
238
247
  # incompatible with this attempt
239
248
  if version in ['invalid','error','unknown']:
240
249
  do_pull = False
241
- print('')
242
- print_log_messages('Unexpected version or problem found in readme.txt file during pull_data, can not safely pull the requested version', logger, True)
243
- 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)
244
- print('')
250
+ msgs = []
251
+ msgs.append('Unexpected version or problem found in readme.txt file during pull_data, can not safely pull the requested version')
252
+ msgs.append('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')
253
+ print_log_messages(msgs, logger, True)
245
254
 
246
255
 
247
256
  if do_pull:
@@ -250,23 +259,28 @@ def pull_data(path=None, version=None, force=False, logger=None):
250
259
  if len(installed_files) == 0:
251
260
  # this shoudn't happen, do not do a pull
252
261
  do_pull = False
253
- print('')
254
- 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)
255
- 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)
256
- print_log_messages('Check for other updates in process or choose a different path or clear out this path and try again', logger, True)
257
- print('')
262
+ msgs = []
263
+ msgs.append('destination path is not empty and the readme.txt file found there did not contain the expected list of installed files')
264
+ msgs.append('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')
265
+ msgs.append('Check for other updates in process or choose a different path or clear out this path and try again')
266
+ print_log_messages(msgs, logger, True)
258
267
 
259
268
  if do_pull:
260
269
  do_pull_data(path, version, installed_files, currentVersion, currentDate, logger)
270
+ if namedVersion:
271
+ # a specific version has been requested, set the times on the measures readme.txt to now to avoid
272
+ # a default update of the measures data without using the force argument
273
+ measuresReadmePath = os.path.join(path,'geodetic/readme.txt')
274
+ os.utime(measuresReadmePath)
261
275
 
262
- # truncate the lock file
276
+ # truncate the lock filed
263
277
  lock_fd.truncate(0)
264
278
 
265
279
  except Exception as exc:
266
- print('')
267
- print_log_messages('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (version, path), logger, True)
268
- print_log_messages('ERROR! : %s' % exc, logger, True)
269
- print()
280
+ msgs = []
281
+ msgs.append('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (version, path))
282
+ msgs.append('ERROR! : %s' % exc)
283
+ print_log_messages(msgs, logger, True)
270
284
  # leave the contents of the lock file as is to aid in debugging
271
285
  # import traceback
272
286
  # traceback.print_exc()
@@ -15,7 +15,7 @@
15
15
  this module will be included in the api
16
16
  """
17
17
 
18
- def update_all(path=None, logger=None):
18
+ def update_all(path=None, logger=None, force=False):
19
19
  """
20
20
  Update the data contants at path to the most recently released versions
21
21
  of casarundata and measures data.
@@ -33,6 +33,8 @@ def update_all(path=None, logger=None):
33
33
  If path already contains the most recent versions of casarundata and
34
34
  measurespath then nothing will change at path.
35
35
 
36
+ The force argument is passed to data_update and measures_update
37
+
36
38
  This uses pull_data, data_update and measures_update. See the
37
39
  documentation for those functions for additional details.
38
40
 
@@ -76,7 +78,10 @@ def update_all(path=None, logger=None):
76
78
  # path must be a directory and it must be owned by the user
77
79
 
78
80
  if (not os.path.isdir(path)) or (os.stat(path).st_uid != os.getuid()):
79
- print_log_messages("path must exist as a directory and it must be owned by the user, path = %s" % path, logger, True)
81
+ msgs = []
82
+ msgs.append("Warning: path must exist as a directory and it must be owned by the user, path = %s" % path)
83
+ msgs.append("Warning: no updates are possible on this path by this user.")
84
+ print_log_messages(msgs, logger, False)
80
85
  return
81
86
 
82
87
  # if path is empty, first use pull_data
@@ -106,7 +111,7 @@ def update_all(path=None, logger=None):
106
111
  return
107
112
 
108
113
  # the updates should work now
109
- data_update(path, logger)
110
- measures_update(path, logger)
114
+ data_update(path, logger, force=force)
115
+ measures_update(path, logger, force=force)
111
116
 
112
117
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: casaconfig
3
- Version: 0.0.80
3
+ Version: 0.0.81
4
4
  Summary: CASA Operational Configuration Package
5
5
  Home-page: https://github.com/casangi/casaconfig
6
6
  Author: National Radio Astronomy Observatory
@@ -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.80',
9
+ version='0.0.81',
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