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.

282 lines
6.7 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_trans
  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)
  27. * Set up package level i18n files (*.mo)
  28. * Set up scripts (executables) (if supported by platform)
  29. * Run setup
  30. """
  31. from distutils import cmd
  32. from distutils.core import setup
  33. from distutils.command.build import build
  34. import os
  35. import sys
  36. import glob
  37. from shutil import copyfile
  38. from subprocess import call
  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. def on_windows():
  60. """Returns True if OS is Windows."""
  61. return os.name == "nt"
  62. class BuildBin(cmd.Command):
  63. description = "build the youtube-dl-gui binary file"
  64. user_options = []
  65. def initialize_options(self):
  66. self.scripts_dir = None
  67. def finalize_options(self):
  68. self.scripts_dir = os.path.join("build", "_scripts")
  69. def run(self):
  70. if not os.path.exists(self.scripts_dir):
  71. os.makedirs(self.scripts_dir)
  72. copyfile(os.path.join(__packagename__, "__main__.py"),
  73. os.path.join(self.scripts_dir, "youtube-dl-gui"))
  74. class BuildTranslations(cmd.Command):
  75. description = "build the translation files"
  76. user_options = []
  77. def initialize_options(self):
  78. self.exec_name = None
  79. self.search_pattern = None
  80. def finalize_options(self):
  81. if on_windows():
  82. self.exec_name = "msgfmt.exe"
  83. else:
  84. self.exec_name = "msgfmt"
  85. self.search_pattern = os.path.join(__packagename__, "locale", "*", "LC_MESSAGES", "youtube_dl_gui.po")
  86. def run(self):
  87. for po_file in glob.glob(self.search_pattern):
  88. mo_file = po_file.replace(".po", ".mo")
  89. try:
  90. print("building MO file for '{}'").format(po_file)
  91. call([self.exec_name, "-o", mo_file, po_file])
  92. except OSError:
  93. print("could not locate file '{}', exiting...".format(self.exec_name))
  94. sys.exit(1)
  95. class Build(build):
  96. """Overwrite the default 'build' behaviour."""
  97. sub_commands = [
  98. ("build_bin", None),
  99. ("build_trans", None)
  100. ] + build.sub_commands
  101. def run(self):
  102. build.run(self)
  103. # Overwrite cmds
  104. cmdclass = {
  105. "build": Build,
  106. "build_bin": BuildBin,
  107. "build_trans": BuildTranslations
  108. }
  109. def linux_setup():
  110. scripts = []
  111. data_files = []
  112. package_data = {}
  113. # Add hicolor icons
  114. for path in glob.glob("youtube_dl_gui/data/icons/hicolor/*x*"):
  115. size = os.path.basename(path)
  116. dst = "share/icons/hicolor/{size}/apps".format(size=size)
  117. src = "{icon_path}/apps/youtube-dl-gui.png".format(icon_path=path)
  118. data_files.append((dst, [src]))
  119. # Add fallback icon, see issue #14
  120. data_files.append(
  121. ("share/pixmaps", ["youtube_dl_gui/data/pixmaps/youtube-dl-gui.png"])
  122. )
  123. # Add pixmaps icons (*.png) & i18n files
  124. package_data[__packagename__] = [
  125. "data/pixmaps/*.png",
  126. "locale/*/LC_MESSAGES/*.mo"
  127. ]
  128. # Add scripts
  129. scripts.append("build/_scripts/youtube-dl-gui")
  130. setup_params = {
  131. "scripts": scripts,
  132. "data_files": data_files,
  133. "package_data": package_data
  134. }
  135. return setup_params
  136. def windows_setup():
  137. def normal_setup():
  138. package_data = {}
  139. # Add pixmaps icons (*.png) & i18n files
  140. package_data[__packagename__] = [
  141. "data\\pixmaps\\*.png",
  142. "locale\\*\\LC_MESSAGES\\*.mo"
  143. ]
  144. setup_params = {
  145. "package_data": package_data
  146. }
  147. return setup_params
  148. def py2exe_setup():
  149. windows = []
  150. data_files = []
  151. # py2exe dependencies & options
  152. # TODO change directory for ffmpeg.exe & ffprobe.exe
  153. dependencies = [
  154. "C:\\Windows\\System32\\ffmpeg.exe",
  155. "C:\\Windows\\System32\\ffprobe.exe",
  156. "C:\\python27\\DLLs\\MSVCP90.dll"
  157. ]
  158. options = {
  159. "includes": ["wx.lib.pubsub.*",
  160. "wx.lib.pubsub.core.*",
  161. "wx.lib.pubsub.core.arg1.*"]
  162. }
  163. #############################################
  164. # Add py2exe deps & pixmaps icons (*.png)
  165. data_files.extend([
  166. ("", dependencies),
  167. ("data\\pixmaps", glob.glob("youtube_dl_gui\\data\\pixmaps\\*.png")),
  168. ])
  169. # We have to manually add the translation files since py2exe cant do it
  170. for lang in os.listdir("youtube_dl_gui\\locale"):
  171. dst = os.path.join("locale", lang, "LC_MESSAGES")
  172. src = os.path.join("youtube_dl_gui", dst, "youtube_dl_gui.mo")
  173. data_files.append((dst, [src]))
  174. # Add GUI executable details
  175. windows.append({
  176. "script": "build\\_scripts\\youtube-dl-gui",
  177. "icon_resources": [(0, "youtube_dl_gui\\data\\pixmaps\\youtube-dl-gui.ico")]
  178. })
  179. setup_params = {
  180. "windows": windows,
  181. "data_files": data_files,
  182. "options": {"py2exe": options}
  183. }
  184. return setup_params
  185. if PY2EXE:
  186. return py2exe_setup()
  187. return normal_setup()
  188. if on_windows():
  189. params = windows_setup()
  190. else:
  191. params = linux_setup()
  192. setup(
  193. author = __author__,
  194. name = __appname__,
  195. version = __version__,
  196. license = __license__,
  197. author_email = __contact__,
  198. url = __projecturl__,
  199. description = __description__,
  200. long_description = __descriptionfull__,
  201. packages = [__packagename__],
  202. cmdclass = cmdclass,
  203. **params
  204. )