|
| 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): |
| 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 | + This uses pull_data, data_update and measures_update. See the |
| 37 | + documentation for those functions for additional details. |
| 38 | +
|
| 39 | + Some of the data updated by this function is only read when casatools starts. |
| 40 | + Use of update_all after CASA has started should typically be followed by a restart |
| 41 | + so that any changes are seen by the tools and tasks that use this data. |
| 42 | +
|
| 43 | + Parameters |
| 44 | + - 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 used the value of measurespath set by importing config.py. |
| 45 | + - 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. |
| 46 | +
|
| 47 | + Returns |
| 48 | + None |
| 49 | +
|
| 50 | + """ |
| 51 | + |
| 52 | + import os |
| 53 | + |
| 54 | + from .print_log_messages import print_log_messages |
| 55 | + from .pull_data import pull_data |
| 56 | + from .data_update import data_update |
| 57 | + from .measures_update import measures_update |
| 58 | + |
| 59 | + if path is None: |
| 60 | + from casaconfig import config |
| 61 | + path = config.measurespath |
| 62 | + |
| 63 | + if path is None: |
| 64 | + print_log_messages("config.measurespath is None. Edit your config.py or the casasiteconfig.py to set measurespath to an appropriate location,", logger, True) |
| 65 | + return |
| 66 | + |
| 67 | + if not os.path.exists(path): |
| 68 | + # create it, all the way down |
| 69 | + try: |
| 70 | + os.makedirs(path, exist_ok=True) |
| 71 | + except: |
| 72 | + print_log_messages("unable to create path, check the permissions of the directory it is being created at, path = %s" % path, logger, True) |
| 73 | + return |
| 74 | + |
| 75 | + # path must be a directory and it must be owned by the user |
| 76 | + |
| 77 | + if (not os.path.isdir(path)) or (os.stat(path).st_uid != os.getuid()): |
| 78 | + print_log_messages("path must exist as a directory and it must be owned by the user, path = %s" % path, logger, True) |
| 79 | + return |
| 80 | + |
| 81 | + # if path is empty, first use pull_data |
| 82 | + if len(os.listdir(path))==0: |
| 83 | + pull_data(path, logger) |
| 84 | + # double check that it's not empty |
| 85 | + if len(os.listdir(path))==0: |
| 86 | + print_log_messages("pull_data failed, see the error messages for more details. update_all can not continue") |
| 87 | + return |
| 88 | + |
| 89 | + # readme.txt must exist in path at this point |
| 90 | + if not os.path.exists(os.path.join(path, 'readme.txt')): |
| 91 | + print_log_messages('readme.txt not found at path, update_all can not continue, path = %s' % path, logger) |
| 92 | + return |
| 93 | + |
| 94 | + # the updates should work now |
| 95 | + data_update(path, logger) |
| 96 | + measures_update(path, logger) |
| 97 | + |
| 98 | + return |
0 commit comments