casaconfig 1.0.2__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.
@@ -0,0 +1,315 @@
1
+ # Copyright 2020 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
+ this module will be included in the api
16
+ """
17
+
18
+ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
19
+ """
20
+ Pull the casarundata contents from the CASA host and install it in path.
21
+
22
+ The verbose argument controls the level of information provided when this function when the data
23
+ are unchanged for expected reasons. A level of 0 prints and logs nothing. A
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
27
+ or it must not exist or be empty.
28
+
29
+ If path is None then config.measurespath will be used.
30
+
31
+ If version is None (the default) then the most recent version is pulled.
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
+ checked or installed.
37
+
38
+ If force is True then the requested version is installed even if that
39
+ version is already installed.
40
+
41
+ Results and errors are always printed. They are also logged to the logger
42
+ if available.
43
+
44
+ A text file (readme.txt at path) records the version string, the date
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
47
+ version. If path is not empty then this file must exist with the expected
48
+ contents in order for pull_data to proceed.
49
+
50
+ If the version to be pulled matches the version in the readme.txt file then
51
+ pull_data does nothing unless force is True. No error messages will result when the
52
+ version already matches what was previously installed (no installation is then
53
+ necessary unless force is True).
54
+
55
+ The measures tables included in casarundata will typically not be the most
56
+ recent version. To get the most recent measures data, measures_update
57
+ should be used after pull_data.
58
+
59
+ If path contains a previously installed version then all of the files listed in
60
+ the manifest part of the readme.txt file are first removed from path. This ensures
61
+ that files not present in the version being installed are removed in moving to the
62
+ other version.
63
+
64
+ A file lock is used to prevent more than one data update (pull_data, measures_update,
65
+ or data_update) from updating any files in path at the same time. When locked, the
66
+ lock file (data_update.lock in path) contains information about the process that
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
69
+ match what was requested, or force is True). If the lock file is not
70
+ empty then a previous update of path (pull_data, data_update, or measures_update)
71
+ did not exit as expected and the contents of path are suspect. In that case, pull_data
72
+ will report that as an error and nothing will be updated. The lock file can be checked
73
+ to see the details of when that file was locked. The lock file can be removed and
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
76
+ a fresh copy of the desired version.
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
80
+ any changes are seen by the tools and tasks that use this data.
81
+
82
+ **Note:** When version is None (the default), data_available is always used to find out
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).
85
+
86
+ Parameters
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.
88
+ - version (str=None) - casadata version to retrieve. Default None gets the most recent version.
89
+ - force (bool=False) - If True, re-download and install the data even when the requested version matches what is already installed. Default False will not download data if the installed version matches the requested version.
90
+ - logger (casatools.logsink=None) - Instance of the casalogger to use for writing messages. Messages are always written to the terminal. Default None does not write any messages to a logger.
91
+ - 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.
92
+
93
+ Returns
94
+ None
95
+
96
+ Raises
97
+ - casaconfig.BadLock - raised when the lock file is not empty when a lock is requested
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.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.UnsetMeasurespath - raised when path is None and and measurespath has not been set in config.
102
+
103
+ """
104
+
105
+ import os
106
+
107
+ from casaconfig import data_available
108
+ from casaconfig import get_data_info
109
+ from casaconfig import UnsetMeasurespath, BadLock, BadReadme, NotWritable
110
+
111
+ from .print_log_messages import print_log_messages
112
+ from .get_data_lock import get_data_lock
113
+ from .do_pull_data import do_pull_data
114
+
115
+ if path is None:
116
+ from .. import config as _config
117
+ path = _config.measurespath
118
+
119
+ if path is None:
120
+ raise UnsetMeasurespath('path is None and has not been set in config.measurespath. Provide a valid path and retry.')
121
+
122
+ # when a specific version is requested then the measures readme.txt that is part of that version
123
+ # will get a timestamp of now so that default measures updates won't happen for a day unless the
124
+ # force argument is used for measures_update
125
+ namedVersion = version is not None
126
+
127
+ path = os.path.expanduser(path)
128
+ readme_path = os.path.join(path, 'readme.txt')
129
+
130
+ installed_files = []
131
+ available_data = None
132
+ currentVersion = None
133
+ currentDate = None
134
+
135
+ # attempt a pull if path does not exist or is empty (except for any lock file, handled later)
136
+ readmeInfo = get_data_info(path, logger, type='casarundata')
137
+ do_pull = readmeInfo is None
138
+ if not do_pull:
139
+ # find the current version, install date, and installed files
140
+ currentVersion = readmeInfo['version']
141
+ currentDate = readmeInfo['date']
142
+ installed_files = readmeInfo['manifest']
143
+
144
+ if currentVersion == 'invalid':
145
+ msgs = []
146
+ 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')
147
+ msgs.append('choose a different path or empty this path and try again')
148
+ print_log_messages(msgs, logger, True)
149
+ # no lock has been set yet, safe to simply return here
150
+ return
151
+
152
+ if currentVersion == 'unknown':
153
+ msgs = []
154
+ msgs.append('destination path appears to be casarundata but no readme.txt file was found')
155
+ 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.')
156
+ if force:
157
+ msgs.append('force is True but there is no readme.txt found and the location is not empty, no data will be installed')
158
+ msgs.append('Choose a different path or empty this path to install new casarundata')
159
+ print_log_messages(msgs, logger, True)
160
+ # no lock as been set yet, safe to simply return here
161
+ return
162
+
163
+ if (installed_files is None or len(installed_files) == 0):
164
+ # this shouldn't happen
165
+ # no lock has been set yet, safe to raise this exception without worrying about the lock
166
+ raise BadReadme('pull_data: the readme.txt file at path did not contain the expected list of installed files')
167
+
168
+ # the readme file looks as expected, pull if the version is different or force is true
169
+ if version is None:
170
+ # 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
+ available_data = data_available()
173
+ version = available_data[-1]
174
+
175
+ do_pull = (version!=currentVersion) or force
176
+
177
+ if not do_pull:
178
+ # it's already at the expected version and force is False, nothing to do
179
+ # safe to return here, no lock has been set
180
+ print_log_messages('pull_data: version is already at the expected version and force is False. Nothing was changed', logger, verbose=verbose)
181
+ return
182
+
183
+ # a pull will happen, unless the version string is not available
184
+
185
+ if version is None:
186
+ # need a version, use most recent available
187
+
188
+ 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
+ available_data = data_available()
191
+
192
+ version = available_data[-1]
193
+
194
+ expectedMeasuresVersion = None
195
+ if version == 'release':
196
+ # use the release version from get_data_info
197
+ releaseInfo = get_data_info()['release']
198
+ if releaseInfo is None:
199
+ print_log_messages('No release info found, pull_data can not continue', logger, True)
200
+ return
201
+ version = releaseInfo['casarundata']
202
+ expectedMeasuresVersion = releaseInfo['measures']
203
+ else:
204
+ # requested version must be available
205
+ 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
+ available_data = data_available()
208
+
209
+ if version not in available_data:
210
+ print_log_messages('version %s not found on CASA server, use casaconfig.data_available() for a list of casarundata versions' % version, logger, True)
211
+ return
212
+
213
+ if not os.path.exists(path):
214
+ # make dirs all the way down path if possible
215
+ os.makedirs(path)
216
+
217
+ # path must be writable with execute bit set
218
+ if (not os.access(path, os.W_OK | os.X_OK)) :
219
+ raise NotWritable('pull_data: No permission to write to path, cannot update : %s' % path)
220
+
221
+ # lock the data_update.lock file
222
+ lock_fd = None
223
+ clean_lock = True # set to False if the contents are actively being update and the lock file should not be cleaned on exception
224
+ try:
225
+ print_log_messages('pull_data using version %s, acquiring the lock ... ' % version, logger)
226
+
227
+ lock_fd = get_data_lock(path, 'pull_data')
228
+ # the BadLock exception that may happen here is caught below
229
+
230
+ do_pull = True
231
+ if not force:
232
+ # need to recheck any readme file that may be present here
233
+ # it's possible that another process had path locked and updated the readme file with new information
234
+ readmeInfo = get_data_info(path, logger, type='casarundata')
235
+ if readmeInfo is not None:
236
+ currentVersion = readmeInfo['version']
237
+ currentDate = readmeInfo['date']
238
+ if ((currentVersion == version) and (not force)):
239
+ if expectedMeasuresVersion is not None:
240
+ # this is a release pull and the measures version must also match
241
+ # start off assuming a pull is necessary
242
+ do_pull = True
243
+ measuresReadmeInfo = get_data_info(path, logger, type='measures')
244
+ if measuresReadmeInfo is not None:
245
+ measuresVersion = measuresReadmeInfo['version']
246
+ if measuresVersion == expectedMeasuresVersion:
247
+ # no pull is necessary
248
+ do_pull = False
249
+ print_log_messages('pull_data requested "release" versions of casarundata and measures are already installed.', logger)
250
+ # otherwise this is a release pull and even if the measuresVersion is 'unknown' or 'invalid' we should proceed with a pull at this point
251
+ # problems with casarundata path will have been caught before
252
+ else:
253
+ # nothing to do here, already at the expected casarundata version and a pull is not being forced and this is not a release pull
254
+ do_pull = False
255
+ print_log_messages('pull_data requested version is already installed.', logger)
256
+
257
+ # a version of 'invalid', 'error', or 'unknown' is a surprise here, likely caused by something else doing something
258
+ # incompatible with this attempt
259
+ if version in ['invalid','error','unknown']:
260
+ # raise BadReadme (caught below) and do not clean up the lock file
261
+ clean_lock = False
262
+ raise BadReadme('data_update : something unexpected has changed in the path location, can not continue')
263
+
264
+ if do_pull:
265
+ # make sure the copy of installed_files is the correct one
266
+ installed_files = readmeInfo['manifest']
267
+ if len(installed_files) == 0:
268
+ # this shoudn't happen, raise BadReadme (caught below) and do not clean up the lock file
269
+ clean_lock = False
270
+ raise BadReadme('pull_data : the readme.txt file at path did not contain the expected list of installed files after the lock was obtained, this should never happen.')
271
+
272
+ if do_pull:
273
+ # do not clean the lock file contents at this point unless do_pull_data returns normally
274
+ clean_lock = False
275
+ do_pull_data(path, version, installed_files, currentVersion, currentDate, logger)
276
+ clean_lock = True
277
+ if namedVersion:
278
+ # a specific version has been requested, set the times on the measures readme.txt to now to avoid
279
+ # a default update of the measures data without using the force argument
280
+ measuresReadmePath = os.path.join(path,'geodetic/readme.txt')
281
+ os.utime(measuresReadmePath)
282
+
283
+
284
+ except BadLock as exc:
285
+ # 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)
287
+ msgs.append('The lock file at %s is not empty.' % path)
288
+ msgs.append('A previous attempt to update path may have failed or exited prematurely.')
289
+ msgs.append('It may be best to completely repopulated path using pull_data and measures_update.')
290
+ print_log_messages(msgs, logger, True)
291
+ # reraise this
292
+ raise
293
+ except BadReadme as exc:
294
+ # 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)
296
+ 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
+ msgs.append('Check for other updates in progress or choose a different path or clear out this path and try again')
298
+ print_log_messages(msgs, logger, True)
299
+ raise
300
+
301
+ except Exception as exc:
302
+ msgs = []
303
+ msgs.append('ERROR! : Unexpected exception while populating casarundata version %s to %s' % (version, path))
304
+ msgs.append('ERROR! : %s' % exc)
305
+ print_log_messages(msgs, logger, True)
306
+ raise
307
+
308
+ finally:
309
+ # make sure the lock file is closed and also clean the lock file if safe to do so, this is always executed
310
+ if lock_fd is not None and not lock_fd.closed:
311
+ if clean_lock:
312
+ lock_fd.truncate(0)
313
+ lock_fd.close()
314
+
315
+ return
@@ -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
+ result = None
59
+
60
+ return result
@@ -0,0 +1,62 @@
1
+ # Copyright 2020 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
+ this module will be included in the api
16
+ """
17
+
18
+
19
+ def set_casacore_path(path=None):
20
+ """
21
+ Set the path in .casarc to the desired data directory
22
+
23
+ The "measures.directory" in the .casarc file is not used by any part of CASA. This function is
24
+ provided as a convenience for casacore users (e.g. python-casacore) so that the path to
25
+ the casacore data directory can be found by casacore users. It sets the value of that
26
+ parameter to the casacore data location, replacing any previously set value.
27
+
28
+ Parameters
29
+ - path (string=None) - path to the desired data directory. Default None uses the included data directory from this package
30
+
31
+ Returns
32
+ None
33
+
34
+ """
35
+ import pkg_resources
36
+ import os
37
+ import re
38
+ import sys
39
+
40
+ if path is None: path = pkg_resources.resource_filename('casaconfig', 'data/')
41
+ path = os.path.abspath(os.path.expanduser(path))
42
+
43
+ rctext = 'measures.directory: %s\n' % path
44
+
45
+ casarc = os.path.expanduser('~/.casarc')
46
+
47
+ # get the current .casarc contents if it exists
48
+ # set/replace the path to the geodetic folder
49
+ if os.path.exists(casarc):
50
+ with open(casarc, 'r') as fid:
51
+ print('found existing .casarc...', file = sys.stderr )
52
+ oldtxt = fid.read()
53
+ if 'measures.directory' in oldtxt:
54
+ rctext = re.sub('measures.directory: .+?\n', '%s'%rctext, oldtxt, flags=re.DOTALL)
55
+ else:
56
+ rctext = oldtxt.strip() + '\n' + rctext
57
+ # write out new .casarc file
58
+ with open(casarc, 'w') as fid:
59
+ print('writing %s...' % casarc)
60
+ fid.write(rctext)
61
+
62
+ return
@@ -0,0 +1,90 @@
1
+ # Copyright 2024 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 summary(configDict = None):
16
+ """
17
+ Summarize the configure status.
18
+
19
+ This prints out the config files that were loaded successfully, the files are shown by
20
+ type (default, site, user), the command flags are shown that control whether the site
21
+ and user config files are used, any errors encountered while loading are printed, the
22
+ value of the measurespath config value is shown, the installed data versions are shown
23
+ (casarundata and measures) and any release version information is shown.
24
+
25
+ Parameters
26
+ - configDict (dict) - a config dictionary. If None this is imported from casaconfig.
27
+
28
+ Returns
29
+ None
30
+
31
+ """
32
+
33
+ import casaconfig
34
+
35
+ if configDict is None:
36
+ from casaconfig import config as configDict
37
+
38
+ try:
39
+ dataInfo = casaconfig.get_data_info()
40
+ except casaconfig.UnsetMeasurespath:
41
+ print("Measurespath is unset or does not exist in config dictionary. Use a valid path and try again")
42
+ return
43
+
44
+ print("")
45
+ print("casaconfig summary")
46
+ print("")
47
+ print("loaded config files : ")
48
+ for f in configDict.load_success():
49
+ print(" %s" % f)
50
+ if len(configDict.load_failure()) > 0:
51
+ print("")
52
+ print("config failures :")
53
+ for f in configDict.load_failure():
54
+ print("\n%s :" % f)
55
+ print(configDict.load_failure()[f])
56
+ print("")
57
+ if (configDict.__flags.noconfig):
58
+ print("--noconfig option was used")
59
+ if (configDict.__flags.nositeconfig):
60
+ print("--nositeconfig option was used")
61
+ print("")
62
+ print("measurespath : %s" % configDict.measurespath)
63
+ print("")
64
+ if (dataInfo['casarundata'] is None):
65
+ print("casarundata version : no casarundata found")
66
+ else:
67
+ rundataVers = dataInfo['casarundata']['version']
68
+ msg = "casarundata version : %s" % rundataVers
69
+ if rundataVers == "unknown":
70
+ msg += "; legacy data not maintained by casaconfig"
71
+ elif rundataVers == "error":
72
+ msg += "; unexpected readme.txt file, casarundata should be reinstalled"
73
+ print(msg)
74
+ if (dataInfo['measures'] is None):
75
+ print("measures version : no measures found")
76
+ else:
77
+ measVers = dataInfo['measures']['version']
78
+ msg = "measures version : %s" % measVers
79
+ if measVers == "unknown":
80
+ msg += "; legacy data not maintained by casaconfig"
81
+ elif measVers == "error":
82
+ msg += "; unexpected readme.txt file, measures should be reinstalled"
83
+ print(msg)
84
+
85
+ if (dataInfo['release'] is None):
86
+ print("no release version information found")
87
+ else:
88
+ print('release casarundata version : %s' % dataInfo['release']['casarundata'])
89
+ print('release measures version : %s' % dataInfo['release']['measures'])
90
+ print("")
@@ -0,0 +1,123 @@
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
+ this module will be included in the api
16
+ """
17
+
18
+ def update_all(path=None, logger=None, force=False, verbose=None):
19
+ """
20
+ Update the data contants at path to the most recently released versions
21
+ of casarundata and measures data.
22
+
23
+ If path does not exist it will be created (the user must have permission
24
+ to create path).
25
+
26
+ If path does exist and is not empty it must contain a previously
27
+ installed version of casarundata. Path must be a directory and it
28
+ must be owned by the user.
29
+
30
+ If path is not provided then config is imported and the measurespath value set
31
+ by that process will be used.
32
+
33
+ If path already contains the most recent versions of casarundata and
34
+ measurespath then nothing will change at path.
35
+
36
+ The force argument is passed to data_update and measures_update
37
+
38
+ The verbose argument controls the level of information provided when
39
+ this function when the data are unchanged for expected reasons. A level
40
+ of 0 prints and logs nothing. A value of 1 logs the information and a value
41
+ of 2 logs and prints the information.
42
+
43
+ This uses pull_data, data_update and measures_update. See the
44
+ documentation for those functions for additional details (e.g. verbose argument).
45
+
46
+ Some of the data updated by this function is only read when casatools starts.
47
+ Use of update_all after CASA has started should typically be followed by a restart
48
+ so that any changes are seen by the tools and tasks that use this data.
49
+
50
+ Parameters
51
+ - path (str=None) - Folder path to place casarundata contents. It must not exist, or be empty, or contain a valid, previously installed version. If it exists, it must be owned by the user. Default None uses the value of measurespath set by importing config.py.
52
+ - logger (casatools.logsink=None) - Instance of the casalogger to use for writing messages. Messages are always written to the terminal. Default None does not write any messages to a logger.
53
+ - 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.
54
+
55
+ Returns
56
+ None
57
+
58
+ """
59
+
60
+ import os
61
+
62
+ from .print_log_messages import print_log_messages
63
+ from .get_data_info import get_data_info
64
+ from .pull_data import pull_data
65
+ from .data_update import data_update
66
+ from .measures_update import measures_update
67
+
68
+ if path is None:
69
+ from casaconfig import config
70
+ path = config.measurespath
71
+
72
+ if path is None:
73
+ print_log_messages("config.measurespath is None. Edit your config.py to set measurespath to an appropriate location,", logger, True)
74
+ return
75
+
76
+ if not os.path.exists(path):
77
+ # create it, all the way down
78
+ try:
79
+ os.makedirs(path, exist_ok=True)
80
+ except:
81
+ print_log_messages("unable to create path, check the permissions of the directory it is being created at, path = %s" % path, logger, True)
82
+ return
83
+
84
+ # path must be a directory and it must be owned by the user
85
+
86
+ if (not os.path.isdir(path)) or (os.stat(path).st_uid != os.getuid()):
87
+ msgs = []
88
+ msgs.append("Warning: path must exist as a directory and it must be owned by the user, path = %s" % path)
89
+ msgs.append("Warning: no updates are possible on this path by this user.")
90
+ print_log_messages(msgs, logger, False)
91
+ return
92
+
93
+ # if path is empty, first use pull_data
94
+ if len(os.listdir(path))==0:
95
+ pull_data(path, logger, verbose=verbose)
96
+ # double check that it's not empty
97
+ if len(os.listdir(path))==0:
98
+ print_log_messages("pull_data failed, see the error messages for more details. update_all can not continue")
99
+ return
100
+
101
+ # readme.txt must exist in path at this point, using get_data_info provides more possible feedback
102
+ dataInfo = get_data_info(path, logger)
103
+ if dataInfo is None:
104
+ # this should not happen
105
+ print_log_messages('could not find any data information about %s, can not continue with update_all' % path, logger, True)
106
+
107
+ if dataInfo['casarundata'] is None:
108
+ print_log_messages('readme.txt not found at path, update_all can not continue, path = %s' % path, logger)
109
+ return
110
+
111
+ if dataInfo['casarundata'] == 'invalid':
112
+ print_log_messages('readme.txt is invalid at path, update_all can not continue, path = %s' % path, logger)
113
+ return
114
+
115
+ if dataInfo['casarundata'] == 'unknown':
116
+ print_log_messages('contents at path appear to be casarundata but no readme.txt was found, casaconfig did not populate this data and update_all can not continue, path = %s', path, logger)
117
+ return
118
+
119
+ # the updates should work now
120
+ data_update(path, logger, force=force, verbose=verbose)
121
+ measures_update(path, logger, force=force, verbose=verbose)
122
+
123
+ return