| 1 |
from packagewindows import PackageInfo, generateInstallFiles |
| 2 |
|
| 3 |
from os.path import abspath, basename, exists, join as joinpath, relpath |
| 4 |
from zipfile import ZIP_DEFLATED, ZipFile |
| 5 |
import os, sys |
| 6 |
|
| 7 |
def addFile(zipFile, path, zipPath): |
| 8 |
print('Adding ' + path) |
| 9 |
zipFile.write(path, zipPath, ZIP_DEFLATED) |
| 10 |
|
| 11 |
def addDirectory(zipFile, root, zipPath): |
| 12 |
for path, dirs, files in os.walk(root): |
| 13 |
for name in files: |
| 14 |
thisZipPath = zipPath |
| 15 |
if abspath(root) != abspath(path): |
| 16 |
thisZipPath = joinpath(thisZipPath, relpath(path, root)) |
| 17 |
addFile(zipFile, joinpath(path, name), joinpath(thisZipPath, name)) |
| 18 |
|
| 19 |
def packageZip(info): |
| 20 |
print('Generating install files...') |
| 21 |
generateInstallFiles(info) |
| 22 |
|
| 23 |
if not exists(info.packagePath): |
| 24 |
os.mkdir(info.packagePath) |
| 25 |
|
| 26 |
zipFileName = info.packageFileName + '-bin.zip' |
| 27 |
zipFilePath = joinpath(info.packagePath, zipFileName) |
| 28 |
if exists(zipFilePath): |
| 29 |
os.unlink(zipFilePath) |
| 30 |
|
| 31 |
print('Generating ' + zipFilePath) |
| 32 |
zipFile = ZipFile(zipFilePath, 'w') |
| 33 |
|
| 34 |
addDirectory(zipFile, joinpath(info.makeInstallPath, 'doc'), 'doc') |
| 35 |
addDirectory(zipFile, joinpath(info.makeInstallPath, 'share'), 'share') |
| 36 |
addDirectory(zipFile, info.codecPath, 'codec') |
| 37 |
addFile(zipFile, info.openmsxExePath, basename(info.openmsxExePath)) |
| 38 |
addFile( |
| 39 |
zipFile, joinpath(info.sourcePath, 'resource\\openmsx.ico'), |
| 40 |
'share\\icons\\openmsx.ico' |
| 41 |
) |
| 42 |
|
| 43 |
if info.packageCatapult: |
| 44 |
addFile(zipFile, info.catapultExePath, 'Catapult\\bin\\Catapult.exe') |
| 45 |
addDirectory(zipFile, joinpath(info.catapultPath, 'doc'), 'Catapult\\doc') |
| 46 |
addDirectory( |
| 47 |
zipFile, joinpath(info.catapultPath, 'resources\\bitmaps'), |
| 48 |
'Catapult\\resources\\bitmaps' |
| 49 |
) |
| 50 |
addDirectory( |
| 51 |
zipFile, joinpath(info.catapultBuildPath, 'install\\dialogs'), |
| 52 |
'Catapult\\resources\\dialogs' |
| 53 |
) |
| 54 |
addFile( |
| 55 |
zipFile, joinpath(info.catapultSourcePath, 'catapult.xpm'), |
| 56 |
'Catapult\\resources\\icons\\catapult.xpm' |
| 57 |
) |
| 58 |
addFile( |
| 59 |
zipFile, joinpath(info.catapultPath, 'README'), |
| 60 |
'Catapult\\doc\\README' |
| 61 |
) |
| 62 |
zipFile.close() |
| 63 |
|
| 64 |
zipFileName = info.packageFileName + '-pdb.zip' |
| 65 |
zipFilePath = joinpath(info.packagePath, zipFileName) |
| 66 |
if exists(zipFilePath): |
| 67 |
os.unlink(zipFilePath) |
| 68 |
|
| 69 |
print('Generating ' + zipFilePath) |
| 70 |
zipFile = ZipFile(zipFilePath, 'w') |
| 71 |
addFile(zipFile, info.openmsxPdbPath, basename(info.openmsxPdbPath)) |
| 72 |
if info.packageCatapult: |
| 73 |
addFile(zipFile, info.catapultPdbPath, basename(info.catapultPdbPath)) |
| 74 |
zipFile.close() |
| 75 |
|
| 76 |
if __name__ == '__main__': |
| 77 |
if len(sys.argv) == 4: |
| 78 |
packageZip(PackageInfo(*sys.argv[1 : ])) |
| 79 |
else: |
| 80 |
print( |
| 81 |
'Usage: py packagezip.py ' |
| 82 |
'platform configuration catapultPath', |
| 83 |
file=sys.stderr |
| 84 |
) |
| 85 |
sys.exit(2) |