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.

324 lines
8.0 KiB

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Youtube-dlg setup file.
python py2exe
python install
Build source distribution::
python sdist
Build platform distribution::
python bdist
Build the translations::
python build_trans
Build with updates disabled::
python build --no-updates
* GNU gettext utilities
If you get 'TypeError: decoding Unicode is not supported' when you run
py2exe then apply the following patch::
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)
* Set up package level i18n files (*.mo)
* Set up scripts (executables) (if supported by platform)
* Run setup
from distutils import cmd, log
from distutils.core import setup
from import build
import os
import sys
import glob
from shutil import copyfile
from subprocess import call
PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == "py2exe"
if PY2EXE:
import py2exe
except ImportError as error:
from youtube_dl_gui import (
# Setup can not handle unicode
__packagename__ = str(__packagename__)
def on_windows():
"""Returns True if OS is Windows."""
return == "nt"
class BuildBin(cmd.Command):
description = "build the youtube-dl-gui binary file"
user_options = []
def initialize_options(self):
self.scripts_dir = None
def finalize_options(self):
self.scripts_dir = os.path.join("build", "_scripts")
def run(self):
if not os.path.exists(self.scripts_dir):
copyfile(os.path.join(__packagename__, ""),
os.path.join(self.scripts_dir, "youtube-dl-gui"))
class BuildTranslations(cmd.Command):
description = "build the translation files"
user_options = []
def initialize_options(self):
self.exec_name = None
self.search_pattern = None
def finalize_options(self):
if on_windows():
self.exec_name = "msgfmt.exe"
self.exec_name = "msgfmt"
self.search_pattern = os.path.join(__packagename__, "locale", "*", "LC_MESSAGES", "youtube_dl_gui.po")
def run(self):
for po_file in glob.glob(self.search_pattern):
mo_file = po_file.replace(".po", ".mo")
try:"building MO file for '{}'".format(po_file))
call([self.exec_name, "-o", mo_file, po_file])
except OSError:
log.error("could not locate file '{}', exiting...".format(self.exec_name))
class Build(build):
"""Overwrite the default 'build' behaviour."""
sub_commands = [
("build_bin", None),
("build_trans", None)
] + build.sub_commands
build.user_options.append(("no-updates", None, "build with updates disabled"))
def initialize_options(self):
self.no_updates = None
def run(self):
if self.no_updates:
def __disable_updates(self):
lib_dir = os.path.join(self.build_lib, __packagename__)
target_file = ""
# Options file should be available from previous build commands
optionsfile = os.path.join(lib_dir, target_file)
data = None
with open(optionsfile, "r") as input_file:
data = input_file.readlines()
if data is None:
log.error("building with updates disabled failed!")
for index, line in enumerate(data):
if "'disable_update': False" in line:"disabling updates")
data[index] = line.replace("False", "True")
with open(optionsfile, "w") as output_file:
# Overwrite cmds
cmdclass = {
"build": Build,
"build_bin": BuildBin,
"build_trans": BuildTranslations
def linux_setup():
scripts = []
data_files = []
package_data = {}
# Add hicolor icons
for path in glob.glob("youtube_dl_gui/data/icons/hicolor/*x*"):
size = os.path.basename(path)
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]))
# Add fallback icon, see issue #14
("share/pixmaps", ["youtube_dl_gui/data/pixmaps/youtube-dl-gui.png"])
# Add man page
("share/man/man1", ["youtube-dl-gui.1"])
# Add pixmaps icons (*.png) & i18n files
package_data[__packagename__] = [
# Add scripts
setup_params = {
"scripts": scripts,
"data_files": data_files,
"package_data": package_data
return setup_params
def windows_setup():
def normal_setup():
package_data = {}
# Add pixmaps icons (*.png) & i18n files
package_data[__packagename__] = [
setup_params = {
"package_data": package_data
return setup_params
def py2exe_setup():
windows = []
data_files = []
# py2exe dependencies & options
# TODO change directory for ffmpeg.exe & ffprobe.exe
dependencies = [
options = {
"includes": ["wx.lib.pubsub.*",
# Add py2exe deps & pixmaps icons (*.png)
("", dependencies),
("data\\pixmaps", glob.glob("youtube_dl_gui\\data\\pixmaps\\*.png")),
# 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, "")
data_files.append((dst, [src]))
# Add GUI executable details
"script": "build\\_scripts\\youtube-dl-gui",
"icon_resources": [(0, "youtube_dl_gui\\data\\pixmaps\\youtube-dl-gui.ico")]
setup_params = {
"windows": windows,
"data_files": data_files,
"options": {"py2exe": options}
return setup_params
if PY2EXE:
return py2exe_setup()
return normal_setup()
if on_windows():
params = windows_setup()
params = linux_setup()
author = __author__,
name = __appname__,
version = __version__,
license = __license__,
author_email = __contact__,
url = __projecturl__,
description = __description__,
long_description = __descriptionfull__,
packages = [__packagename__],
cmdclass = cmdclass,