This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
executable file
·105 lines (85 loc) · 3.32 KB
/
setup.py
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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from distutils.core import setup
from distutils.command.build import build
from distutils.command.install_data import install_data
from distutils.command.install import install
from distutils.dist import Distribution
from xml.dom import minidom
from distutils.log import error, info, warn
import sys
import glob
import subprocess
import shutil
import os
appname = "subget"
w = open("usr/share/"+appname+"/version.xml", "r")
contents = w.read()
w.close()
dom = minidom.parseString(contents)
VERSION = str(dom.getElementsByTagName('version').item(0).firstChild.data)
class Dist(Distribution):
""" Additional commandline arguments """
global_options = Distribution.global_options + [
("without-gettext", None, "Don't build/install gettext .mo files")]
def __init__ (self, *args):
self.without_gettext = False
Distribution.__init__(self, *args)
class BuildData(build):
def run(self):
build.run(self)
# don't build languages if --without-gettext was specified in commandline
if self.distribution.without_gettext: return
languages = glob.glob("usr/share/"+appname+"/locale/*/*/*.po")
for k in languages:
try:
mo = k.replace("-src", "")[:-3]
rc = subprocess.call(['msgfmt', '-o', mo+".mo", k])
if rc != 0: raise Warning, "msgfmt returned %d" % rc
info("msgfmt -o "+mo+".mo "+k)
except Exception as e:
error("Building gettext files failed. Try setup.py --without-gettext [build|install]")
error("Error: %s" % str(e))
sys.exit(1)
class Install(install):
def run(self):
shutil.copyfile("subget.py", "/tmp/subget") # small trick to cut off ".py" extension
shutil.copyfile("subget-translator.py", "/tmp/subget-translator")
self.distribution.scripts=['/tmp/subget', '/tmp/subget-translator']
install.run(self)
os.remove("/tmp/subget-translator")
class InstallData(install_data):
def run(self):
files = self.listDirs("usr")
self.data_files.extend(files)
install_data.run(self)
warn("If application wont run try: ln -s /usr/local/share/subget/ /usr/share/subget")
def listDirs(self, directory):
# Source: http://mayankjohri.wordpress.com/2008/07/02/create-list-of-files-in-a-dir-tree/
fileList = []
for root, subFolders, files in os.walk(directory):
a = []
file = None
for file in files:
f = os.path.join(root,file)
a.append(f)
if file is not None:
fileList.append((root[4:],a))
return fileList
setup(name='subget',
description = "Simple subtitles downloading program",
long_description = "Subget is an application that supports downloading from many subtitles servers, plugins, multiplatform and international languages.",
author = "Damian Kęska",
author_email = "[email protected]",
version=VERSION,
license = "GPL",
package_dir={'': 'src'},
packages=['subgetlib', 'subgetcore'],
distclass=Dist,
data_files = [],
cmdclass={
'build': BuildData,
'install_data': InstallData,
'install': Install
}
)