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.

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