setup.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. """
  2. This is a setup.py script generated by py2applet
  3. Usage:
  4. python2.7 setup.py py2app
  5. """
  6. import sys
  7. import glob
  8. import os
  9. import plistlib
  10. import shutil
  11. import subprocess
  12. from setuptools import setup
  13. from setuptools.extension import Extension
  14. from distutils.file_util import copy_file
  15. from distutils.dir_util import mkpath
  16. from py2app.build_app import py2app as py2app_cmd
  17. if sys.version < '2.7':
  18. raise RuntimeError('LVC requires Python 2.7')
  19. APP = ['lvc/osx/app_main.py']
  20. DATA_FILES = ['lvc/widgets/osx/Resources-Widgets/MainMenu.nib']
  21. OPTIONS = {
  22. 'iconfile': os.path.join(SETUP_DIR, 'lvc3.icns'),
  23. 'excludes': ['lvc.widgets.gtk'],
  24. 'includes': ['lvc.widgets.osx.fasttypes'],
  25. 'packages': ['lvc', 'lvc.widgets', 'lvc.widgets.osx', 'lvc.ui',
  26. 'lvc.qtfaststart', 'lvc.resources']
  27. }
  28. # this should work if run from build.sh
  29. BKIT_DIR = os.environ['BKIT_PATH']
  30. def copy_binaries(source, target, binaries):
  31. mkpath(target)
  32. for mem in binaries:
  33. src = os.path.join(BKIT_DIR, source, mem)
  34. if os.path.islink(src):
  35. dst = os.path.join(target, mem)
  36. linkto = os.readlink(src)
  37. if os.path.exists(dst):
  38. os.remove(dst)
  39. os.symlink(linkto, dst)
  40. else:
  41. copy_file(src, target, update=True)
  42. def extract_tarball(tar_file, target_directory):
  43. subprocess.check_call(["tar", "-C", target_directory, "-zxf", tar_file])
  44. class py2app_lvc(py2app_cmd):
  45. def run(self):
  46. py2app_cmd.run(self)
  47. self.setup_directories()
  48. self.copy_ffmpeg()
  49. self.copy_sparkle()
  50. self.copy_update_public_key()
  51. self.delete_site_py()
  52. def setup_directories(self):
  53. self.bundle_root = os.path.join(self.dist_dir,
  54. 'Libre Video Converter.app/Contents')
  55. self.helpers_root = os.path.join(self.bundle_root, 'Helpers')
  56. self.frameworks_root = os.path.join(self.bundle_root, 'Frameworks')
  57. self.resources_root = os.path.join(self.bundle_root, 'Resources')
  58. self.python_lib_root = os.path.join(self.resources_root, 'lib',
  59. 'python2.7')
  60. if os.path.exists(self.helpers_root):
  61. shutil.rmtree(self.helpers_root)
  62. os.mkdir(self.helpers_root)
  63. def copy_ffmpeg(self):
  64. ffmpeg_files = ["ffmpeg"]
  65. lib_paths = glob.glob(os.path.join(BKIT_DIR, "ffmpeg", "bin",
  66. "*.dylib"))
  67. ffmpeg_files.extend(os.path.basename(p) for p in lib_paths)
  68. copy_binaries('ffmpeg/bin/', self.helpers_root, ffmpeg_files)
  69. def copy_sparkle(self):
  70. tarball = os.path.join(BKIT_DIR, "frameworks", "sparkle.1.5b6.tar.gz")
  71. extract_tarball(tarball, self.frameworks_root)
  72. def copy_update_public_key(self):
  73. src = os.path.join(SETUP_DIR, "sparkle-keys", "dsa_pub.pem")
  74. target = os.path.join(self.resources_root, 'dsa_pub.pem')
  75. copy_file(src, target, update=True)
  76. def delete_site_py(self):
  77. """Delete the site.py symlink.
  78. This causes issues with codesigning on 10.8 -- possibly because it's a
  79. symlink that links to a location outside the resources dir. In any
  80. case, it's not needed, so let's just nuke it.
  81. """
  82. os.unlink(os.path.join(self.python_lib_root, 'site.py'))
  83. plist = plistlib.readPlist(os.path.join(SETUP_DIR, 'Info.plist'))
  84. plist['NSHumanReadableCopyright'] = 'Copyright (C) Jesús E.'
  85. plist['CFBundleGetInfoString'] = 'Libre Video Converter'
  86. plist['CFBundleIdentifier'] = 'org.participatoryculture.MiroVideoConverter'
  87. plist['CFBundleShortVersionString'] = '1.1'
  88. plist['CFBundleExecutable'] = 'Libre Video Converter'
  89. plist['CFBundleName'] = 'Libre Video Converter'
  90. plist['CFBundleVersion'] = '1.1.0'
  91. plist['SUFeedURL'] = ('http://miro-updates.participatoryculture.org/'
  92. 'lvc-appcast-osx.xml')
  93. plist['SUPublicDSAKeyFile'] = 'dsa_pub.pem'
  94. OPTIONS['plist'] = plist
  95. setup(
  96. app=APP,
  97. data_files=DATA_FILES,
  98. options={'py2app': OPTIONS},
  99. setup_requires=['py2app'],
  100. cmdclass={'py2app': py2app_lvc},
  101. ext_modules=[
  102. Extension("lvc.widgets.osx.fasttypes",
  103. [
  104. os.path.join(
  105. ROOT_DIR,
  106. 'lvc', 'widgets',
  107. 'osx', 'fasttypes.c'
  108. )
  109. ])
  110. ],
  111. **SETUP_ARGS
  112. )