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.

245 lines
5.9 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. # Commands that run the pre-build tasks
  38. EXEC_PRE_COMMANDS = ["py2exe", "install", "bdist", "build"]
  39. PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == "py2exe"
  40. if PY2EXE:
  41. try:
  42. import py2exe
  43. except ImportError as error:
  44. print error
  45. sys.exit(1)
  46. from youtube_dl_gui import (
  47. __author__,
  48. __appname__,
  49. __contact__,
  50. __version__,
  51. __license__,
  52. __projecturl__,
  53. __description__,
  54. __packagename__,
  55. __descriptionfull__
  56. )
  57. # Setup can not handle unicode
  58. __packagename__ = str(__packagename__)
  59. # Helper functions
  60. def create_scripts():
  61. """Create the binary scripts."""
  62. dest_dir = os.path.join("build", "_scripts")
  63. if not os.path.exists(dest_dir):
  64. os.makedirs(dest_dir)
  65. copyfile(os.path.join(__packagename__, "__main__.py"),
  66. os.path.join(dest_dir, "youtube-dl-gui"))
  67. def build_translations():
  68. """Build the MO files."""
  69. exec_name = "msgfmt.exe" if os.name == "nt" else "msgfmt"
  70. search_pattern = os.path.join("youtube_dl_gui", "locale", "*", "LC_MESSAGES", "*.po")
  71. for po_file in glob.glob(search_pattern):
  72. mo_file = po_file.replace(".po", ".mo")
  73. try:
  74. print "Building MO file for '%s'" % po_file
  75. call([exec_name, "-o", mo_file, po_file])
  76. except OSError:
  77. print "Could not locate file '%s', exiting..." % exec_name
  78. sys.exit(1)
  79. ##################################
  80. def linux_setup():
  81. scripts = []
  82. data_files = []
  83. package_data = {}
  84. # Add hicolor icons
  85. for path in glob.glob("youtube_dl_gui/data/icons/hicolor/*x*"):
  86. size = os.path.basename(path)
  87. dst = "share/icons/hicolor/{size}/apps".format(size=size)
  88. src = "{icon_path}/apps/youtube-dl-gui.png".format(icon_path=path)
  89. data_files.append((dst, [src]))
  90. # Add fallback icon, see issue #14
  91. data_files.append(
  92. ("share/pixmaps", ["youtube_dl_gui/data/pixmaps/youtube-dl-gui.png"])
  93. )
  94. # Add other package data
  95. package_data[__packagename__] = [
  96. "data/pixmaps/*.png",
  97. "data/pixmaps/*.ico",
  98. "locale/*/LC_MESSAGES/*.mo"
  99. ]
  100. # Add scripts
  101. scripts.append("build/_scripts/youtube-dl-gui")
  102. setup_params = {
  103. "scripts": scripts,
  104. "data_files": data_files,
  105. "package_data": package_data
  106. }
  107. return setup_params
  108. def windows_setup():
  109. def normal_setup():
  110. package_data = {}
  111. # On Windows we dont use the icons under hicolor
  112. package_data[__packagename__] = [
  113. "data\\pixmaps\\*.png",
  114. "data\\pixmaps\\*.ico",
  115. "locale\\*\\LC_MESSAGES\\*.mo"
  116. ]
  117. setup_params = {
  118. "package_data": package_data
  119. }
  120. return setup_params
  121. def py2exe_setup():
  122. windows = []
  123. data_files = []
  124. # Py2exe dependencies & options
  125. dependencies = [
  126. "C:\\Windows\\System32\\ffmpeg.exe",
  127. "C:\\Windows\\System32\\ffprobe.exe",
  128. "C:\\python27\\DLLs\\MSVCP90.dll"
  129. ]
  130. options = {
  131. "includes": ["wx.lib.pubsub.*",
  132. "wx.lib.pubsub.core.*",
  133. "wx.lib.pubsub.core.arg1.*"]
  134. }
  135. #############################################
  136. # Add package data
  137. data_files.extend([
  138. ("", dependencies),
  139. ("data\\pixmaps", glob.glob("youtube_dl_gui\\data\\pixmaps\\*.*")),
  140. ])
  141. # We have to manually add the translation files since py2exe cant do it
  142. for lang in os.listdir("youtube_dl_gui\\locale"):
  143. dst = os.path.join("locale", lang, "LC_MESSAGES")
  144. src = os.path.join("youtube_dl_gui", dst, "youtube_dl_gui.mo")
  145. data_files.append((dst, [src]))
  146. # Add GUI executable details
  147. windows.append({
  148. "script": "build\\_scripts\\youtube-dl-gui",
  149. "icon_resources": [(0, "youtube_dl_gui\\data\\pixmaps\\youtube-dl-gui.ico")]
  150. })
  151. setup_params = {
  152. "windows": windows,
  153. "data_files": data_files,
  154. "options": {"py2exe": options}
  155. }
  156. return setup_params
  157. if PY2EXE:
  158. return py2exe_setup()
  159. return normal_setup()
  160. # Execute pre-build tasks
  161. if any(command in sys.argv for command in EXEC_PRE_COMMANDS):
  162. create_scripts()
  163. build_translations()
  164. if os.name == "nt":
  165. params = windows_setup()
  166. else:
  167. params = linux_setup()
  168. setup(
  169. author = __author__,
  170. name = __appname__,
  171. version = __version__,
  172. license = __license__,
  173. author_email = __contact__,
  174. url = __projecturl__,
  175. description = __description__,
  176. long_description = __descriptionfull__,
  177. packages = [__packagename__],
  178. **params
  179. )