-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
138 lines (104 loc) · 3.82 KB
/
__init__.py
File metadata and controls
138 lines (104 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# __all__=["acx2"]
import acx2
import pyatomdb
import curl
import os
import shutil
import time
import urllib
import wget
__version__="2.5.1"
#-------------------------------------------------------------------------------
def download_acx2_emissivity_files(adbroot, userid, version):
"""
Download the AtomDB equilibrium emissivity files for AtomDB"
This code will go to the AtomDB FTP site and download the necessary files.
It will then unpack them into a directory adbroot. It will not
overwrite existing files with the same md5sum (to avoid pointless updates)
but it will not know this until it has downloaded and unzipped the main
file.
Parameters
----------
adbroot : string
The location to install the data. Typically should match $ATOMDB
userid : string
An 8 digit ID number. Usually passed as a string, but integer
is also fine (provided it is all numbers)
version : string
The version string for the release, e.g. "3.0.2"
Returns
-------
None
"""
#
# Version 0.1 Initail Release
# Adam Foster 24th September 2015
#
import tarfile
# set up remote file name
fname = "acx2-v%s-data.tar.bz2"%(version)
# set up temporary directory to hold data
if adbroot[0] != '/':
# is a relative path
adbroot = "%s/%s"%(os.getcwd(), adbroot)
pyatomdb.util.mkdir_p(adbroot)
if adbroot[-1]=='/':
tmpdir = adbroot+'installtmp'
else:
tmpdir = adbroot+'/installtmp'
print("making directory %s"%(tmpdir))
pyatomdb.util.mkdir_p(tmpdir)
# get the files
urllib.request.urlcleanup()
fnameout = wget.download('%s/releases/%s'%(pyatomdb.const.FTPPATH,fname), out="%s/%s"%(tmpdir, fname))
# collect user statistics if allowed.
pyatomdb.util.record_upload(fname)
#uncompress
print("")
print("Uncompressing ... ", end=' ')
tf = tarfile.open(name=fnameout, mode='r:bz2')
tf.extractall(path=tmpdir)
print("Uncompressed")
# copy the files
dirname = 'acx2-v%s-data'%(version)
for l in os.listdir('%s/%s'%(tmpdir, dirname)):
print("moving %s/%s/%s to %s/%s"%(tmpdir, dirname, l, adbroot, l))
shutil.move("%s/%s/%s"%(tmpdir, dirname, l), "%s/%s"%(adbroot, l))
print("...done")
shutil.rmtree(tmpdir)
# check initialization
on_rtd=os.environ.get('READTHEDOCS')=='True'
install='no'
if on_rtd:
pass
else:
if os.environ.get('ATOMDB')==None:
print("ATOMDB environment variable is not set. Please set this to where your "+\
"AtomDB files are stored. If you do not have these files, open python and "+\
"call `import pyatomdb' to set up. Exiting.")
exit()
# issues here
adbroot=os.environ.get('ATOMDB')
READMEFILE = os.path.expandvars("$ATOMDB/README_ACX")
if not os.path.exists(READMEFILE):
print("ACX2 emissivity files not found. Installing now to $ATOMDB folder (%s)."%\
os.path.expandvars('$ATOMDB'))
install='yes'
if install=='yes':
a=curl.Curl()
version=a.get('%s/releases/LATEST_ACX'%(pyatomdb.const.FTPPATH))[:-1].decode(encoding='ascii')
userprefs = pyatomdb.util.load_user_prefs(adbroot=adbroot)
userid = userprefs['USERID']
userprefs['LASTCXVERSIONCHECK'] = time.time()
userprefs = pyatomdb.util.write_user_prefs(userprefs, adbroot=adbroot)
download_acx2_emissivity_files(os.environ.get('ATOMDB'), userid, version)
# elif not os.path.exists(os.path.expandvars("$ATOMDB/userdata")):
# install = ''
# while not install in ['yes','no']:
# install = util.question("ATOMDB Environment Variable Not Set. Set up AtomDB files now?", "yes",multichoice=["yes","no","info"])
# if install=='info':
# print("If yes, this will run the pyatomdb.util.initialize() script, which installs the necessary data files to run pyatomdb")
# if install=='yes':
# util.initialize()
# now get the CX files
#elif not os.path.exists(os.path.expandvars("$ATOMDB/userdata")):