1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
# -*- coding: utf-8 -*-
# Useful guide: http://docs.python.org/distutils/builtdist.html
# setup.py --help
"""
Required PyGTK:
You can download PyGTK 2.16 (lastest for now) from:
http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.16/pygtk-2.16.0.win32-py2.6.exe
PyObject:
http://ftp.gnome.org/pub/GNOME/binaries/win32/pygobject/2.20/pygobject-2.20.0.win32-py2.6.exe
Commandline for Windows (from root folder of project):
python setup.py bdist_wininst --bitmap src/data/img/tivion.bmp --title "Tivion: A simple streaming player" --dist-dir dist/windows/
python setup.py bdist_wininst --bitmap src/data/img/tivion.bmp --title "Tivion: A simple streaming player" --dist-dir dist/windows/ --install-script=src/tivion_postinstall.py --user-access-control force --target-version 2.6 -p win32
python setup.py bdist_wininst --bitmap src/data/img/tivion.bmp --title "Tivion: A simple streaming player" --dist-dir dist/windows/ --install-script=src/tivion_postinstall.py --user-access-control force --target-version 2.6 -p win-amd64
python setup.py bdist_wininst --bitmap src/data/img/tivion.bmp --title "Tivion: A simple streaming player" --dist-dir dist/windows/ --install-script=src/tivion_postinstall.py --user-access-control force --target-version 2.6 -p win-ia64
For debug:
set DISTUTILS_DEBUG=True
"""
import platform
import distutils
import distutils.file_util
import distutils.sysconfig
if platform.system() == 'Windows':
import distutils.command.bdist_msi
from distutils.command.build import show_compilers
from distutils.core import setup
from distutils.command.install_data import install_data
from distutils.command.install_lib import install_lib
from distutils.command.bdist_wininst import bdist_wininst
from distutils.sysconfig import get_python_lib
import sys
if sys.version_info[:3] < (2, 6, 0):
raise SystemExit, \
"Python 2.6.0 or higher is required, %d.%d.%d found" % sys.version_info[:3]
try:
import gtk
except:
print 'You need install GTK to run Tivion.'
sys.exit(1)
gtk_v = gtk.gtk_version
if gtk_v < (2, 14):
print 'You need GTK 2.14 or higher to run Tivion.'
sys.exit(1)
try:
import pygtk
except:
print 'You need install PyGTK to run Tivion.'
sys.exit(1)
pygtk.require('2.0')
pygtk_v = gtk.pygtk_version
if pygtk_v < (2, 14):
print 'You need PyGTK 2.14 or higher to run Tivion.'
sys.exit(1)
class post_install(install_data):
def run(self):
print '=== Post install script ==='
install_cmd = self.get_finalized_command('install')
print 'Install dir:', getattr(install_cmd, 'install_lib')
#self.install_dir = getattr(install_cmd, 'install_lib')
install_data.run(self) # Call parent
# Execute commands
print
class post_install_lib(install_lib):
def run(self):
print '=== Post install lib script ==='
install_lib.run(self)
print
class pre_bdist_wininst(bdist_wininst):
#def get_inidata(self):
#return bdist_wininst.get_inidata(bdist_wininst) + 'Hola'
#return super(pre_bdist_wininst, self)
#.get_inidata() + 'TODO'
def run(self):
#[TODO] Make a translation for the installer and fix some
# variables name like author_email
print '=== Pre bdist_wininst script ==='
#print self.get_inidata()
#print dir(bdist_wininst)
#print self.get_inidata()
bdist_wininst.run(self)
print
#get_inidata
class post_bdist_wininst(bdist_wininst):
def run(self):
print '=== Post bdist_wininst script ==='
bdist_wininst.run(self)
print
#import _winreg
#import win32api
#import win32security
# patch distutils if it can't cope with the "classifiers" or
# "download_url" keywords
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8') # For spanish characters
from sys import version
if version < '2.2.3':
try:
# add necessary to distutils (for backwards compatibility)
from distutils.dist import DistributionMetadata
DistributionMetadata.classifiers = None
DistributionMetadata.download_url = None
DistributionMetadata.platforms = None
except:
pass
# Get current Python version
python_version = platform.python_version_tuple()
# Setup the default install prefix
prefix = sys.prefix
# Check our python is version 2.6 or higher
if python_version[0] >= 2 and python_version[1] >= 6:
## Set file location prefix accordingly
prefix = '/usr/local'
# Get the install prefix if one is specified from the command line
for arg in sys.argv:
if arg.startswith('--prefix='):
prefix = arg[9:]
prefix = os.path.expandvars(prefix)
"""if arg.startswith('bdist_wininst'): # bdist_wise
#[TODO]Put windows path here
if arg.startswith('bdist_rpm'):
#[TODO]Put fedora path here"""
if platform.system() == 'Windows':
import src.constants as cons
else:
VERSION = 'Tivion 0.0.4'
print '=== Installer for', VERSION, '==='
print 'Plataform:', distutils.util.get_platform()
lib_dir = get_python_lib(plat_specific = 1)
print 'Lib dir:', lib_dir
print show_compilers()
print
"""
try:
prg = get_special_folder_path("CSIDL_COMMON_PROGRAMS")
except OSError:
try:
prg = get_special_folder_path("CSIDL_PROGRAMS")
except OSError, reason:
# give up - cannot install shortcuts
print "cannot install shortcuts: %s" % reason
sys.exit()
print "PRG", prg
"""
files = ['src/data/*']
#ValueError: path 'src/' cannot end with '/'
if platform.system() == 'Windows':
scripts_data = None #['src/tivion.py']
else:
scripts_data = ['src/tivion']
if platform.system() == 'Windows':
author_data = unicode('Ángel Guzmán Maeso')
else:
author_data = 'Ángel Guzmán Maeso'
if platform.system() == 'Windows':
usr_share = os.path.join('usr', 'share')#\\usr\\share\\'
else:
usr_share = '/usr/share/'
if platform.system() == 'Windows':
sep = os.sep
src_dir = 'src' + os.sep
img_dir = 'data\\img\\'
lang_dir = '\\usr\\share\\locale'
tivion_install_path = os.environ['HOMEDRIVE'] + sep + os.environ['PROGRAMFILES'] + '\\' + cons.VERSION_NAME+ '\\'
#loptions = {'bdist_wininst': {'install_script': src_dir + 'pygtk_postinstall.py'}}
#loptions = [{"bdist_wininst": {"install_script": "pygtk_postinstall.py"}}]
#scripts = [src_dir + 'postinstall.py'],
else:
sep = os.sep
src_dir = 'src/'
img_dir = 'data/img/'
lang_dir = '/usr/share/locale'
tivion_install_path = '/usr/share/tivion/'
#loptions = []
#scripts = []
"""
path = os.path.join(tivion_install_path, "Tivion.lnk")
arguments = os.path.join(lib_dir, "Tivion\\layoutEditor.py")
create_shortcut(pythonw, "Layout Editor", path, tivion_install_path + 'tivion.py')
file_created(path)
"""
"""
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut("t:\\test.lnk")
shortcut.Targetpath = "t:\\ftemp"
shortcut.save()
"""
data_files_installed = [
## Installing the executable
(tivion_install_path, [src_dir + 'tivion.py']),
## Installing the channels, constants, utils and countries module
(tivion_install_path, [src_dir + 'channels.py']),
(tivion_install_path, [src_dir + 'constants.py']),
(tivion_install_path, [src_dir + 'countries.py']),
(tivion_install_path, [src_dir + 'utils.py']),
## Installing the data files (logo and images)
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion-icon.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion-icon.svg']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion-launcher.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion-frame.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'all.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'media-playback-start.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'pause_bg.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'play_bg.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'radio.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'sopcast.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tv.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'camera-photo.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'audio-volume-muted.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'audio-volume-high.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'audio-volume-low.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'audio-volume-medium.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'lpi-help.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'lpi-translate.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'lpi-bug.png']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion.bmp']),
(tivion_install_path + img_dir, [src_dir + img_dir + 'tivion.xcf']),
## Installing the locale files
# Catala
(lang_dir + sep + 'ca' + sep + 'LC_MESSAGES' + sep,
[src_dir + 'lang' + sep + 'ca' + sep + 'LC_MESSAGES' + sep + 'tivion.po']),
(lang_dir + sep + 'ca' + sep + 'LC_MESSAGES' + sep,
[src_dir + 'lang' + sep + 'ca' + sep + 'LC_MESSAGES' + sep + 'tivion.mo'])
]
if platform.system() == 'Windows':
data_files_installed.append((tivion_install_path, [src_dir + 'bin//mplayer.exe']))
data_files_installed.append((tivion_install_path, [src_dir + 'Tivion.lnk']))
data_files_installed.append((os.environ['HOMEDRIVE'] + os.sep + os.environ['HOMEPATH'] + os.sep + 'Desktop', [src_dir + 'Tivion.lnk']))
data_files_installed.append((os.environ['HOMEDRIVE'] + os.sep + os.environ['HOMEPATH'] + os.sep + 'Escritorio', [src_dir + 'Tivion.lnk']))
setup(name = 'tivion',
version = '0.0.4',
description = 'A simple player to online TV streaming',
long_description = 'A simple player and recorder for streaming online television and radio \nchannels composed of multicultural and international level.',
author = author_data,
author_email = 'shakaran@gmail.com',
maintainer = 'Ángel Guzmán Maeso',
maintainer_email = 'shakaran@gmail.com',
url = 'http://www.shakaran.es',
download_url = 'http://www.shakaran.net/blog/tivion',
packages = [''],
package_data = {'' : ''}, # files
#scripts = scripts,
license = 'GNU GPL Version 3', #,
platforms = 'Python 2.6.0 and later',
data_files = data_files_installed,
py_modules=[],
scripts=[src_dir + 'tivion_postinstall.py'],
cmdclass={'install_data': post_install,
'install_lib': post_install_lib,
'bdist_wininst': pre_bdist_wininst,
'install_script': post_bdist_wininst}#,
#options = loptions
)
"""
[TODO]
# English
('src/lang/', ['/usr/share/locale/en/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/en/LC_MESSAGES/tivion.mo']),
# English (United Kingdom)
('src/lang/', ['/usr/share/locale/en_GB/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/en_GB/LC_MESSAGES/tivion.mo']),
# Spanish
('src/lang/', ['/usr/share/locale/es/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/es/LC_MESSAGES/tivion.mo']),
# French
('src/lang/', ['/usr/share/locale/fr/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/fr/LC_MESSAGES/tivion.mo']),
# Italian
('src/lang/', ['/usr/share/locale/it/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/it/LC_MESSAGES/tivion.mo']),
# Portuguese
('src/lang/', ['/usr/share/locale/pt/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/pt/LC_MESSAGES/tivion.mo']),
# Russian
('src/lang/', ['/usr/share/locale/ru/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/ru/LC_MESSAGES/tivion.mo']),
# Turkish
('src/lang/', ['/usr/share/locale/tr/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/tr/LC_MESSAGES/tivion.mo']),
# Italian
('src/lang/', ['/usr/share/locale/it/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/it/LC_MESSAGES/tivion.mo']),
# Portuguese
('src/lang/', ['/usr/share/locale/pt/LC_MESSAGES/tivion.po']),
('src/lang/', ['/usr/share/locale/pt/LC_MESSAGES/tivion.mo']),
# Russian
('/usr/share/locale/ru/LC_MESSAGES/', ['src/lang/ru/LC_MESSAGES/tivion.po']),
('/usr/share/locale/ru/LC_MESSAGES/', ['src/lang/ru/LC_MESSAGES/tivion.mo']),
# Afrikaans
('/usr/share/locale/af/LC_MESSAGES/', ['src/lang/af/LC_MESSAGES/tivion.po']),
('/usr/share/locale/af/LC_MESSAGES/', ['src/lang/af/LC_MESSAGES/tivion.mo']),
# Aragonese
('/usr/share/locale/an/LC_MESSAGES/', ['src/lang/an/LC_MESSAGES/tivion.po']),
('/usr/share/locale/an/LC_MESSAGES/', ['src/lang/an/LC_MESSAGES/tivion.mo']),
# Arabic
('/usr/share/locale/ar/LC_MESSAGES/', ['src/lang/ar/LC_MESSAGES/tivion.po']),
('/usr/share/locale/ar/LC_MESSAGES/', ['src/lang/ar/LC_MESSAGES/tivion.mo']),
# Bosnian
('/usr/share/locale/bs/LC_MESSAGES/', ['src/lang/bs/LC_MESSAGES/tivion.po']),
('/usr/share/locale/bs/LC_MESSAGES/', ['src/lang/bs/LC_MESSAGES/tivion.mo']),
# Greek
('/usr/share/locale/el/LC_MESSAGES/', ['src/lang/el/LC_MESSAGES/tivion.po']),
('/usr/share/locale/el/LC_MESSAGES/', ['src/lang/el/LC_MESSAGES/tivion.mo']),
# English (Australia)
('/usr/share/locale/en_AU/LC_MESSAGES/', ['src/lang/en_AU/LC_MESSAGES/tivion.po']),
('/usr/share/locale/en_AU/LC_MESSAGES/', ['src/lang/en_AU/LC_MESSAGES/tivion.mo']),
# Basque
('/usr/share/locale/eu/LC_MESSAGES/', ['src/lang/eu/LC_MESSAGES/tivion.po']),
('/usr/share/locale/eu/LC_MESSAGES/', ['src/lang/eu/LC_MESSAGES/tivion.mo']),
# Albanian
('/usr/share/locale/sq/LC_MESSAGES/', ['src/lang/sq/LC_MESSAGES/tivion.po']),
('/usr/share/locale/sq/LC_MESSAGES/', ['src/lang/sq/LC_MESSAGES/tivion.mo']),
# Klingon
('/usr/share/locale/tlh/LC_MESSAGES/', ['src/lang/tlh/LC_MESSAGES/tivion.po']),
('/usr/share/locale/tlh/LC_MESSAGES/', ['src/lang/tlh/LC_MESSAGES/tivion.mo']),
# Chinese (Traditional)
('/usr/share/locale/zh_TW/LC_MESSAGES/', ['src/lang/zh_TW/LC_MESSAGES/tivion.po']),
('/usr/share/locale/zh_TW/LC_MESSAGES/', ['src/lang/tlh/LC_MESSAGES/tivion.mo']),
# German
('/usr/share/locale/de/LC_MESSAGES/', ['src/lang/de/LC_MESSAGES/tivion.po']),
('/usr/share/locale/de/LC_MESSAGES/', ['src/lang/de/LC_MESSAGES/tivion.mo']),
# Galician
('/usr/share/locale/gl/LC_MESSAGES/', ['src/lang/gl/LC_MESSAGES/tivion.po']),
('/usr/share/locale/gl/LC_MESSAGES/', ['src/lang/gl/LC_MESSAGES/tivion.mo']),
# Croatian
('/usr/share/locale/hr/LC_MESSAGES/', ['src/lang/hr/LC_MESSAGES/tivion.po']),
('/usr/share/locale/hr/LC_MESSAGES/', ['src/lang/hr/LC_MESSAGES/tivion.mo']),
# Indonesian
('/usr/share/locale/id/LC_MESSAGES/', ['src/lang/id/LC_MESSAGES/tivion.po']),
('/usr/share/locale/id/LC_MESSAGES/', ['src/lang/id/LC_MESSAGES/tivion.mo']),
## Installing menufile
('src/', ['/usr/share/applications/tivion.desktop']),
## Readme and documentation files
#('.', ['/usr/share/doc/tivion/README']),
],
"""
#"""[TODO]data_files=[('/usr/share/tivion/', ['bm/b1.gif', 'bm/b2.gif']),
# ('config', ['cfg/data.cfg']),
# ('/etc/init.d', ['init-script'])],"""
#platforms = ['Linux'],
#scripts = ["runner"],
#cmdclass={'install': InstallAndUpdate},
#
#windows = ["tivion.py"],
#options = {"py2exe": {"bundle_files": 1}},
#
#scripts = scripts_data,
#"""classifiers = [
# 'Development Status :: 1 - Alpha',
# 'Environment :: Console',
# 'Environment :: Web Environment',
# 'Intended Audience :: End Users/Desktop',
# 'Intended Audience :: Developers',
# 'Intended Audience :: System Administrators',
# 'License :: OSI Approved :: GNU Public Licence Version 3',
# 'Operating System :: Linux :: Ubuntu 9.04',
# 'Operating System :: Linux :: Ubuntu 9.10',
# 'Operating System :: Linux :: Ubuntu 10.04',
# #'Operating System :: Microsoft :: Windows', # Not yet
# #'Operating System :: MacOS :: MacOS X', # Not yet
# 'Programming Language :: Python',
# 'Topic :: Internet :: Media',
# 'Topic :: Internet :: Sound & Video',
# 'Topic :: Multimedia :: Graphics :: Viewers',
# ],"""
|