-
Notifications
You must be signed in to change notification settings - Fork 4
/
linux_distrubution.py
267 lines (223 loc) · 7.96 KB
/
linux_distrubution.py
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"""
Create the distribution zip file.
General paradigm is files and dir's are chosen to be distributed,
rather than having everything automatically distributed. This stops
getting junky files/dir's getting into the distribution.
"""
import sys
import tempfile
import re
import os
from shutil import copyfile, copytree, rmtree
from os import system, remove, sep, getcwd, chdir, rmdir, mkdir, popen, \
listdir
from os.path import join, isfile
from for_all_verification import do_tests_checks_demos_audits
# directories to include in the distro, at the root level
distro_dirs = [
'demo',
'Documentation',
'eqrm_code',
'implementation_tests',
'Matlab_utils',
'postprocessing',
'preprocessing',
'resources',
'test_resources'
]
# files to include at the root level
# Note copyright.pdf is created from copyright.tex
distro_files = [
'check_scenarios.py',
'clean_all.py',
'copyright.tex',
'eqrm_analysis.py',
'README.txt',
'README-getting-started.txt',
'README-getting-started.txt',
'README-install.txt',
'README-tests.txt',
'test_all.py'
]
def main():
create_distribution_zip('eqrm_version2.1.',distro_dirs=distro_dirs,
distro_files=distro_files)
def create_distribution_zip(vername, distro_dirs=None,
distro_files=None):
"""
Create a zip file that can be posted to source forge.
vername - part of the distribution file;
vername+'svn'+version+'.zip'
distro_dirs - directories in python_eqrm to be included in the zip file.
distro_files - files in python_eqrm to be included in the zip file.
return:
Return False if create_distribution_zip fails
"""
# Exporting the eqrm root repository to the temp file
expo_dir = tempfile.mkdtemp(prefix='EQRM_distribution_expo_dir')
print "expo_dir", expo_dir
# When using this, make sure the expo_dir is not deleted in 2 places.
if True:
s = 'svn --force export http://65.61.168.30/svn/eqrm_core/trunk '\
+ expo_dir
print s
print "This will take a while..."
fid = popen(s)
version_info = fid.read()
print "version_info", version_info
for line in version_info.split('\n'):
# print "line", line
if line.startswith('Exported'):
version = re.findall(re.compile(r'[0-9]+'),line)
if len(version)==1:
version = version[0]
print "Got a version number:" , version
else:
print "Could not get version number. Got this instead", \
version
print "WARNING: Using incorrect version number."
version ='999'
fid.close()
else:
expo_dir = join("C:","WINNT","Profiles","gray duncan",
"Local Settings","Temp",
"EQRM_distribution_expo_dir-uphuz")
expo_dir = join("c:\\","dump","eqrm_core_trunk")
version = '858'
# create another temp dir to move things into
temp_dir = tempfile.mkdtemp(prefix='EQRM_distribution_temp_dir')
eqrm_dir_name = 'python_eqrm'
# zip_dir is the directory where files to be distributed are placed
zip_dir = join(temp_dir, eqrm_dir_name)
mkdir(zip_dir)
print "zip_dir", zip_dir
# Copy the dir's we want to distribute
for dir in distro_dirs:
# Fail silently if I can't copy a dir.
src = join(expo_dir, dir)
dst = join(zip_dir, dir)
copytree(src, dst)
# Copy the file's we want to distribute
for file in distro_files:
# Fail silently if I can't copy a file.
src = join(expo_dir, file)
dst = join(zip_dir, file)
try:
copyfile(src, dst)
except:
pass
# I tried doing the compile stuff before moving files.
# It didn't work for me.
# compile the copyright document
current_dir = getcwd()
chdir(zip_dir)
print ' '
print 'compiling the copyright document'
s = 'latex copyright.tex'
print s
system(s)
s = 'dvipdfm copyright.dvi'
print s
system(s)
remove('copyright.tex')
remove('copyright.dvi')
try:
remove('copyright.aux')
except:
pass
try:
remove('copyright.log')
except:
pass
try:
remove('copyright.tex.bak')
except:
pass
# Move the EQRM inputs pdf to the Documentation directory.
src = join(expo_dir, 'latex_sourcefiles', 'manual_tech', 'EQRM_inputs.pdf')
dst = join(zip_dir, 'Documentation', 'EQRM_inputs.pdf')
try:
copyfile(src, dst)
except:
print "***************************************"
print "*** Could not move EQRM_inputs.pdf ***"
print "***************************************"
if False:
chdir('latex_sourcefiles')
chdir('manual_tech')
file_base = 'EQRM_inputs'
print ' '
print 'compiling the new parameter list'
s = 'latex ' + file_base + '.tex'
print s
system(s)
s = 'dvipdfm ' + file_base + '.dvi'
print s
system(s)
if False:
for ext in ['.tex', '.log', '.aux', '.dvi']:
try:
remove(file_base + ext)
except:
pass
try:
remove(file_base + '.bak')
except:
pass
chdir('..')
chdir('..')
chdir('Documentation')
# Remove, this dir is not our IP, we shouldn't distribute.
rmtree('coding_standards')
# Add the stored_version_info.py file to eqrm_code
chdir('..')
chdir('eqrm_code')
fid = open('stored_version_info.py', 'w')
fid.write('version = '+version+'\n')
fid.close()
remove('test_cadell_damage.py')
#rmtree('plotting')
#eqrm_code_dir = join(zip_dir,'eqrm_code')
#store_version_info(eqrm_code_dir)
# Create the zip file before running tests which create .pyc
zip_file = vername+'svn'+version+'.zip'
repos_distro_file = join(current_dir,'distribution', zip_file)
chdir(temp_dir)
print ' '
print 'zipping application into ', repos_distro_file
system('zip -r -q '+zip_file+' '+eqrm_dir_name)
# Haven't tried
# # List all files in the current directory
# allFileNames = os.listdir( os.curdir )
# # Open the zip file for writing, and write some files to it
# myZipFile = zipfile.ZipFile( "spam_skit.zip", "w" )
# # Write each file present into the new zip archive, except the python script
# for fileName in allFileNames:
# (name, ext) = os.path.splitext( fileName )
# if ext != ".py":
# print "Writing... " + fileName
# myZipFile.write( fileName, os.path.basename(fileName), zipfile.ZIP_DEFLATED )
# myZipFile.close()
# Run all the tests
results_passed = do_tests_checks_demos_audits(
eqrm_root_dir=zip_dir,
ip_audit=True,
test_all=True,
check_scenarios=True,
mini_check_scenarios=False,
demo_batchrun=True,
verbose=True)
if results_passed is False:
#os.remove(zip_file) # delete the zip file. It is a fail
#clean_up(current_dir, temp_dir, expo_dir)
return False
chdir(temp_dir)
# Move the zip file to the repository distro dir
copyfile(zip_file,repos_distro_file)
clean_up(current_dir, temp_dir, expo_dir)
def clean_up(current_dir, temp_dir, expo_dir):
chdir(current_dir)
rmtree(temp_dir)
rmtree(expo_dir)
if __name__ == '__main__':
main()