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.

212 lines
5.0 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. # Helper functions
  51. def create_scripts():
  52. """Create the binary scripts."""
  53. dest_dir = os.path.join("build", "_scripts")
  54. if not os.path.exists(dest_dir):
  55. os.makedirs(dest_dir)
  56. copyfile(os.path.join(__packagename__, "__main__.py"),
  57. os.path.join(dest_dir, "youtube-dl-gui"))
  58. ##################################
  59. def linux_setup():
  60. scripts = []
  61. data_files = []
  62. package_data = {}
  63. # Add hicolor icons
  64. for path in glob.glob("youtube_dl_gui/data/icons/hicolor/*x*"):
  65. size = os.path.basename(path)
  66. dst = "share/icons/hicolor/{size}/apps".format(size=size)
  67. src = "{icon_path}/apps/youtube-dl-gui.png".format(icon_path=path)
  68. data_files.append((dst, [src]))
  69. # Add fallback icon, see issue #14
  70. data_files.append(
  71. ("share/pixmaps", ["youtube_dl_gui/data/pixmaps/youtube-dl-gui.png"])
  72. )
  73. # Add other package data
  74. package_data[__packagename__] = [
  75. "data/pixmaps/*.png",
  76. "data/pixmaps/*.ico",
  77. "locale/*/LC_MESSAGES/*.mo"
  78. ]
  79. # Add scripts
  80. scripts.append("build/_scripts/youtube-dl-gui")
  81. setup_params = {
  82. "scripts": scripts,
  83. "data_files": data_files,
  84. "package_data": package_data
  85. }
  86. return setup_params
  87. def windows_setup():
  88. def normal_setup():
  89. package_data = {}
  90. # On Windows we dont use the icons under hicolor
  91. package_data[__packagename__] = [
  92. "data\\pixmaps\\*.png",
  93. "data\\pixmaps\\*.ico",
  94. "locale\\*\\LC_MESSAGES\\*.mo"
  95. ]
  96. setup_params = {
  97. "package_data": package_data
  98. }
  99. return setup_params
  100. def py2exe_setup():
  101. windows = []
  102. data_files = []
  103. # Py2exe dependencies & options
  104. dependencies = [
  105. "C:\\Windows\\System32\\ffmpeg.exe",
  106. "C:\\Windows\\System32\\ffprobe.exe",
  107. "C:\\python27\\DLLs\\MSVCP90.dll"
  108. ]
  109. options = {
  110. "includes": ["wx.lib.pubsub.*",
  111. "wx.lib.pubsub.core.*",
  112. "wx.lib.pubsub.core.arg1.*"]
  113. }
  114. #############################################
  115. # Add package data
  116. data_files.extend([
  117. ("", dependencies),
  118. ("data\\pixmaps", glob.glob("youtube_dl_gui\\data\\pixmaps\\*.*")),
  119. ])
  120. # We have to manually add the translation files since py2exe cant do it
  121. for lang in os.listdir("youtube_dl_gui\\locale"):
  122. dst = os.path.join("locale", lang, "LC_MESSAGES")
  123. src = os.path.join("youtube_dl_gui", dst, "youtube_dl_gui.mo")
  124. data_files.append((dst, [src]))
  125. # Add GUI executable details
  126. windows.append({
  127. "script": "build\\_scripts\\youtube-dl-gui",
  128. "icon_resources": [(0, "youtube_dl_gui\\data\\pixmaps\\youtube-dl-gui.ico")]
  129. })
  130. setup_params = {
  131. "windows": windows,
  132. "data_files": data_files,
  133. "options": {"py2exe": options}
  134. }
  135. return setup_params
  136. if PY2EXE:
  137. return py2exe_setup()
  138. return normal_setup()
  139. # Execute pre-build stuff
  140. create_scripts()
  141. if os.name == "nt":
  142. params = windows_setup()
  143. else:
  144. params = linux_setup()
  145. setup(
  146. author = __author__,
  147. name = __appname__,
  148. version = __version__,
  149. license = __license__,
  150. author_email = __contact__,
  151. url = __projecturl__,
  152. description = __description__,
  153. long_description = __descriptionfull__,
  154. packages = [str(__packagename__)],
  155. **params
  156. )