Coverage for /home/deng/Projects/ete4/hackathon/ete4/ete4/config.py: 62%
13 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-03-21 09:19 +0100
« prev ^ index » next coverage.py v7.2.7, created at 2024-03-21 09:19 +0100
1"""
2Constants with the XDG-compliant directories for ete.
3"""
5# See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
7from os import environ, system
8from os.path import dirname, exists
11def ete_path(xdg_var, default):
12 return environ.get(xdg_var, environ['HOME'] + default) + '/ete'
14ETE_DATA_HOME = ete_path('XDG_DATA_HOME', '/.local/share')
15ETE_CONFIG_HOME = ete_path('XDG_CONFIG_HOME', '/.config')
16ETE_CACHE_HOME = ete_path('XDG_CACHE_HOME', '/.cache')
19def update_ete_data(path, url):
20 """Refresh the contents of path with the ones in the given in the url."""
21 # Resolve relative paths to refer to ETE_DATA_HOME.
22 if not path.startswith('/'):
23 path = ETE_DATA_HOME + '/' + path
25 if dirname(path) and not exists(dirname(path)):
26 system('mkdir -p ' + dirname(path)) # create the directory
28 system(f'wget -c -nv -O {path} {url}') # update from the web
29 # TODO: Some possible improvements:
30 # - Raise an exception if the update doesn't happen.
31 # - Do not require wget to be installed.
34# Example:
35#
36# path = 'gtdb202dump.tar.gz'
37# url = ('https://github.com/etetoolkit/ete-data/raw/main'
38# '/gtdb_taxonomy/gtdb202/gtdb202dump.tar.gz')
39#
40# update_ete_data(path, url)