comparison setup.py @ 235:7a2ef5fe4e8d

distutils: added preinstall_check hack + some tuning while testing
author Goffi <goffi@goffi.org>
date Fri, 07 Jan 2011 03:47:24 +0100
parents 6a37bc1b0b8c
children aae816738314
comparison
equal deleted inserted replaced
234:a7079e835432 235:7a2ef5fe4e8d
13 NAME = 'sat' 13 NAME = 'sat'
14 LAUNCH_DAEMON_COMMAND = 'sat' 14 LAUNCH_DAEMON_COMMAND = 'sat'
15 15
16 class MercurialException(Exception): 16 class MercurialException(Exception):
17 pass 17 pass
18
19 def module_installed(module_name):
20 """Try to import muc from custom wokkel build
21 @param module_name: name of the module to test
22 @return: True if successful"""
23 try:
24 __import__(module_name)
25 except:
26 return False
27 return True
18 28
19 class custom_install(install): 29 class custom_install(install):
20 30
21 def custom_auto_options(self): 31 def custom_auto_options(self):
22 """Change options for twistd in the shell script 32 """Change options for twistd in the shell script
46 assert (copied) 56 assert (copied)
47 #we change the perm in the same way as in the original install_scripts 57 #we change the perm in the same way as in the original install_scripts
48 mode = ((os.stat(dest_name)[ST_MODE]) | 0555) & 07777 58 mode = ((os.stat(dest_name)[ST_MODE]) | 0555) & 07777
49 os.chmod(dest_name, mode) 59 os.chmod(dest_name, mode)
50 60
51 def _custom_wokkel_installed(self):
52 """Try to import muc from custom wokkel build
53 @return: True if successful"""
54 try:
55 __import__('wokkel.muc')
56 except:
57 return False
58 return True
59 61
60 def custom_wokkel_requirement(self): 62 def custom_wokkel_requirement(self):
61 """Test if the custom wokkel is present, else get and build it""" 63 """Test if the custom wokkel is present, else get and build it"""
62 if not self._custom_wokkel_installed(): 64 if not module_installed('wokkel.muc'):
63 print ('Custom wokkel is not present, building it') 65 sys.stdout.write ('Custom wokkel is not present, building it\n')
64 import tempfile 66 import tempfile
65 ori_path = os.getcwd() 67 ori_path = os.getcwd()
66 work_path = tempfile.mkdtemp() 68 work_path = tempfile.mkdtemp()
67 os.chdir(work_path) 69 os.chdir(work_path)
70 hg_path = subprocess.Popen('which hg', stdout=subprocess.PIPE, shell=True).communicate()[0][:-1]
68 #we are now in a temp dir, we can get the repositories 71 #we are now in a temp dir, we can get the repositories
69 commands = ['/usr/bin/hg clone http://hg.ik.nu/wokkel wokkel', 72 commands = ['%s clone http://hg.ik.nu/wokkel wokkel' % hg_path,
70 'cd wokkel', 73 'cd wokkel',
71 '/usr/bin/hg pull -f http://hg.ik.nu/ralphm/wokkel-muc-client-support-24-2', 74 '%s pull -f http://hg.ik.nu/ralphm/wokkel-muc-client-support-24-2' % hg_path,
72 '/usr/bin/hg merge wokkel-muc-client-support-24', 75 '%s merge wokkel-muc-client-support-24' % hg_path,
73 '/usr/bin/hg commit -m "Merged wokkel\'s MUC branch"', 76 '%s commit -u "SàT installation script" -m "Merged wokkel\'s MUC branch"' % hg_path,
74 '%s setup.py install' % sys.executable] 77 '%s setup.py install' % sys.executable]
75 for command in commands: 78 for command in commands:
76 if command.startswith('cd '): 79 if command.startswith('cd '):
77 os.chdir(command[3:]) 80 os.chdir(command[3:])
78 else: 81 else:
79 ret = subprocess.call(command, stdout=open('/dev/null', 'w'), shell=True) 82 ret = subprocess.call(command, stdout=open('/dev/null', 'w'), shell=True)
80 if ret!=0: 83 if ret!=0:
81 os.chdir(ori_path) 84 os.chdir(ori_path)
82 print ("ERROR while building/installing custom wokkel") 85 sys.stderr.write ("ERROR while building/installing custom wokkel\n")
83 print ('Error happened when executing [%s]' % command) 86 sys.stderr.write ('Error happened when executing [%s]\n' % command)
84 print ('tmpdir is [%s]' % work_path) 87 sys.stderr.write ('tmpdir is [%s]\n' % work_path)
85 raise MercurialException 88 raise MercurialException
86 os.chdir(ori_path) 89 os.chdir(ori_path)
87 print "Custom wokkel builded and installed, removing temporary files" 90 sys.stdout.write ("Custom wokkel builded and installed, removing temporary files\n")
88 import shutil 91 import shutil
89 shutil.rmtree(work_path) 92 shutil.rmtree(work_path)
90 print "done" 93 sys.stdout.write ("done\n")
91 else: 94 else:
92 print "Custom wokkel already installed" 95 sys.stdout.write ("Custom wokkel already installed\n")
93 96
94 97
95 def run(self): 98 def run(self):
96 install.run(self) 99 install.run(self)
97 print ('running post installation stuff') 100 sys.stdout.write ('running post installation stuff\n')
98 self.sh_script_path = os.path.join(self.install_lib,'sat','sat.sh') 101 self.sh_script_path = os.path.join(self.install_lib,'sat','sat.sh')
99 self.primitivus_path = os.path.join(self.install_lib,'sat_frontends','primitivus') 102 self.primitivus_path = os.path.join(self.install_lib,'sat_frontends','primitivus')
100 self.custom_auto_options() 103 self.custom_auto_options()
101 self.custom_create_links() 104 self.custom_create_links()
102 self.custom_wokkel_requirement() 105 self.custom_wokkel_requirement()
103 106
104 107
108 def preinstall_check():
109 """Check presence of problematic dependencies, and try to install them with package manager
110 This ugly stuff is necessary as distributions are not installed correctly with setuptools/distribute
111 Hope to remove this at some point"""
112
113 #modules_tocheck=['twisted', 'twisted.words', 'twisted.web', 'wx', 'urwid']
114 modules_tocheck=['wx'] #XXX: wx is the only one to really difficult to install
115
116 package = {'twisted':'python-twisted-core',
117 'twisted.words':'python-twisted-words',
118 'twisted.web':'python-twisted-web',
119 'wx':'python-wxgtk2.8',
120 'urwid':'python-urwid',
121 'mercurial':'mercurial'} #this dict map dependencies to packages names for debian distributions
122
123 sys.stdout.write ("Running pre-installation dependencies check\n")
124
125 #which modules are not installed ?
126 modules_toinstall = filter(lambda mod:not module_installed(mod),modules_tocheck)
127 """#is mercurial available ?
128 hg_installed = subprocess.call('which hg', stdout=open('/dev/null', 'w'), shell=True) == 0
129 if not hg_installed:
130 modules_toinstall.append('mercurial')""" #hg can be installed from pypi
131
132 if modules_toinstall:
133 #are we on a distribution using apt ?
134 apt_path = subprocess.Popen('which apt-get', stdout=subprocess.PIPE, shell=True).communicate()[0][:-1]
135 not_installed=set()
136 if apt_path:
137 #we have apt, we'll try to use it
138 for module_name in modules_toinstall:
139 package_name = package[module_name]
140 sys.stdout.write ("Installing %s\n" % package_name)
141 success = subprocess.call('%s -qy install %s' % (apt_path,package_name), shell=True) == 0
142 if not success:
143 not_installed.add(module_name)
144 else:
145 not_installed=set(modules_toinstall)
146
147 if not_installed:
148 #some packages can't be automatically installed, we sys.stdout.write their name for manual installation
149 sys.stdout.write ("You should install the following dependencies with your distribution recommanded tool before installing %s:\n" % NAME)
150 for module_name in not_installed:
151 sys.stdout.write ("- %s (Debian name: %s)\n" % (module_name,package[module_name]))
152 sys.exit(2)
153
154
155 if sys.argv[1].lower() in ['egg_info','install']:
156 #we only check dependencies in egg_info or install is used
157 preinstall_check()
105 158
106 setup(name=NAME, 159 setup(name=NAME,
107 version='0.1.0', 160 version='0.1.0',
108 description=u'Salut à Toi multi-frontend XMPP client', 161 description=u'Salut à Toi multi-frontend XMPP client',
109 long_description=u'Salut à Toi (SàT) is a XMPP client based on a daemon/frontend architecture. You can use it with the desktop frontend (wix - WxPython based), console ui frontend (Primitivus, Urwid based), or command line frontend (jp), and others are coming. ', 162 long_description=u'Salut à Toi (SàT) is a XMPP client based on a daemon/frontend architecture. You can use it with the desktop frontend (wix - WxPython based), console ui frontend (Primitivus, Urwid based), or command line frontend (jp), and others are coming. ',
129 ('share/doc/%s' % NAME, ['CHANGELOG', 'COPYING', 'INSTALL', 'README', 'README4TRANSLATORS']), 182 ('share/doc/%s' % NAME, ['CHANGELOG', 'COPYING', 'INSTALL', 'README', 'README4TRANSLATORS']),
130 ('share/doc/%s/misc' % NAME, ['frontends/src/wix/images/split_card.sh']), 183 ('share/doc/%s/misc' % NAME, ['frontends/src/wix/images/split_card.sh']),
131 ], 184 ],
132 scripts=['frontends/src/jp/jp', 'frontends/src/primitivus/primitivus', 'frontends/src/wix/wix'], 185 scripts=['frontends/src/jp/jp', 'frontends/src/primitivus/primitivus', 'frontends/src/wix/wix'],
133 zip_safe=False, 186 zip_safe=False,
134 install_requires=['twisted', 'progressbar', 'wxPython', 'urwid', 'BeautifulSoup','Mercurial'], 187 install_requires=['twisted', 'progressbar', 'urwid', 'beautifulsoup', 'mercurial'],
135 cmdclass=dict(install=custom_install), 188 cmdclass=dict(install=custom_install),
136 ) #XXX: The Mercurial dependecy is just here to build the custom wokkel (with MUC branch), it must be removed 189 ) #XXX: The Mercurial dependecy is just here to build the custom wokkel (with MUC branch), it must be removed
137 # and replace by wokkel as soon as MUC branch is officially available in wokkel main branch. 190 # and replace by wokkel as soon as MUC branch is officially available in wokkel main branch.
191 # wxpython doesn't work, it's managed with preinstall_check
192