Browse Source

Update setup.py to handle new UI changes

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
a1c33c4b3a
1 changed files with 132 additions and 95 deletions
  1. 227
      setup.py

227
setup.py

@ -3,19 +3,50 @@
"""Youtube-dlg setup file. """Youtube-dlg setup file.
Note:
Examples:
Windows::
python setup.py py2exe
Linux::
python setup.py install
Build source distribution::
python setup.py sdist
Build platform distribution::
python setup.py bdist
Notes:
If you get 'TypeError: decoding Unicode is not supported' when you run If you get 'TypeError: decoding Unicode is not supported' when you run
py2exe then apply the following patch:
py2exe then apply the following patch::
http://sourceforge.net/p/py2exe/patches/28/
http://sourceforge.net/p/py2exe/patches/28/
Basic steps of the setup::
* Run pre-build tasks
* Call setup handler based on OS & options
* Set up hicolor icons (if supported by platform)
* Set up fallback pixmaps icon (if supported by platform)
* Set up package level pixmaps icons (*.png, *.ico)
* Set up package level i18n files (*.mo)
* Set up scripts (executables) (if supported by platform)
* Run setup
""" """
from distutils.core import setup
import os import os
import sys import sys
import shutil
import glob
from shutil import copyfile
PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == 'py2exe'
PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == "py2exe"
if PY2EXE: if PY2EXE:
try: try:
@ -24,9 +55,6 @@ if PY2EXE:
print error print error
sys.exit(1) sys.exit(1)
from distutils.core import setup
from distutils.sysconfig import get_python_lib
from youtube_dl_gui import ( from youtube_dl_gui import (
__author__, __author__,
__appname__, __appname__,
@ -35,129 +63,138 @@ from youtube_dl_gui import (
__license__, __license__,
__projecturl__, __projecturl__,
__description__, __description__,
__packagename__,
__descriptionfull__ __descriptionfull__
) )
ICONS_SIZES = ('16x16', '32x32', '48x48', '64x64', '128x128', '256x256')
ICONS_TEMPLATE = 'youtube_dl_gui/icons/youtube-dl-gui_{size}.png'
ICONS_LIST = [ICONS_TEMPLATE.format(size=size) for size in ICONS_SIZES]
# Set icons path
PY2EXE_ICONS = 'icons'
WINDOWS_ICONS = os.path.join(get_python_lib(), 'youtube_dl_gui', 'icons')
LINUX_ICONS = '/usr/share/icons/hicolor/'
LINUX_FALLBACK_ICONS = '/usr/share/pixmaps/'
# Helper functions
def create_scripts():
"""Create the binary scripts."""
dest_dir = os.path.join("build", "_scripts")
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
# Set localization files path
LOCALE_PATH = os.path.join('youtube_dl_gui', 'locale')
copyfile(os.path.join(__packagename__, "__main__.py"),
os.path.join(dest_dir, "youtube-dl-gui"))
PY2EXE_LOCALE_DIR = 'locale'
WIN_LOCALE_DIR = os.path.join(get_python_lib(), 'youtube_dl_gui', 'locale')
LINUX_LOCALE_DIR = '/usr/share/{app_name}/locale/'.format(app_name=__appname__.lower())
##################################
def create_scripts():
dest_dir = os.path.join('build', '_scripts')
def linux_setup():
scripts = []
data_files = []
package_data = {}
dest_file = os.path.join(dest_dir, 'youtube-dl-gui')
src_file = os.path.join('youtube_dl_gui', '__main__.py')
# Add hicolor icons
for path in glob.glob("youtube_dl_gui/data/icons/hicolor/*x*"):
size = os.path.basename(path)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
shutil.copyfile(src_file, dest_file)
dst = "share/icons/hicolor/{size}/apps".format(size=size)
src = "{icon_path}/apps/youtube-dl-gui.png".format(icon_path=path)
data_files.append((dst, [src]))
def set_locale_files(data_files):
for directory in os.listdir(LOCALE_PATH):
locale_lang = os.path.join(directory, 'LC_MESSAGES')
# Add fallback icon, see issue #14
data_files.append(
("share/pixmaps", ["youtube_dl_gui/data/pixmaps/youtube-dl-gui.png"])
)
src = os.path.join(LOCALE_PATH, locale_lang, 'youtube_dl_gui.mo')
# Add other package data
package_data[__packagename__] = [
"data/pixmaps/*.png",
"data/pixmaps/*.ico",
"locale/*/LC_MESSAGES/*.mo"
]
if PY2EXE:
dst = os.path.join(PY2EXE_LOCALE_DIR, locale_lang)
elif os.name == 'nt':
dst = os.path.join(WIN_LOCALE_DIR, locale_lang)
else:
dst = os.path.join(LINUX_LOCALE_DIR, locale_lang)
# Add scripts
scripts.append("build/_scripts/youtube-dl-gui")
data_files.append((dst, [src]))
setup_params = {
"scripts": scripts,
"data_files": data_files,
"package_data": package_data
}
return setup_params
def py2exe_setup():
create_scripts()
py2exe_dependencies = [
'C:\\Windows\\System32\\ffmpeg.exe',
'C:\\Windows\\System32\\ffprobe.exe',
'C:\\python27\\DLLs\\MSVCP90.dll'
]
def windows_setup():
def normal_setup():
package_data = {}
py2exe_data_files = [
('', py2exe_dependencies),
(PY2EXE_ICONS, ICONS_LIST)
]
# On Windows we dont use the icons under hicolor
package_data[__packagename__] = [
"data\\pixmaps\\*.png",
"data\\pixmaps\\*.ico",
"locale\\*\\LC_MESSAGES\\*.mo"
]
set_locale_files(py2exe_data_files)
setup_params = {
"package_data": package_data
}
py2exe_options = {
'includes': ['wx.lib.pubsub.*',
'wx.lib.pubsub.core.*',
'wx.lib.pubsub.core.arg1.*']
}
return setup_params
py2exe_windows = {
'script': 'build\\_scripts\\youtube-dl-gui',
'icon_resources': [(0, 'youtube_dl_gui\\icons\\youtube-dl-gui.ico')]
}
def py2exe_setup():
windows = []
data_files = []
params = {
'data_files': py2exe_data_files,
'windows': [py2exe_windows],
'options': {'py2exe': py2exe_options}
}
# Py2exe dependencies & options
dependencies = [
"C:\\Windows\\System32\\ffmpeg.exe",
"C:\\Windows\\System32\\ffprobe.exe",
"C:\\python27\\DLLs\\MSVCP90.dll"
]
return params
options = {
"includes": ["wx.lib.pubsub.*",
"wx.lib.pubsub.core.*",
"wx.lib.pubsub.core.arg1.*"]
}
#############################################
def normal_setup():
data_files = list()
# Add package data
data_files.extend([
("", dependencies),
("data\\pixmaps", glob.glob("youtube_dl_gui\\data\\pixmaps\\*.*")),
])
if os.name == 'nt':
icons_dir = (WINDOWS_ICONS, ICONS_LIST)
data_files.append(icons_dir)
# We have to manually add the translation files since py2exe cant do it
for lang in os.listdir("youtube_dl_gui\\locale"):
dst = os.path.join("locale", lang, "LC_MESSAGES")
src = os.path.join("youtube_dl_gui", dst, "youtube_dl_gui.mo")
set_locale_files(data_files)
data_files.append((dst, [src]))
params = {'data_files': data_files}
else:
# Create all the hicolor icons
for index, size in enumerate(ICONS_SIZES):
icons_dest = os.path.join(LINUX_ICONS, size, 'apps')
icons_dir = (icons_dest, [ICONS_LIST[index]])
# Add GUI executable details
windows.append({
"script": "build\\_scripts\\youtube-dl-gui",
"icon_resources": [(0, "youtube_dl_gui\\data\\pixmaps\\youtube-dl-gui.ico")]
})
data_files.append(icons_dir)
setup_params = {
"windows": windows,
"data_files": data_files,
"options": {"py2exe": options}
}
# Add the 48x48 icon as fallback
fallback_icon = (LINUX_FALLBACK_ICONS, [ICONS_LIST[2]])
data_files.append(fallback_icon)
return setup_params
set_locale_files(data_files)
if PY2EXE:
return py2exe_setup()
create_scripts()
params = {'data_files': data_files, 'scripts': ['build/_scripts/youtube-dl-gui']}
return normal_setup()
return params
# Execute pre-build stuff
create_scripts()
if PY2EXE:
params = py2exe_setup()
if os.name == "nt":
params = windows_setup()
else: else:
params = normal_setup()
params = linux_setup()
setup( setup(
@ -169,7 +206,7 @@ setup(
url = __projecturl__, url = __projecturl__,
description = __description__, description = __description__,
long_description = __descriptionfull__, long_description = __descriptionfull__,
packages = ['youtube_dl_gui'],
packages = [str(__packagename__)],
**params **params
) )
Loading…
Cancel
Save