casaconfig 1.1.0__tar.gz → 1.1.1__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 (38) hide show
  1. {casaconfig-1.1.0/casaconfig.egg-info → casaconfig-1.1.1}/PKG-INFO +1 -1
  2. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/data_update.py +2 -2
  3. casaconfig-1.1.1/casaconfig/private/measures_available.py +84 -0
  4. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/measures_update.py +63 -64
  5. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/pull_data.py +2 -2
  6. {casaconfig-1.1.0 → casaconfig-1.1.1/casaconfig.egg-info}/PKG-INFO +1 -1
  7. {casaconfig-1.1.0 → casaconfig-1.1.1}/pyproject.toml +1 -1
  8. casaconfig-1.1.0/casaconfig/private/measures_available.py +0 -59
  9. {casaconfig-1.1.0 → casaconfig-1.1.1}/LICENSE +0 -0
  10. {casaconfig-1.1.0 → casaconfig-1.1.1}/MANIFEST.in +0 -0
  11. {casaconfig-1.1.0 → casaconfig-1.1.1}/README.md +0 -0
  12. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/__init__.py +0 -0
  13. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/__main__.py +0 -0
  14. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/config.py +0 -0
  15. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/CasaconfigErrors.py +0 -0
  16. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/__init__.py +0 -0
  17. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/casasiteconfig_example.py +0 -0
  18. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/config_defaults.py +0 -0
  19. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/config_defaults_static.py +0 -0
  20. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/data_available.py +0 -0
  21. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/do_auto_updates.py +0 -0
  22. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/do_pull_data.py +0 -0
  23. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/get_argparser.py +0 -0
  24. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/get_config.py +0 -0
  25. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/get_data_info.py +0 -0
  26. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/get_data_lock.py +0 -0
  27. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/io_redirect.py +0 -0
  28. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/print_log_messages.py +0 -0
  29. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/read_readme.py +0 -0
  30. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/set_casacore_path.py +0 -0
  31. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/summary.py +0 -0
  32. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig/private/update_all.py +0 -0
  33. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig.egg-info/SOURCES.txt +0 -0
  34. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig.egg-info/dependency_links.txt +0 -0
  35. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig.egg-info/requires.txt +0 -0
  36. {casaconfig-1.1.0 → casaconfig-1.1.1}/casaconfig.egg-info/top_level.txt +0 -0
  37. {casaconfig-1.1.0 → casaconfig-1.1.1}/setup.cfg +0 -0
  38. {casaconfig-1.1.0 → casaconfig-1.1.1}/tests/test_casaconfig.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: casaconfig
3
- Version: 1.1.0
3
+ Version: 1.1.1
4
4
  Summary: CASA Operational Configuration Package
5
5
  Author-email: National Radio Astronomy Observatory <casa-feedback@nrao.edu>
6
6
  License: Apache License
@@ -330,7 +330,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
330
330
 
331
331
  except BadLock as exc:
332
332
  # the path is known to exist so this means that the lock file was not empty and it's not locked
333
- msgs = str(exc)
333
+ msgs = [str(exc)]
334
334
  msgs.append('data_update: the lock file at %s is not empty.' % path)
335
335
  msgs.append('A previous attempt to update path may have failed or exited prematurely.')
336
336
  msgs.append('Remove the lock file and set force to True with the desired version (default to most recent).')
@@ -341,7 +341,7 @@ def data_update(path=None, version=None, force=False, logger=None, auto_update_r
341
341
 
342
342
  except BadReadme as exc:
343
343
  # something is wrong in the readme after an update was triggered, this shouldn't happen, print more context reraise this
344
- msgs = str(exc)
344
+ msgs = [str(exc)]
345
345
  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')
346
346
  msgs.append('Check for other updates in progress or choose a different path or clear out this path and try again using pull_data or update_all')
347
347
  print_log_messages(msgs, logger, True)
@@ -0,0 +1,84 @@
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 measures_available():
19
+ """
20
+ List available measures versions on ASTRON at https://www.astron.nl/iers/
21
+
22
+ This returns a list of the measures versions available on the ASTRON
23
+ server. The version parameter of measures_update must be one
24
+ of the values in that list if set (otherwise the most recent version
25
+ in this list is used).
26
+
27
+ Parameters
28
+ None
29
+
30
+ Returns
31
+ list - version names returned as list of strings
32
+
33
+ Raises
34
+ - casaconfig.RemoteError - Raised when there is an error fetching some remote content
35
+ - Exception - Unexpected exception while getting list of available measures versions
36
+
37
+ """
38
+
39
+ import html.parser
40
+ import urllib.request
41
+ import urllib.error
42
+ import ssl
43
+ import certifi
44
+
45
+ from casaconfig import RemoteError
46
+
47
+ class LinkParser(html.parser.HTMLParser):
48
+ def reset(self):
49
+ super().reset()
50
+ self.rundataList = []
51
+
52
+ def handle_starttag(self, tag, attrs):
53
+ if tag == 'a':
54
+ for (name, value) in attrs:
55
+ # only care if this is an href and the value starts with
56
+ # WSRT_Measures and has 'tar' after character 15 to exclude the "WSRT_Measures.ztar" file
57
+ # without relying on the specific type of compression or nameing in more detail than that
58
+ if name == 'href' and (value.startswith('WSRT_Measures') and (value.rfind('tar')>15)):
59
+ # only add it to the list if it's not already there
60
+ if (value not in self.rundataList):
61
+ self.rundataList.append(value)
62
+
63
+ try:
64
+ context = ssl.create_default_context(cafile=certifi.where())
65
+ with urllib.request.urlopen('https://www.astron.nl/iers', context=context, timeout=400) as urlstream:
66
+ parser = LinkParser()
67
+ encoding = urlstream.headers.get_content_charset() or 'UTF-8'
68
+ for line in urlstream:
69
+ parser.feed(line.decode(encoding))
70
+
71
+ # return the sorted list, earliest versions are first, newest is last
72
+ return sorted(parser.rundataList)
73
+
74
+ except urllib.error.URLError as urlerr:
75
+ raise RemoteError("Unable to retrieve list of available measures versions : " + str(urlerr)) from None
76
+
77
+ except Exception as exc:
78
+ msg = "Unexpected exception while getting list of available measures versions : " + str(exc)
79
+ raise Exception(msg)
80
+
81
+ # nothing to return if it got here, must have been an exception
82
+ return []
83
+
84
+
@@ -17,20 +17,23 @@ this module will be included in the api
17
17
 
18
18
  def measures_update(path=None, version=None, force=False, logger=None, auto_update_rules=False, use_astron_obs_table=False, verbose=None):
19
19
  """
20
- Update or install the IERS data used for measures calculations from the ASTRON server at path.
20
+ Update or install the IERS data used for measures calculations from ASTRON into 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
24
  If no update is necessary then this function will silently return.
25
25
 
26
- The verbose argument controls the level of information provided when this function when the data
27
- are unchanged for expected reasons. A level of 0 prints and logs nothing. A
28
- value of 1 logs the information and a value of 2 logs and prints the information.
26
+ The verbose argument controls the level of information provided by this function when the data
27
+ are unchanged for expected reasons. A level of 0 outputs nothing. A
28
+ value of 1 sends any output to the logger and a value of 2 logs and prints the information.
29
+ The default value of the verbose argument is taken from the casaconfig_verbose config
30
+ value (defaults to 1).
29
31
 
30
32
  CASA maintains a separate Observatories table which is available in the casarundata
31
33
  collection through pull_data and data_update. The Observatories table found at ASTRON
32
34
  is not installed by measures_update and any Observatories file at path will not be changed
33
- by using this function.
35
+ by using this function. This behavior can be changed by setting force and use_astron_obs_table
36
+ both to True (use_astron_obs_table is ignored when force is False).
34
37
 
35
38
  A text file (readme.txt in the geodetic directory in path) records the measures version string
36
39
  and the date when that version was installed in path.
@@ -43,9 +46,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
43
46
  If a specific version is not requested (the default) and the modification time of that text
44
47
  file is less than 24 hrs before now then this function does nothing unless force is True. When this
45
48
  function checks for a more recent version and finds that the installed version is the most recent
46
- then modification time of that text file is checked to the current time even though nothing has
47
- changed in path. This limits the number of attempts to update the measures data (including checking f\
48
- or more recent data) to once per day. When the force argument is True and a specific version is
49
+ then the modification time of that text file is changed to the current time even though nothing has
50
+ changed in path. This limits the number of attempts to update the measures data (including checking
51
+ for more recent data) to once per day. When the force argument is True and a specific version is
49
52
  not requested then this function always checks for the latest version.
50
53
 
51
54
  When auto_update_rules is True then path must exist and contain the expected readme.txt file.
@@ -75,11 +78,11 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
75
78
  especially if they may also be starting at that time. If a specific version is
76
79
  requested or force is True there is a risk that the measures may be updated while
77
80
  one of those other sessions are trying to load the same measures data, leading to
78
- unpredictable results. The lock file will prevent simulateous updates from
79
- happening but if each simultanous update eventually updates the same measures
81
+ unpredictable results. The lock file will prevent simultaneous updates from
82
+ happening but if each simultaneous update eventually updates the same measures
80
83
  location (because force is True or the updates are requesting different versions)
81
- then the measures that any of those simultanous casatools modules sees is
82
- unpredictable. Avoid multiple, simultanous updates outside of the automatic
84
+ then the measures that any of those simultaneous casatools modules sees is
85
+ unpredictable. Avoid multiple, simultaneous updates outside of the automatic
83
86
  update process.
84
87
 
85
88
  **Note:** during auto updates, measures_update requires that the expected
@@ -91,10 +94,10 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
91
94
  read and write permissions there). The version must then also be None and the force option
92
95
  must be False.
93
96
 
94
- **Note::** During use outside of auto updates, if path does not exist it will be created
97
+ **Note:** During use outside of auto updates, if path does not exist it will be created
95
98
  by this function.
96
99
 
97
- **Notes::** During use outside of auto updates, if the readme.txt file exists but can not
100
+ **Note:** During use outside of auto updates, if the readme.txt file exists but can not
98
101
  be read as expected **OR** that file does not exist but the contents of path appear to
99
102
  contain measures data (table names in the expected locations) then this function will
100
103
  print messages describing that and exit without changing anything at path. Using
@@ -104,24 +107,25 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
104
107
 
105
108
  Parameters
106
109
  - path (str=None) - Folder path to place updated measures data. Must contain a valid geodetic/readme.txt. If not set then config.measurespath is used.
107
- - version (str=None) - Version of measures data to retrieve (usually in the form of yyyymmdd-160001.ztar, see measures_available()). Default None retrieves the latest.
110
+ - version (str=None) - Version of measures data to retrieve (usually in the form of WSRT_Measures_yyyymmdd-160001.ztar, see measures_available()). Default None retrieves the latest.
108
111
  - force (bool=False) - If True, always re-download the measures data. Default False will not download measures data if updated within the past day unless the version parameter is specified and different from what was last downloaded.
109
112
  - logger (casatools.logsink=None) - Instance of the casalogger to use for writing messages. Default None writes messages to the terminal
110
113
  - auto_update_rules (bool=False) - If True then the user must be the owner of path, version must be None, and force must be False.
114
+ - use_astron_obs_table (bool=False) - If True and force is also True then keep the Observatories table found in the Measures tar tarball (possibly overwriting the Observatories table from casarundata).
111
115
  - verbose (int=None) - Level of output, 0 is none, 1 is to logger, 2 is to logger and terminal, defaults to casaconfig_verbose in config dictionary.
112
116
 
113
117
  Returns
114
118
  None
115
119
 
116
120
  Raises
117
- casaconfig.AutoUpdatesNotAllowed - raised when path does not exists as a directory or is not owned by the user when auto_update_rules is True
118
- casaconfig.BadLock - raised when the lock file was not empty when found
119
- casaconfig.BadReadme - raised when something unexpected is found in the readme or the readme changed after an update is in progress
120
- casaconfig.NoReadme - raised when the readme.txt file is not found at path (path also may not exist)
121
- casaconfig.NotWritable - raised when the user does not have permission to write to path
122
- casaconfig.RemoteError - raised by measures_available when the remote list of measures could not be fetched
123
- casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
124
- Exception - raised when something unexpected happened while updating measures
121
+ - casaconfig.AutoUpdatesNotAllowed - raised when path does not exists as a directory or is not owned by the user when auto_update_rules is True
122
+ - casaconfig.BadLock - raised when the lock file was not empty when found
123
+ - casaconfig.BadReadme - raised when something unexpected is found in the readme or the readme changed after an update is in progress
124
+ - casaconfig.NoReadme - raised when the readme.txt file is not found at path (path also may not exist)
125
+ - casaconfig.NotWritable - raised when the user does not have permission to write to path
126
+ - casaconfig.RemoteError - raised by measures_available when the remote list of measures could not be fetched
127
+ - casaconfig.UnsetMeasurespath - raised when path is None and has not been set in config
128
+ - Exception - raised when something unexpected happened while updating measures
125
129
 
126
130
  """
127
131
  import os
@@ -129,13 +133,12 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
129
133
  from datetime import datetime
130
134
  import sys
131
135
 
132
- from ftplib import FTP
133
136
  import tarfile
134
137
  import re
135
138
  import ssl
136
139
  import urllib.request
137
140
  import certifi
138
- import fcntl
141
+ import shutil
139
142
 
140
143
  from casaconfig import measures_available
141
144
  from casaconfig import AutoUpdatesNotAllowed, UnsetMeasurespath, RemoteError, NotWritable, BadReadme, BadLock, NoReadme
@@ -244,7 +247,7 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
244
247
 
245
248
  # lock the measures_update.lock file
246
249
  lock_fd = None
247
- clean_lock = True # set to false if the contents are actively being u pdate and the lock file should not be cleaned one exception
250
+ clean_lock = True # set to false if the contents are actively being update and the lock file should not be cleaned one exception
248
251
  try:
249
252
  print_log_messages('measures_update ... acquiring the lock ... ', logger)
250
253
 
@@ -286,13 +289,9 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
286
289
  if force:
287
290
  print_log_messages('A measures update has been requested by the force argument', logger)
288
291
 
289
- print_log_messages(' ... connecting to ftp.astron.nl ...', logger)
292
+ print_log_messages(' ... finding available measures at www.astron.nl ...', logger)
290
293
 
291
- clean_lock = False
292
- ftp = FTP('ftp.astron.nl')
293
- rc = ftp.login()
294
- rc = ftp.cwd('outgoing/Measures')
295
- files = sorted([ff for ff in ftp.nlst() if (len(ff) > 0) and (not ff.endswith('.dat')) and (ftp.size(ff) > 0)])
294
+ files = measures_available()
296
295
 
297
296
  # target filename to download
298
297
  # for the non-force unspecified version case this can only get here if the age is > 1 day so there should be a newer version
@@ -302,51 +301,51 @@ def measures_update(path=None, version=None, force=False, logger=None, auto_upda
302
301
  print_log_messages("measures_update can't find specified version %s" % target, logger, True)
303
302
 
304
303
  else:
305
- # there are files to extract, make sure there's no past measures.ztar from a failed previous install
306
- ztarPath = os.path.join(path,'measures.ztar')
307
- if os.path.exists(ztarPath):
308
- os.remove(ztarPath)
309
-
310
- with open(ztarPath, 'wb') as fid:
311
- print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger)
312
- ftp.retrbinary('RETR ' + target, fid.write)
313
-
314
- ftp.close()
315
-
304
+ # there are files to extract
305
+ print_log_messages(' ... downloading %s from ASTRON server to %s ...' % (target, path), logger)
306
+
307
+ astronURL = 'https://www.astron.nl/iers'
308
+ context = ssl.create_default_context(cafile=certifi.where())
309
+ # just in case there's a redirect at astron the way there is for the go.nrao.edu site and casarundata
310
+ measuresURLroot = urllib.request.urlopen(astronURL, context=context).url
311
+ measuresURL = os.path.join(measuresURLroot, target)
312
+
313
+ # it's at this point that this code starts modifying what's there so the lock file should
314
+ # not be removed on failure after this although it may leave that temp tar file around, but that's OK
315
+ clean_lock = False
316
316
  # remove any existing measures readme.txt now in case something goes wrong during extraction
317
317
  readme_path = os.path.join(path,'geodetic/readme.txt')
318
318
  if os.path.exists(readme_path):
319
319
  os.remove(readme_path)
320
320
 
321
- # extract from the fetched tarfile
322
- with tarfile.open(ztarPath, mode='r:gz') as ztar:
323
- # the list of members to extract
324
- x_list = []
325
- for m in ztar.getmembers() :
326
- if force and use_astron_obs_table:
327
- # exclude the *.old names in geodetic
328
- if not(re.search('geodetic',m.name) and re.search('.old',m.name)):
329
- x_list.append(m)
330
- else:
331
- # exclude the Observatories table and *.old names in geodetic
332
- if not((re.search('geodetic',m.name) and re.search('.old',m.name)) or re.search('Observatories',m.name)):
333
- x_list.append(m)
334
-
321
+ # custom filter that incorporates data_filter to watch for dangerous members of the tar file and
322
+ # add filtering to remove the Observatories table (unless use_astron_obs_table is True) and
323
+ # the *.old tables that may be in the geodetic tree
324
+ def custom_filter(member, extractionPath):
325
+ # member is a TarInfo instance and extractionPath is the destination path
326
+ # use the 'data_filter' first to deal with dangerous members
327
+ member = tarfile.data_filter(member, extractionPath)
328
+ # always exclude *.old names in geodetic
329
+ if (member is not None) and (re.search('geodetic',member.name) and re.search('.old',member.name)):
330
+ member = None
331
+ # the use_astron_obs_table argumen only has weight if force is True
332
+ if (not (force and use_astron_obs_table)) and (member is not None) and (re.search('Observatories',member.name)):
333
+ member = None
334
+ return member
335
+
336
+ with urllib.request.urlopen(measuresURL, context=context, timeout=400) as tstream, tarfile.open(fileobj=tstream, mode='r|*') as tar :
335
337
  # use the 'data' filter if available, revert to previous 'fully_trusted' behavior of not available
336
- ztar.extraction_filter = getattr(tarfile, 'data_filter', (lambda member, path: member))
337
- ztar.extractall(path=path,members=x_list)
338
- ztar.close()
339
-
340
- os.remove(ztarPath)
338
+ tar.extraction_filter = custom_filter
339
+ tar.extractall(path=path)
340
+ tar.close()
341
341
 
342
342
  # create a new readme.txt file
343
343
  with open(readme_path,'w') as fid:
344
344
  fid.write("# measures data populated by casaconfig\nversion : %s\ndate : %s" % (target, datetime.today().strftime('%Y-%m-%d')))
345
345
 
346
+ clean_lock = True
346
347
  print_log_messages(' ... measures data updated at %s' % path, logger)
347
348
 
348
- clean_lock = True
349
-
350
349
  # closing out the do_update
351
350
 
352
351
  # closing out the try block
@@ -283,7 +283,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
283
283
 
284
284
  except BadLock as exc:
285
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)
286
+ msgs = [str(exc)]
287
287
  msgs.append('The lock file at %s is not empty.' % path)
288
288
  msgs.append('A previous attempt to update path may have failed or exited prematurely.')
289
289
  msgs.append('It may be best to completely repopulated path using pull_data and measures_update.')
@@ -292,7 +292,7 @@ def pull_data(path=None, version=None, force=False, logger=None, verbose=None):
292
292
  raise
293
293
  except BadReadme as exc:
294
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)
295
+ msgs = [str(exc)]
296
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
297
  msgs.append('Check for other updates in progress or choose a different path or clear out this path and try again')
298
298
  print_log_messages(msgs, logger, True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: casaconfig
3
- Version: 1.1.0
3
+ Version: 1.1.1
4
4
  Summary: CASA Operational Configuration Package
5
5
  Author-email: National Radio Astronomy Observatory <casa-feedback@nrao.edu>
6
6
  License: Apache License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "casaconfig"
3
- version = "1.1.0"
3
+ version = "1.1.1"
4
4
  description = "CASA Operational Configuration Package"
5
5
  readme = 'README.md'
6
6
  authors = [
@@ -1,59 +0,0 @@
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 measures_available():
20
- """
21
- List available measures versions on the ASTRON server
22
-
23
- This returns a list of the measures files available on the ASTRON
24
- server. The version parameter of measures_update must be one
25
- of the values in that list if set (otherwise the most recent version
26
- in this list is used).
27
-
28
- Parameters
29
- None
30
-
31
- Returns
32
- version names returned as list of strings
33
-
34
- Raises:
35
- - casaconfig.RemoteError - raised when when a socket.gaierror is seen, likely due to no network connection
36
- - Exception: raised when any unexpected exception happens
37
-
38
- """
39
- from ftplib import FTP
40
- import socket
41
-
42
- from casaconfig import RemoteError
43
-
44
- files = []
45
- try:
46
- ftp = FTP('ftp.astron.nl')
47
- rc = ftp.login()
48
- rc = ftp.cwd('outgoing/Measures')
49
- files = ftp.nlst()
50
- ftp.quit()
51
- #files = [ff.replace('WSRT_Measures','').replace('.ztar','').replace('_','') for ff in files]
52
- files = [ff for ff in files if (len(ff) > 0) and (not ff.endswith('.dat'))]
53
- except socket.gaierror as gaierr:
54
- raise RemoteError("Unable to retrieve list of available measures versions : " + str(gaierr)) from None
55
- except Exception as exc:
56
- msg = "Unexpected exception while getting list of available measures versions : " + str(exc)
57
- raise Exception(msg)
58
-
59
- return files
File without changes
File without changes
File without changes
File without changes