Browse Source

Refactor setup.py

Also, fix Windows setup icons problem
were you had to copy icons manually
doc-issue-template
MrS0m30n3 10 years ago
parent
commit
d28d67c3b0
1 changed files with 72 additions and 63 deletions
  1. 135
      setup.py

135
setup.py

@ -5,14 +5,15 @@ import sys
PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == 'py2exe'
try:
import py2exe
except ImportError as e:
if PY2EXE:
print e
if PY2EXE:
try:
import py2exe
except ImportError as error:
print error
sys.exit(1)
from distutils.core import setup
from distutils.sysconfig import get_python_lib
from youtube_dl_gui import (
__author__,
@ -25,83 +26,91 @@ from youtube_dl_gui import (
__descriptionfull__
)
ICONS_SIZE = ('16x16', '32x32', '48x48', '64x64', '128x128', '256x256')
ICONS_NAME = 'youtube_dl_gui/icons/youtube-dl-gui_%s.png'
ICONS_LIST = [ICONS_NAME % size for size in ICONS_SIZE]
ICONS_SIZES = ('16x16', '32x32', '48x48', '64x64', '128x128', '256x256')
ICONS_TEMPLATE = 'youtube_dl_gui/icons/youtube-dl-gui_{size}.png'
py2exe_includes = [
'wx.lib.pubsub.*',
'wx.lib.pubsub.core.*',
'wx.lib.pubsub.core.arg1.*'
]
ICONS_LIST = [ICONS_TEMPLATE.format(size=size) for size in ICONS_SIZES]
py2exe_options = {
'includes': py2exe_includes
}
# Set icons path
PY2EXE_ICONS = 'icons'
WINDOWS_ICONS = os.path.join(get_python_lib(), 'youtube_dl_gui', 'icons')
LINUX_ICONS = '/usr/share/icons/hicolor/'
py2exe_windows = {
'script': 'youtube_dl_gui\\__main__.py',
'icon_resources': [(0, 'youtube_dl_gui\\icons\\youtube-dl-gui.ico')]
}
LINUX_FALLBACK_ICONS = '/usr/share/pixmaps/'
py2exe_dependencies = [
'C:\\Windows\\System32\\ffmpeg.exe',
'C:\\Windows\\System32\\ffprobe.exe',
'C:\\python27\\DLLs\MSVCP90.dll'
]
# Set icons path
if PY2EXE:
icons_path = 'icons'
fallback_icons_path = ''
else:
# On windows you have to copy the icons manually if you dont use py2exe
icons_path = '/usr/share/icons/hicolor/'
fallback_icons_path = '/usr/share/pixmaps/'
def py2exe_setup():
py2exe_dependencies = [
'C:\\Windows\\System32\\ffmpeg.exe',
'C:\\Windows\\System32\\ffprobe.exe',
'C:\\python27\\DLLs\\MSVCP90.dll'
]
# Set params
if PY2EXE:
data_files = [
py2exe_data_files = [
('', py2exe_dependencies),
(icons_path, ICONS_LIST)
(PY2EXE_ICONS, ICONS_LIST)
]
py2exe_options = {
'includes': ['wx.lib.pubsub.*',
'wx.lib.pubsub.core.*',
'wx.lib.pubsub.core.arg1.*']
}
py2exe_windows = {
'script': 'youtube_dl_gui\\__main__.py',
'icon_resources': [(0, 'youtube_dl_gui\\icons\\youtube-dl-gui.ico')]
}
params = {
'data_files': data_files,
'data_files': py2exe_data_files,
'windows': [py2exe_windows],
'options': {'py2exe': py2exe_options}
}
else:
data_files = []
if os.name != 'nt':
return params
def normal_setup():
data_files = list()
if os.name == 'nt':
icons_dir = (WINDOWS_ICONS, ICONS_LIST)
data_files.append(icons_dir)
else:
# Create all the hicolor icons
for index, size in enumerate(ICONS_SIZE):
data_file = (icons_path + size + '/apps', [ICONS_LIST[index]])
data_files.append(data_file)
for index, size in enumerate(ICONS_SIZES):
icons_dest = os.path.join(LINUX_ICONS, size, 'apps')
icons_dir = (icons_dest, [ICONS_LIST[index]])
data_files.append(icons_dir)
if fallback_icons_path != '':
# Add the 48x48 icon as fallback in /usr/share/pixmaps
data_file = (fallback_icons_path, [ICONS_LIST[2]])
data_files.append(data_file)
# Add the 48x48 icon as fallback
fallback_icon = (LINUX_FALLBACK_ICONS, [ICONS_LIST[2]])
data_files.append(fallback_icon)
params = {'data_files': data_files}
return params
if PY2EXE:
params = py2exe_setup()
else:
params = normal_setup()
params = {
'data_files': data_files
}
setup(
name=__appname__,
author=__author__,
url=__projecturl__,
version=__version__,
license=__license__,
author_email=__contact__,
description=__description__,
long_description=__descriptionfull__,
packages=['youtube_dl_gui'],
author = __author__,
name = __appname__,
version = __version__,
license = __license__,
author_email = __contact__,
url = __projecturl__,
description = __description__,
long_description = __descriptionfull__,
packages = ['youtube_dl_gui'],
**params
)
Loading…
Cancel
Save