Академический Документы
Профессиональный Документы
Культура Документы
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
Examples:
Windows::
Linux::
Requirements:
Notes:
If you get 'TypeError: decoding Unicode is not supported' when you run
py2exe then apply the following patch::
http://sourceforge.net/p/py2exe/patches/28/
"""
Página 1
setup
import os
import sys
import glob
from shutil import copyfile
from subprocess import call
if PY2EXE:
try:
import py2exe
except ImportError as error:
print(error)
sys.exit(1)
def on_windows():
"""Returns True if OS is Windows."""
return os.name == "nt"
class BuildBin(cmd.Command):
def initialize_options(self):
self.scripts_dir = None
def finalize_options(self):
self.scripts_dir = os.path.join("build", "_scripts")
Página 2
setup
def run(self):
if not os.path.exists(self.scripts_dir):
os.makedirs(self.scripts_dir)
copyfile(os.path.join(__packagename__, "__main__.py"),
os.path.join(self.scripts_dir, "youtube-dl-gui"))
class BuildTranslations(cmd.Command):
def initialize_options(self):
self.exec_name = None
self.search_pattern = None
def finalize_options(self):
if on_windows():
self.exec_name = "msgfmt.exe"
else:
self.exec_name = "msgfmt"
def run(self):
for po_file in glob.glob(self.search_pattern):
mo_file = po_file.replace(".po", ".mo")
try:
log.info("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))
sys.exit(1)
class Build(build):
sub_commands = [
("build_bin", None),
("build_trans", None)
] + build.sub_commands
def initialize_options(self):
Página 3
setup
build.initialize_options(self)
self.no_updates = None
def run(self):
build.run(self)
if self.no_updates:
self.__disable_updates()
def __disable_updates(self):
lib_dir = os.path.join(self.build_lib, __packagename__)
target_file = "optionsmanager.py"
if data is None:
log.error("building with updates disabled failed!")
sys.exit(1)
# Overwrite cmds
cmdclass = {
"build": Build,
"build_bin": BuildBin,
"build_trans": BuildTranslations
}
def linux_setup():
scripts = []
data_files = []
package_data = {}
dst = "share/icons/hicolor/{size}/apps".format(size=size)
Página 4
setup
src = "{icon_path}/apps/youtube-dl-gui.png".format(icon_path=path)
data_files.append((dst, [src]))
# Add scripts
scripts.append("build/_scripts/youtube-dl-gui")
setup_params = {
"scripts": scripts,
"data_files": data_files,
"package_data": package_data
}
return setup_params
def windows_setup():
def normal_setup():
package_data = {}
setup_params = {
"package_data": package_data
}
return setup_params
def py2exe_setup():
windows = []
data_files = []
Página 5
setup
# py2exe dependencies & options
# TODO change directory for ffmpeg.exe & ffprobe.exe
dependencies = [
"C:\\Windows\\System32\\ffmpeg.exe",
"C:\\Windows\\System32\\ffprobe.exe",
"C:\\python27\\DLLs\\MSVCP90.dll"
]
options = {
"includes": ["wx.lib.pubsub.*",
"wx.lib.pubsub.core.*",
"wx.lib.pubsub.core.arg1.*"]
}
#############################################
data_files.append((dst, [src]))
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()
Página 6
setup
else:
params = linux_setup()
setup(
author = __author__,
name = __appname__,
version = __version__,
license = __license__,
author_email = __contact__,
url = __projecturl__,
description = __description__,
long_description = __descriptionfull__,
packages = [__packagename__],
cmdclass = cmdclass,
**params
)
Página 7