Skip to content

Commit 52409d1

Browse files
committed
Merge branch 'master' of github.com:casangi/casaconfig
2 parents 0b17cd3 + 3e1bf0e commit 52409d1

File tree

7 files changed

+111
-8
lines changed

7 files changed

+111
-8
lines changed

Diff for: casaconfig/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
Interface specification for all user facing external functions in the casaconfig package.
33
"""
44
# __init__.py
5+
print("top of init")
56
from .private.pull_data import pull_data
67
from .private.data_available import data_available
78
from .private.data_update import data_update
89
from .private.measures_available import measures_available
910
from .private.measures_update import measures_update
11+
from .private.update_all import update_all
1012
from .private.set_casacore_path import set_casacore_path
1113
from .private.get_config import get_config
14+
print("bottom of init")

Diff for: casaconfig/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from .private import io_redirect as _io
3939
from .private.get_argparser import get_argparser as __get_argparser
4040

41+
print("top of casaconfig/config.py")
42+
4143
## list of config variables
4244
__defaults = [ x for x in dir(_config_defaults) if not x.startswith('_') ]
4345

Diff for: casaconfig/private/config_defaults.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def _globals( ):
5757
measurespath = _f
5858
else:
5959
datapath = [ ]
60-
measurespath = _os.path.expanduser("~/.casa/measures")
60+
measurespath = _os.path.expanduser("~/.casa/data")
6161
else:
6262
datapath = [ ]
63-
measurespath = _os.path.expanduser("~/.casa/measures")
63+
measurespath = _os.path.expanduser("~/.casa/data")
6464

Diff for: casaconfig/private/get_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def get_config( expanded=False ):
99
list[str] - list of configuration strings
1010
"""
1111

12-
from .. import config as _config
12+
from casaconfig import config as _config
1313
if expanded :
1414
valsObj = _config
1515
else:

Diff for: casaconfig/private/get_data_lock.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def get_data_lock(path, fn_name):
6767
lock_fd.write("locked using %s by %s on %s : pid = %s at %s" % (fn_name, getpass.getuser(), os.uname().nodename, os.getpid(), datetime.today().strftime('%Y-%m-%d:%H:%M:%S')))
6868
lock_fd.flush()
6969
except:
70-
print("Unexpected failure in writing lock information to lock file %s" % lock_path)
71-
print("Called by function : %s" % fn_name)
7270
import traceback
7371
traceback.print_exc()
72+
print("Unexpected failure in writing lock information to lock file %s" % lock_path)
73+
print("Called by function : %s" % fn_name)
7474
lock_fd.close()
7575
return None
7676

Diff for: casaconfig/private/pull_data.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def pull_data(path, version=None, force=False, logger=None):
5656
a fresh copy of the desired version.
5757
5858
Some of the tables installed by pull_data are only read when casatools starts. Use of
59-
pull_data should typically be followed by a restart so that any changes are seen by the
60-
tools and tasks that use this data.
59+
pull_data after CASA has started should typically be followed by a restart so that
60+
any changes are seen by the tools and tasks that use this data.
6161
6262
Parameters
63-
- path (str) - Folder path to place casadata contents. It must be empty or not exist or contain a valid, previously installed version.
63+
- path (str) - Folder path to place casarundata contents. It must be empty or not exist or contain a valid, previously installed version.
6464
- version (str=None) - casadata version to retrieve. Default None gets the most recent version.
6565
- force (bool=False) - If True, re-download 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.
6666
- 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.

Diff for: casaconfig/private/update_all.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

Comments
 (0)