comparison setup.py @ 586:6a718ede8be1

Fix coding style in setup.py.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:27 +0100
parents 78ca32cc0b51
children 21ddafccf32d
comparison
equal deleted inserted replaced
585:9902ec2d8d9b 586:6a718ede8be1
22 from distribute_setup import use_setuptools 22 from distribute_setup import use_setuptools
23 use_setuptools() 23 use_setuptools()
24 from setuptools.command.install import install 24 from setuptools.command.install import install
25 from setuptools import setup 25 from setuptools import setup
26 from distutils.file_util import copy_file 26 from distutils.file_util import copy_file
27 import os,sys,subprocess 27 import os
28 import sys
29 import subprocess
28 from stat import ST_MODE 30 from stat import ST_MODE
29 31
30 NAME = 'sat' 32 NAME = 'sat'
31 LAUNCH_DAEMON_COMMAND = 'sat' 33 LAUNCH_DAEMON_COMMAND = 'sat'
32 34
35
33 class MercurialException(Exception): 36 class MercurialException(Exception):
34 pass 37 pass
38
35 39
36 def module_installed(module_name): 40 def module_installed(module_name):
37 """Try to import module_name, and return False if it failed 41 """Try to import module_name, and return False if it failed
38 @param module_name: name of the module to test 42 @param module_name: name of the module to test
39 @return: True if successful""" 43 @return: True if successful"""
40 try: 44 try:
41 __import__(module_name) 45 __import__(module_name)
42 except: 46 except ImportError:
43 return False 47 return False
44 return True 48 return True
45 49
46 class custom_install(install): 50
47 51 class CustomInstall(install):
52
48 def custom_auto_options(self): 53 def custom_auto_options(self):
49 """Change options for twistd in the shell script 54 """Change options for twistd in the shell script
50 Mainly change the paths""" 55 Mainly change the paths"""
51 sh_buffer = "" 56 sh_buffer = ""
52 run_dir = os.path.dirname(self.sh_script_path) 57 run_dir = os.path.dirname(self.sh_script_path)
53 with open(self.sh_script_path,'r') as sh_file: 58 with open(self.sh_script_path, 'r') as sh_file:
54 for ori_line in sh_file: 59 for ori_line in sh_file:
55 if ori_line.startswith('DAEMON='): 60 if ori_line.startswith('DAEMON='):
56 dest_line = 'DAEMON=""\n' #we want to launch sat as a daemon 61 dest_line = 'DAEMON=""\n' # we want to launch sat as a daemon
57 elif ori_line.startswith('TAP_PATH='): 62 elif ori_line.startswith('TAP_PATH='):
58 dest_line = 'TAP_PATH="%s/"\n' % run_dir 63 dest_line = 'TAP_PATH="%s/"\n' % run_dir
59 elif ori_line.startswith('PYTHON='): 64 elif ori_line.startswith('PYTHON='):
60 dest_line = 'PYTHON="%s"\n' % sys.executable 65 dest_line = 'PYTHON="%s"\n' % sys.executable
61 else: 66 else:
62 dest_line = ori_line 67 dest_line = ori_line
63 sh_buffer += dest_line 68 sh_buffer += dest_line
64 69
65 with open(self.sh_script_path,'w') as sh_file: 70 with open(self.sh_script_path, 'w') as sh_file:
66 sh_file.write(sh_buffer) 71 sh_file.write(sh_buffer)
67 72
68
69 def custom_create_links(self): 73 def custom_create_links(self):
70 """Create symbolic links to executables""" 74 """Create symbolic links to executables"""
71 #the script which launch the daemon 75 # the script which launch the daemon
72 links = [(self.sh_script_path,LAUNCH_DAEMON_COMMAND),] 76 links = [(self.sh_script_path, LAUNCH_DAEMON_COMMAND)]
73 for source,dest in links: 77 for source, dest in links:
74 dest_name, copied = copy_file(source, os.path.join(self.install_scripts, dest), link='sym') 78 dest_name, copied = copy_file(source, os.path.join(self.install_scripts, dest), link='sym')
75 assert (copied) 79 assert (copied)
76 #we change the perm in the same way as in the original install_scripts 80 # we change the perm in the same way as in the original install_scripts
77 mode = ((os.stat(dest_name)[ST_MODE]) | 0555) & 07777 81 mode = ((os.stat(dest_name)[ST_MODE]) | 0555) & 07777
78 os.chmod(dest_name, mode) 82 os.chmod(dest_name, mode)
79 83
80 def run(self): 84 def run(self):
81 install.run(self) 85 install.run(self)
82 sys.stdout.write ('running post installation stuff\n') 86 sys.stdout.write('running post installation stuff\n')
83 sys.stdout.flush() 87 sys.stdout.flush()
84 self.sh_script_path = os.path.join(self.install_lib,'sat','sat.sh') 88 self.sh_script_path = os.path.join(self.install_lib, 'sat', 'sat.sh')
85 self.primitivus_path = os.path.join(self.install_lib,'sat_frontends','primitivus') 89 self.primitivus_path = os.path.join(self.install_lib, 'sat_frontends', 'primitivus')
86 self.custom_auto_options() 90 self.custom_auto_options()
87 self.custom_create_links() 91 self.custom_create_links()
88 92
89 93
90 def preinstall_check(): 94 def preinstall_check():
91 """Check presence of problematic dependencies, and try to install them with package manager 95 """Check presence of problematic dependencies, and try to install them with package manager
92 This ugly stuff is necessary as distributions are not installed correctly with setuptools/distribute 96 This ugly stuff is necessary as distributions are not installed correctly with setuptools/distribute
93 Hope to remove this at some point""" 97 Hope to remove this at some point"""
94 98
95 #modules_tocheck=['twisted', 'twisted.words', 'twisted.web', 'wx', 'urwid'] 99 #modules_tocheck = ['twisted', 'twisted.words', 'twisted.web', 'wx', 'urwid']
96 modules_tocheck=['wx','gobject'] #XXX: wx is the only one to be really difficult to install, python-gobject is not up-to-date in PyPi 100 modules_tocheck = ['wx', 'gobject'] # XXX: wx is the only one to be really difficult to install, python-gobject is not up-to-date in PyPi
97 101
98 package = {'twisted':'python-twisted-core', 102 package = {'twisted': 'python-twisted-core',
99 'twisted.words':'python-twisted-words', 103 'twisted.words': 'python-twisted-words',
100 'twisted.web':'python-twisted-web', 104 'twisted.web': 'python-twisted-web',
101 'wx':'python-wxgtk2.8', 105 'wx': 'python-wxgtk2.8',
102 'urwid':'python-urwid', 106 'urwid': 'python-urwid',
103 'gobject':'python-gobject', 107 'gobject': 'python-gobject',
104 'mercurial':'mercurial'} #this dict map dependencies to packages names for debian distributions 108 'mercurial': 'mercurial'} # this dict map dependencies to packages names for debian distributions
105 109
106 sys.stdout.write ("Running pre-installation dependencies check\n") 110 sys.stdout.write("Running pre-installation dependencies check\n")
107 111
108 #which modules are not installed ? 112 # which modules are not installed ?
109 modules_toinstall = filter(lambda mod:not module_installed(mod),modules_tocheck) 113 modules_toinstall = [mod for mod in modules_tocheck if not module_installed(mod)]
110 """#is mercurial available ? 114 """# is mercurial available ?
111 hg_installed = subprocess.call('which hg', stdout=open('/dev/null', 'w'), shell=True) == 0 115 hg_installed = subprocess.call('which hg', stdout=open('/dev/null', 'w'), shell=True) == 0
112 if not hg_installed: 116 if not hg_installed:
113 modules_toinstall.append('mercurial')""" #hg can be installed from pypi 117 modules_toinstall.append('mercurial')""" # hg can be installed from pypi
114 118
115 if modules_toinstall: 119 if modules_toinstall:
116 #are we on a distribution using apt ? 120 # are we on a distribution using apt ?
117 apt_path = subprocess.Popen('which apt-get', stdout=subprocess.PIPE, shell=True).communicate()[0][:-1] 121 apt_path = subprocess.Popen('which apt-get', stdout=subprocess.PIPE, shell=True).communicate()[0][:-1]
118 not_installed=set() 122 not_installed = set()
119 if apt_path: 123 if apt_path:
120 #we have apt, we'll try to use it 124 # we have apt, we'll try to use it
121 for module_name in modules_toinstall: 125 for module_name in modules_toinstall:
122 package_name = package[module_name] 126 package_name = package[module_name]
123 sys.stdout.write ("Installing %s\n" % package_name) 127 sys.stdout.write("Installing %s\n" % package_name)
124 success = subprocess.call('%s -qy install %s' % (apt_path,package_name), shell=True) == 0 128 success = subprocess.call('%s -qy install %s' % (apt_path, package_name), shell=True) == 0
125 if not success: 129 if not success:
126 not_installed.add(module_name) 130 not_installed.add(module_name)
127 else: 131 else:
128 not_installed=set(modules_toinstall) 132 not_installed = set(modules_toinstall)
129 133
130 if not_installed: 134 if not_installed:
131 #some packages can't be automatically installed, we print their name for manual installation 135 # some packages can't be automatically installed, we print their name for manual installation
132 sys.stdout.write ("You should install the following dependencies with your distribution recommanded tool before installing %s:\n" % NAME) 136 sys.stdout.write("You should install the following dependencies with your distribution recommanded tool before installing %s:\n" % NAME)
133 for module_name in not_installed: 137 for module_name in not_installed:
134 sys.stdout.write ("- %s (Debian name: %s)\n" % (module_name,package[module_name])) 138 sys.stdout.write("- %s (Debian name: %s)\n" % (module_name, package[module_name]))
135 sys.exit(2) 139 sys.exit(2)
136
137 140
138 if sys.argv[1].lower() in ['egg_info','install']: 141
139 #we only check dependencies if egg_info or install is used 142 if sys.argv[1].lower() in ['egg_info', 'install']:
140 install_opt = os.environ.get("SAT_INSTALL","") 143 # we only check dependencies if egg_info or install is used
141 if not "nopreinstall" in install_opt: #user can force preinstall skipping 144 install_opt = os.environ.get("SAT_INSTALL", "")
145 if not "nopreinstall" in install_opt: # user can force preinstall skipping
142 preinstall_check() 146 preinstall_check()
143 147
144 setup(name=NAME, 148 setup(name=NAME,
145 version='0.3.0', 149 version='0.3.0',
146 description=u'Salut à Toi multi-frontend XMPP client', 150 description=u'Salut à Toi multi-frontend XMPP client',
153 'Environment :: X11 Applications :: GTK', 157 'Environment :: X11 Applications :: GTK',
154 'Framework :: Twisted', 158 'Framework :: Twisted',
155 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)', 159 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
156 'Operating System :: POSIX :: Linux', 160 'Operating System :: POSIX :: Linux',
157 'Topic :: Communications :: Chat'], 161 'Topic :: Communications :: Chat'],
158 package_dir = {'sat':'src', 'sat_frontends':'frontends/src'}, 162 package_dir={'sat': 'src', 'sat_frontends': 'frontends/src'},
159 packages=['sat','sat.tools','sat.bridge', 'sat.plugins', 'sat.test', 'sat.core', 'sat.memory', 163 packages=['sat', 'sat.tools', 'sat.bridge', 'sat.plugins', 'sat.test', 'sat.core', 'sat.memory',
160 'sat_frontends', 'sat_frontends.bridge', 'sat_frontends.quick_frontend', 164 'sat_frontends', 'sat_frontends.bridge', 'sat_frontends.quick_frontend',
161 'sat_frontends.primitivus', 'sat_frontends.wix'], 165 'sat_frontends.primitivus', 'sat_frontends.wix'],
162 package_data = {'sat': ['sat.tac','sat.sh'], 166 package_data={'sat': ['sat.tac', 'sat.sh'],
163 'sat_frontends': ['wix/COPYING']}, 167 'sat_frontends': ['wix/COPYING']},
164 data_files=[(os.path.join(sys.prefix,'share/locale/fr/LC_MESSAGES'), ['i18n/fr/LC_MESSAGES/sat.mo']), 168 data_files=[(os.path.join(sys.prefix, 'share/locale/fr/LC_MESSAGES'), ['i18n/fr/LC_MESSAGES/sat.mo']),
165 (os.path.join(sys.prefix,'share/locale/fr/LC_MESSAGES'), ['frontends/i18n/fr/LC_MESSAGES/sat_frontend.mo']), 169 (os.path.join(sys.prefix, 'share/locale/fr/LC_MESSAGES'), ['frontends/i18n/fr/LC_MESSAGES/sat_frontend.mo']),
166 (os.path.join(sys.prefix,'share/locale/fr/LC_MESSAGES'), ['frontends/src/jp/i18n/fr/LC_MESSAGES/jp.mo']), 170 (os.path.join(sys.prefix, 'share/locale/fr/LC_MESSAGES'), ['frontends/src/jp/i18n/fr/LC_MESSAGES/jp.mo']),
167 ('share/doc/%s' % NAME, ['CHANGELOG', 'COPYING', 'INSTALL', 'README', 'README4TRANSLATORS']), 171 ('share/doc/%s' % NAME, ['CHANGELOG', 'COPYING', 'INSTALL', 'README', 'README4TRANSLATORS']),
168 ], 172 ],
169 scripts=['frontends/src/jp/jp', 'frontends/src/primitivus/primitivus', 'frontends/src/wix/wix'], 173 scripts=['frontends/src/jp/jp', 'frontends/src/primitivus/primitivus', 'frontends/src/wix/wix'],
170 zip_safe=False, 174 zip_safe=False,
171 dependency_links = ['http://www.blarg.net/%7Esteveha/pyfeed-0.7.4.tar.gz','http://www.blarg.net/%7Esteveha/xe-0.7.4.tar.gz'], 175 dependency_links=['http://www.blarg.net/%7Esteveha/pyfeed-0.7.4.tar.gz', 'http://www.blarg.net/%7Esteveha/xe-0.7.4.tar.gz'],
172 install_requires=['twisted', 'wokkel', 'progressbar', 'urwid', 'urwid-satext','pyfeed','xe', 'mutagen'], 176 install_requires=['twisted', 'wokkel', 'progressbar', 'urwid', 'urwid-satext', 'pyfeed', 'xe', 'mutagen'],
173 cmdclass=dict(install=custom_install), 177 cmdclass={'install': CustomInstall},
174 ) #XXX: wxpython doesn't work, it's managed with preinstall_check 178 ) # XXX: wxpython doesn't work, it's managed with preinstall_check
175