packagezip.py 2.6 KB

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