2 # -*- coding: UTF-8 -*-
3 # vim: expandtab sw=4 ts=4 sts=4:
6 Setup script for installation using distutils
8 __author__
= 'Michal Čihař'
9 __email__
= 'michal@cihar.com'
11 Copyright (c) 2003 - 2007 Michal Čihař
13 This program is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License version 2 as published by
15 the Free Software Foundation.
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 import distutils
.command
.build
29 import distutils
.command
.build_scripts
30 import distutils
.command
.clean
31 import distutils
.command
.install
32 import distutils
.command
.install_data
33 from stat
import ST_MODE
34 from wammu_setup
import msgfmt
41 # Optional support for py2exe
48 # used for passing state for skiping dependency check
49 skip_dependencies
= False
52 PYTHONGAMMU_REQUIRED
= (0, 24)
53 WXPYTHON_REQUIRED
= (2, 6, 2, 0)
55 # check if Python is called on the first line with this expression
56 first_line_re
= re
.compile('^#!.*python[0-9.]*([ \t].*)?$')
58 class build_scripts_wammu(distutils
.command
.build_scripts
.build_scripts
, object):
60 This is mostly distutils copy, it just renames script according
61 to platform (.pyw for Windows, without extension for others)
63 def copy_scripts (self
):
64 """Copy each script listed in 'self.scripts'; if it's marked as a
65 Python script in the Unix way (first line matches 'first_line_re',
66 ie. starts with "\#!" and contains "python"), then adjust the first
67 line to refer to the current Python interpreter as we copy.
69 self
.mkpath(self
.build_dir
)
71 for script
in self
.scripts
:
73 script
= distutils
.util
.convert_path(script
)
74 outfile
= os
.path
.join(self
.build_dir
, os
.path
.splitext(os
.path
.basename(script
))[0])
75 if sys
.platform
== 'win32':
76 outfile
+= os
.extsep
+ 'pyw'
77 outfiles
.append(outfile
)
79 if not self
.force
and not distutils
.dep_util
.newer(script
, outfile
):
80 distutils
.log
.debug("not copying %s (up-to-date)", script
)
83 # Always open the file, but ignore failures in dry-run mode --
84 # that way, we'll get accurate feedback if we can read the
93 first_line
= f
.readline()
95 self
.warn("%s is an empty file (skipping)" % script
)
98 match
= first_line_re
.match(first_line
)
101 post_interp
= match
.group(1) or ''
104 distutils
.log
.info("copying and adjusting %s -> %s", script
,
107 outf
= open(outfile
, "w")
108 if not distutils
.sysconfig
.python_build
:
109 outf
.write("#!%s%s\n" %
110 (os
.path
.normpath(sys
.executable
),
113 outf
.write("#!%s%s\n" %
115 distutils
.sysconfig
.get_config_var("BINDIR"),
116 "python" + distutils
.sysconfig
.get_config_var("EXE")),
118 outf
.writelines(f
.readlines())
124 self
.copy_file(script
, outfile
)
126 if os
.name
== 'posix':
127 for file in outfiles
:
129 distutils
.log
.info("changing mode of %s", file)
131 oldmode
= os
.stat(file)[ST_MODE
] & 07777
132 newmode
= (oldmode |
0555) & 07777
133 if newmode
!= oldmode
:
134 distutils
.log
.info("changing mode of %s from %o to %o",
135 file, oldmode
, newmode
)
136 os
.chmod(file, newmode
)
140 def list_message_files(package
= 'wammu', suffix
= '.po'):
142 Return list of all found message files and their installation paths.
144 _files
= glob
.glob('locale/*/' + package
+ suffix
)
147 # basename (without extension) is a locale name
148 _locale
= os
.path
.basename(os
.path
.dirname(_file
))
149 _list
.append((_file
, os
.path
.join(
150 'share', 'locale', _locale
, 'LC_MESSAGES', '%s.mo' % package
)))
153 class build_wammu(distutils
.command
.build
.build
, object):
155 Custom build command with locales support.
157 user_options
= distutils
.command
.build
.build
.user_options
+ [('skip-deps', 's', 'skip checking for dependencies')]
158 boolean_options
= distutils
.command
.build
.build
.boolean_options
+ ['skip-deps']
160 def initialize_options(self
):
161 global skip_dependencies
162 super(build_wammu
, self
).initialize_options()
163 self
.skip_deps
= skip_dependencies
165 def finalize_options(self
):
166 global skip_dependencies
167 super(build_wammu
, self
).finalize_options()
169 skip_dependencies
= self
.skip_deps
171 def build_message_files (self
):
173 For each locale/*.po, build .mo file in target locale directory.
175 for (_src
, _dst
) in list_message_files():
176 _build_dst
= os
.path
.join('build', _dst
)
177 destdir
= os
.path
.dirname(_build_dst
)
178 if not os
.path
.exists(destdir
):
180 if not os
.path
.exists(_build_dst
) or \
181 (os
.path
.getmtime(_build_dst
) < os
.path
.getmtime(_src
)):
182 distutils
.log
.info('compiling %s -> %s' % (_src
, _build_dst
))
183 msgfmt
.make(_src
, _build_dst
)
185 def check_requirements(self
):
186 if os
.getenv('SKIPGAMMUCHECK') == 'yes':
187 print 'Skipping Gammu check, expecting you know what you are doing!'
189 print 'Checking for python-gammu ...',
192 version
= gammu
.Version()
193 print 'found version %s using Gammu %s ...' % (version
[1], version
[0]),
195 pygver
= tuple(map(int, version
[1].split('.')))
196 if pygver
< PYTHONGAMMU_REQUIRED
:
198 print 'You need python-gammu at least %s!' % '.'.join(map(str, PYTHONGAMMU_REQUIRED
))
199 print 'You can get it from <http://cihar.com/gammu/python/>'
202 except ImportError, message
:
203 print 'Could not import python-gammu!'
204 print 'You can get it from <http://cihar.com/gammu/python/>'
205 print 'Import failed with following error: %s' % message
208 if os
.getenv('SKIPWXCHECK') == 'yes':
209 print 'Skipping wxPython check, expecting you know what you are doing!'
211 print 'Checking for wxPython ...',
214 print 'found version %s ...' % wx
.VERSION_STRING
,
215 if wx
.VERSION
< WXPYTHON_REQUIRED
:
217 print 'You need at least wxPython %s!' % '.'.join(map(str, WXPYTHON_REQUIRED
))
218 print 'You can get it from <http://www.wxpython.org>'
220 if not wx
.USE_UNICODE
:
222 print 'You need at least wxPython %s with unicode enabled!' % '.'.join(map(str, WXPYTHON_REQUIRED
))
223 print 'You can get it from <http://www.wxpython.org>'
227 print 'You need wxPython!'
228 print 'You can get it from <http://www.wxpython.org>'
231 print 'Checking for Bluetooth stack ...',
234 print 'PyBluez found'
237 import gnomebt
.controller
238 print 'GNOME Bluetooth found'
239 print 'WARNING: GNOME Bluetooth support is limited, consider installing PyBluez'
241 print 'WARNING: neither GNOME Bluetooth nor PyBluez found, without those you can not search for bluetooth devices'
242 print 'PyBluez can be downloaded from <http://org.csail.mit.edu/pybluez/>'
244 if sys
.platform
== 'win32':
245 print 'Checking for PyWin32 ...',
247 import win32file
, win32com
, win32api
251 print 'This module is now needed for Windows!'
252 print 'PyWin32 can be downloaded from <https://sourceforge.net/projects/pywin32/>'
256 global skip_dependencies
257 self
.build_message_files()
258 if not skip_dependencies
:
259 self
.check_requirements()
260 super(build_wammu
, self
).run()
262 class clean_wammu(distutils
.command
.clean
.clean
, object):
264 Custom clean command.
269 # remove share directory
270 directory
= os
.path
.join('build', 'share')
271 if os
.path
.exists(directory
):
272 distutils
.dir_util
.remove_tree(directory
, dry_run
=self
.dry_run
)
274 distutils
.log
.warn('\'%s\' does not exist -- can\'t clean it',
276 super(clean_wammu
, self
).run()
278 class install_wammu(distutils
.command
.install
.install
, object):
280 Install wrapper to support option for skipping deps
283 user_options
= distutils
.command
.install
.install
.user_options
+ [('skip-deps', 's', 'skip checking for dependencies')]
284 boolean_options
= distutils
.command
.install
.install
.boolean_options
+ ['skip-deps']
286 def initialize_options(self
):
287 global skip_dependencies
288 super(install_wammu
, self
).initialize_options()
289 self
.skip_deps
= skip_dependencies
291 def finalize_options(self
):
292 global skip_dependencies
293 super(install_wammu
, self
).finalize_options()
295 skip_dependencies
= self
.skip_deps
297 class install_data_wammu(distutils
.command
.install_data
.install_data
, object):
299 Install locales in addition to regullar data.
304 Install also .mo files.
306 # add .mo files to data files
307 for (_src
, _dst
) in list_message_files():
308 _build_dst
= os
.path
.join('build', _dst
)
309 item
= [os
.path
.dirname(_dst
), [_build_dst
]]
310 self
.data_files
.append(item
)
312 super(install_data_wammu
, self
).run()
314 py2exepackages
= ['Wammu']
315 if sys
.version_info
>= (2, 5):
316 # Email module changed a lot in python 2.5 and we can not yet use new API
317 py2exepackages
.append('email')
318 py2exepackages
.append('email.mime')
323 addparams
['windows'] = [
325 'script': 'wammu.py',
326 'icon_resources': [(1, 'icon/wammu.ico')],
329 addparams
['zipfile'] = 'shared.lib'
331 distutils
.core
.setup(name
="wammu",
332 version
= Wammu
.__version
__,
333 description
= "Wammu Mobile Phone Manager",
334 long_description
= "Phone manager built on top of python-gammu. Supports many phones.",
335 author
= "Michal Čihař",
336 author_email
= "michal@cihar.com",
337 maintainer
= "Michal Čihař",
338 maintainer_email
= "michal@cihar.com",
339 platforms
= ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME'],
340 keywords
= ['mobile', 'phone', 'SMS', 'contact', 'gammu', 'calendar', 'todo'],
341 url
= "http://wammu.eu/",
342 download_url
= 'http://wammu.eu/download/',
345 'Development Status :: 5 - Production/Stable',
346 'Environment :: Win32 (MS Windows)',
347 'Environment :: X11 Applications :: GTK',
348 'Intended Audience :: End Users/Desktop',
349 'License :: OSI Approved :: GNU General Public License (GPL)',
350 'Operating System :: Microsoft :: Windows :: Windows 95/98/2000',
351 'Operating System :: Microsoft :: Windows :: Windows NT/2000',
352 'Operating System :: POSIX',
353 'Operating System :: Unix',
354 'Programming Language :: Python',
355 'Topic :: Communications :: Telephony',
356 'Topic :: Office/Business :: Scheduling',
357 'Topic :: Utilities',
358 'Natural Language :: Afrikaans',
359 'Natural Language :: English',
360 'Natural Language :: Catalan',
361 'Natural Language :: Chinese (Simplified)',
362 'Natural Language :: Czech',
363 'Natural Language :: Dutch',
364 # 'Natural Language :: Estonian',
365 'Natural Language :: Finnish',
366 'Natural Language :: French',
367 'Natural Language :: German',
368 'Natural Language :: Hungarian',
369 'Natural Language :: Italian',
370 'Natural Language :: Korean',
371 'Natural Language :: Polish',
372 'Natural Language :: Portuguese (Brazilian)',
373 'Natural Language :: Russian',
374 'Natural Language :: Slovak',
375 'Natural Language :: Spanish',
376 'Natural Language :: Swedish',
378 packages
= ['Wammu', 'Wammu.wxcomp'],
379 scripts
= ['wammu.py', 'wammu-configure.py'],
381 (os
.path
.join('share','Wammu','images','icons'), glob
.glob('images/icons/*.png')),
382 (os
.path
.join('share','Wammu','images','misc'), glob
.glob('images/misc/*.png')),
383 (os
.path
.join('share','applications'), ['wammu.desktop']),
384 (os
.path
.join('share','pixmaps'), [
390 (os
.path
.join('share','man','man1'), ['wammu.1', 'wammu-configure.1'])
392 # Override certain command classes with our own ones
394 'build': build_wammu
,
395 'build_scripts': build_scripts_wammu
,
396 'clean': clean_wammu
,
397 'install': install_wammu
,
398 'install_data': install_data_wammu
,
401 options
= {'py2exe': {
404 'packages': py2exepackages
,