You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
5.8 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. """Youtube-dlg setup file.
  4. Examples:
  5. Windows::
  6. python setup.py py2exe
  7. Linux::
  8. python setup.py install
  9. Build source distribution::
  10. python setup.py sdist
  11. Build platform distribution::
  12. python setup.py bdist
  13. Build the translations::
  14. python setup.py build
  15. Requirements:
  16. * GNU gettext utilities
  17. Notes:
  18. If you get 'TypeError: decoding Unicode is not supported' when you run
  19. py2exe then apply the following patch::
  20. http://sourceforge.net/p/py2exe/patches/28/
  21. Basic steps of the setup::
  22. * Run pre-build tasks
  23. * Call setup handler based on OS & options
  24. * Set up hicolor icons (if supported by platform)
  25. * Set up fallback pixmaps icon (if supported by platform)
  26. * Set up package level pixmaps icons (*.png, *.ico)
  27. * Set up package level i18n files (*.mo)
  28. * Set up scripts (executables) (if supported by platform)
  29. * Run setup
  30. """
  31. from distutils.core import setup
  32. import os
  33. import sys
  34. import glob
  35. from shutil import copyfile
  36. from subprocess import call
  37. PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == "py2exe"
  38. if PY2EXE:
  39. try:
  40. import py2exe
  41. except ImportError as error:
  42. print error
  43. sys.exit(1)
  44. from youtube_dl_gui import (
  45. __author__,
  46. __appname__,
  47. __contact__,
  48. __version__,
  49. __license__,
  50. __projecturl__,
  51. __description__,
  52. __packagename__,
  53. __descriptionfull__
  54. )
  55. # Setup can not handle unicode
  56. __packagename__ = str(__packagename__)
  57. # Helper functions
  58. def create_scripts():
  59. """Create the binary scripts."""
  60. dest_dir = os.path.join("build", "_scripts")
  61. if not os.path.exists(dest_dir):
  62. os.makedirs(dest_dir)
  63. copyfile(os.path.join(__packagename__, "__main__.py"),
  64. os.path.join(dest_dir, "youtube-dl-gui"))
  65. def build_translations():
  66. """Build the MO files."""
  67. exec_name = "msgfmt.exe" if os.name == "nt" else "msgfmt"
  68. search_pattern = os.path.join("youtube_dl_gui", "locale", "*", "LC_MESSAGES", "*.po")
  69. for po_file in glob.glob(search_pattern):
  70. mo_file = po_file.replace(".po", ".mo")
  71. try:
  72. print "Building MO file for '%s'" % po_file
  73. call([exec_name, "-o", mo_file, po_file])
  74. except OSError:
  75. print "Could not locate file '%s', exiting..." % exec_name
  76. sys.exit(1)
  77. ##################################
  78. def linux_setup():
  79. scripts = []
  80. data_files = []
  81. package_data = {}
  82. # Add hicolor icons
  83. for path in glob.glob("youtube_dl_gui/data/icons/hicolor/*x*"):
  84. size = os.path.basename(path)
  85. dst = "share/icons/hicolor/{size}/apps".format(size=size)
  86. src = "{icon_path}/apps/youtube-dl-gui.png".format(icon_path=path)
  87. data_files.append((dst, [src]))
  88. # Add fallback icon, see issue #14
  89. data_files.append(
  90. ("share/pixmaps", ["youtube_dl_gui/data/pixmaps/youtube-dl-gui.png"])
  91. )
  92. # Add other package data
  93. package_data[__packagename__] = [
  94. "data/pixmaps/*.png",
  95. "data/pixmaps/*.ico",
  96. "locale/*/LC_MESSAGES/*.mo"
  97. ]
  98. # Add scripts
  99. scripts.append("build/_scripts/youtube-dl-gui")
  100. setup_params = {
  101. "scripts": scripts,
  102. "data_files": data_files,
  103. "package_data": package_data
  104. }
  105. return setup_params
  106. def windows_setup():
  107. def normal_setup():
  108. package_data = {}
  109. # On Windows we dont use the icons under hicolor
  110. package_data[__packagename__] = [
  111. "data\\pixmaps\\*.png",
  112. "data\\pixmaps\\*.ico",
  113. "locale\\*\\LC_MESSAGES\\*.mo"
  114. ]
  115. setup_params = {
  116. "package_data": package_data
  117. }
  118. return setup_params
  119. def py2exe_setup():
  120. windows = []
  121. data_files = []
  122. # Py2exe dependencies & options
  123. dependencies = [
  124. "C:\\Windows\\System32\\ffmpeg.exe",
  125. "C:\\Windows\\System32\\ffprobe.exe",
  126. "C:\\python27\\DLLs\\MSVCP90.dll"
  127. ]
  128. options = {
  129. "includes": ["wx.lib.pubsub.*",
  130. "wx.lib.pubsub.core.*",
  131. "wx.lib.pubsub.core.arg1.*"]
  132. }
  133. #############################################
  134. # Add package data
  135. data_files.extend([
  136. ("", dependencies),
  137. ("data\\pixmaps", glob.glob("youtube_dl_gui\\data\\pixmaps\\*.*")),
  138. ])
  139. # We have to manually add the translation files since py2exe cant do it
  140. for lang in os.listdir("youtube_dl_gui\\locale"):
  141. dst = os.path.join("locale", lang, "LC_MESSAGES")
  142. src = os.path.join("youtube_dl_gui", dst, "youtube_dl_gui.mo")
  143. data_files.append((dst, [src]))
  144. # Add GUI executable details
  145. windows.append({
  146. "script": "build\\_scripts\\youtube-dl-gui",
  147. "icon_resources": [(0, "youtube_dl_gui\\data\\pixmaps\\youtube-dl-gui.ico")]
  148. })
  149. setup_params = {
  150. "windows": windows,
  151. "data_files": data_files,
  152. "options": {"py2exe": options}
  153. }
  154. return setup_params
  155. if PY2EXE:
  156. return py2exe_setup()
  157. return normal_setup()
  158. # Execute pre-build stuff
  159. create_scripts()
  160. build_translations()
  161. if os.name == "nt":
  162. params = windows_setup()
  163. else:
  164. params = linux_setup()
  165. setup(
  166. author = __author__,
  167. name = __appname__,
  168. version = __version__,
  169. license = __license__,
  170. author_email = __contact__,
  171. url = __projecturl__,
  172. description = __description__,
  173. long_description = __descriptionfull__,
  174. packages = [__packagename__],
  175. **params
  176. )