/
matlab_package.py
executable file
·81 lines (70 loc) · 2.21 KB
/
matlab_package.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
#!/usr/bin/env python
#
# A packaging script for NetWorkSpaces MATLAB
#
import sys, os, shutil
def copyDir():
for file in os.listdir("."):
if file in file_list:
shutil.copy(file, dest)
elif file in dir_list:
destDir = dest + "/" + file
shutil.copytree(file, destDir)
def removeCVS(path):
for file in os.listdir(path):
file_or_dir = os.path.join(path, file)
if file == "CVS":
shutil.rmtree(file_or_dir) # remove entire CVS directory without visiting
elif os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir):
removeCVS(file_or_dir)
def check():
for file in file_list:
if not os.path.exists(dest + "/" + file):
print "ERROR: " + file + " file cannot be found"
sys.exit(1)
for dir in dir_list:
if not os.path.exists(dest + "/" + dir):
print "ERROR: " + dir + " directory cannot be found"
sys.exit(1)
# initializing data
nt_ext = ".mexw32"
linux_ext = ".mexglx"
maci_ext = ".mexmaci"
nwsMex = "nwsMex"
release_version = "1.4"
dest = "nws_matlab_" + release_version
dist = "dist"
if os.name == "nt":
mexBinary = nwsMex + nt_ext
tarCmd = "zip -r"
tarball = dest + ".zip"
elif sys.platform == 'darwin':
mexBinary = nwsMex + maci_ext
tarCmd = "tar czvf"
tarball = dest + ".tar.gz"
else:
mexBinary = nwsMex + linux_ext
tarCmd = "tar czvf"
tarball = dest + ".tar.gz"
file_list = ["babelfish.m", "barrierNames.m", "cmdLaunch.m", "envcmd.m", "launch.m",
"lsfcmd.m", "rshcmd.m", "sshcmd.m", "scriptcmd.m", "workerLoop.m",
"INSTALL", "README", "README.sleigh", mexBinary]
dir_list = ["@netWorkSpace", "@nwsServer", "@sleigh", "@sleighPending",
"bin", "doc", "examples"]
if os.path.exists(dest):
print "Deleting", dest
shutil.rmtree(dest)
os.mkdir(dest)
if not os.path.exists(dist):
os.mkdir(dist)
# real work
copyDir()
removeCVS(dest)
# make sure all necessary files are in the package
check()
cmd = tarCmd + " " + tarball + " " + dest
print "Executing command:", cmd
os.system(tarCmd + " " + tarball + " " + dest) # make a tarball
# clean up
shutil.move(tarball, dist)
shutil.rmtree(dest) # remove temp directory