-
Notifications
You must be signed in to change notification settings - Fork 38
/
package.in.py
executable file
·126 lines (108 loc) · 3.69 KB
/
package.in.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
#! /usr/bin/python
import sys
import os
import errno
import shutil
import glob
import tarfile
import zipfile
import platform
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise
MAJOR_VERSION = '@ALS_MAJOR_VERSION@'
MINOR_VERSION = '@ALS_MINOR_VERSION@'
PATCH_VERSION = '@ALS_PATCH_VERSION@'
ALS_VERSION = "%s.%s.%s" % (MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
ARNOLD_VERSION = '@ARNOLD_VERSION@'
subdirs = [
'alBlackbody',
'alCache',
'alColorSpace',
'alCombine',
'alCurvature',
'alFlake',
'alHair',
'alInputVector',
'alJitterColor',
'alLayer',
'alMeasured',
'alNoise',
'alPattern',
'alRemap',
'alSurface',
'alSwitch',
'alTriplanar',
'alFresnel',
'alCel',
'common',
'share'
]
# pattern for files to include in the source distribution
name_src = 'alShaders-src-%s.%s.%s' % (MAJOR_VERSION,MINOR_VERSION,PATCH_VERSION)
ptrn_src = ['*.cpp', '*.h', '*.txt', '*.py', '*.ui', '*.cmake']
# Binary distribution
files_src = ['INSTALL', 'CMakeLists.txt', 'package.in.py', 'README', 'uigen.py']
name_osx = 'alShaders-osx-%s-ai%s' % (ALS_VERSION, ARNOLD_VERSION)
name_win = 'alShaders-win-%s-ai%s' % (ALS_VERSION, ARNOLD_VERSION)
name_linux = 'alShaders-linux-%s-ai%s' % (ALS_VERSION, ARNOLD_VERSION)
def copyPatternsToDistDir(subDirs, subDirPrefix, filePatterns, distDir):
for d in subDirs:
destdir = os.path.join(distDir, d)
mkdir_p(destdir)
subdir = os.path.join(subDirPrefix, d)
for ptrn in filePatterns:
sdir = subdir
for fn in glob.iglob(os.path.join(sdir, ptrn)):
shutil.copy(fn, destdir)
def copyFilesToDistDir(files, distDir):
for fn in files:
shutil.copy(fn, distDir)
def createArchive(distDir, name, isSrc=False):
if not isSrc and platform.system() == "Windows":
f = zipfile.ZipFile(os.path.join('..', '%s.zip' % name), 'w')
for fn in glob.iglob(os.path.join(distDir, '*')):
f.write(fn, arcname=os.path.join(name, os.path.basename(fn)))
f.close()
else:
f = tarfile.open(os.path.join('..', '%s.tar.gz' % name), 'w:gz')
f.add(distDir, arcname = name)
f.close()
def createSourceDistribution(name, ptrn_src, files):
distdir = 'build/%s' % name
shutil.rmtree(distdir, ignore_errors=True)
os.mkdir(distdir)
copyPatternsToDistDir(subdirs, '.', ptrn_src, distdir)
copyFilesToDistDir(files_src, distdir)
createArchive(distdir, name, True)
def createBinaryDistribution(name, droot):
if platform.system() == "Windows":
zf = zipfile.ZipFile(os.path.join('..', '%s.zip' % name), 'w')
for root, dirs, files in os.walk(droot):
rroot = os.path.relpath(root, droot)
for f in files:
rfile = os.path.join(rroot, f)
zf.write(os.path.join(droot, rfile), arcname=rfile)
else:
f = tarfile.open(os.path.join('..', '%s.tar.gz' % name), 'w:gz')
f.add(droot, arcname = name)
f.close()
# source distribution
createSourceDistribution(name_src, ptrn_src, files_src)
# Binary distribution
droot = 'build/dist/%s/ai%s' % (ALS_VERSION, ARNOLD_VERSION)
if platform.system() == "Darwin":
# OS X distribution
createBinaryDistribution(name_osx, droot)
elif platform.system() == "Windows":
# Windows
createBinaryDistribution(name_win, droot)
elif platform.system() == "Linux":
# Linux
createBinaryDistribution(name_linux, droot)
else:
print 'Warning: unknown system "%s", not creating binary package' % platform.system()