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 © 2003 - 2010 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
49 PYTHONGAMMU_REQUIRED
= (0, 24)
50 WXPYTHON_REQUIRED
= (2, 6, 2, 0)
52 # check if Python is called on the first line with this expression
53 first_line_re
= re
.compile('^#!.*python[0-9.]*([ \t].*)?$')
55 class build_scripts_wammu(distutils
.command
.build_scripts
.build_scripts
, object):
57 This is mostly distutils copy, it just renames script according
58 to platform (.pyw for Windows, without extension for others)
60 def copy_scripts (self
):
61 """Copy each script listed in 'self.scripts'; if it's marked as a
62 Python script in the Unix way (first line matches 'first_line_re',
63 ie. starts with "\#!" and contains "python"), then adjust the first
64 line to refer to the current Python interpreter as we copy.
66 self
.mkpath(self
.build_dir
)
68 for script
in self
.scripts
:
70 script
= distutils
.util
.convert_path(script
)
71 outfile
= os
.path
.join(self
.build_dir
, os
.path
.splitext(os
.path
.basename(script
))[0])
72 if sys
.platform
== 'win32':
73 outfile
+= os
.extsep
+ 'pyw'
74 outfiles
.append(outfile
)
76 if not self
.force
and not distutils
.dep_util
.newer(script
, outfile
):
77 distutils
.log
.debug("not copying %s (up-to-date)", script
)
80 # Always open the file, but ignore failures in dry-run mode --
81 # that way, we'll get accurate feedback if we can read the
90 first_line
= f
.readline()
92 self
.warn("%s is an empty file (skipping)" % script
)
95 match
= first_line_re
.match(first_line
)
98 post_interp
= match
.group(1) or ''
101 distutils
.log
.info("copying and adjusting %s -> %s", script
,
104 outf
= open(outfile
, "w")
105 if not distutils
.sysconfig
.python_build
:
106 outf
.write("#!%s%s\n" %
107 (os
.path
.normpath(sys
.executable
),
110 outf
.write("#!%s%s\n" %
112 distutils
.sysconfig
.get_config_var("BINDIR"),
113 "python" + distutils
.sysconfig
.get_config_var("EXE")),
115 outf
.writelines(f
.readlines())
121 self
.copy_file(script
, outfile
)
123 if os
.name
== 'posix':
124 for file in outfiles
:
126 distutils
.log
.info("changing mode of %s", file)
128 oldmode
= os
.stat(file)[ST_MODE
] & 07777
129 newmode
= (oldmode |
0555) & 07777
130 if newmode
!= oldmode
:
131 distutils
.log
.info("changing mode of %s from %o to %o",
132 file, oldmode
, newmode
)
133 os
.chmod(file, newmode
)
137 def list_message_files(package
= 'wammu', suffix
= '.po'):
139 Return list of all found message files and their installation paths.
141 _files
= glob
.glob('locale/*/' + package
+ suffix
)
144 # basename (without extension) is a locale name
145 _locale
= os
.path
.basename(os
.path
.dirname(_file
))
146 _list
.append((_locale
, _file
, os
.path
.join(
147 'share', 'locale', _locale
, 'LC_MESSAGES', '%s.mo' % package
)))
150 class build_wammu(distutils
.command
.build
.build
, object):
152 Custom build command with locales support.
155 def build_message_files (self
):
157 For each locale/*.po, build .mo file in target locale directory.
159 As a side effect we build wammu.desktop file with updated
162 desktop_translations
= {}
163 for (_locale
, _src
, _dst
) in list_message_files():
164 _build_dst
= os
.path
.join(self
.build_base
, _dst
)
165 destdir
= os
.path
.dirname(_build_dst
)
166 if not os
.path
.exists(destdir
):
168 distutils
.log
.info('compiling %s -> %s' % (_src
, _build_dst
))
169 msgfmt
.make(_src
, _build_dst
)
170 desktop_translations
[_locale
] = msgfmt
.DESKTOP_TRANSLATIONS
172 desktop
= os
.path
.join(self
.build_base
, 'wammu.desktop')
173 in_desktop
= file('wammu.desktop.in', 'r')
174 out_desktop
= file(desktop
, 'w')
175 for line
in in_desktop
:
176 if line
.startswith('_Name'):
177 out_desktop
.write('Name=%s\n' % msgfmt
.DESKTOP_NAME
)
178 for loc
in desktop_translations
.keys():
179 if desktop_translations
[loc
].has_key('Name'):
180 out_desktop
.write('Name[%s]=%s\n' % (loc
, desktop_translations
[loc
]['Name']))
181 elif line
.startswith('_GenericName'):
182 out_desktop
.write('GenericName=%s\n' % msgfmt
.DESKTOP_GENERIC_NAME
)
183 for loc
in desktop_translations
.keys():
184 if desktop_translations
[loc
].has_key('GenericName'):
185 out_desktop
.write('GenericName[%s]=%s\n' % (loc
, desktop_translations
[loc
]['GenericName']))
186 elif line
.startswith('_Comment'):
187 out_desktop
.write('Comment=%s\n' % msgfmt
.DESKTOP_COMMENT
)
188 for loc
in desktop_translations
.keys():
189 if desktop_translations
[loc
].has_key('Comment'):
190 out_desktop
.write('Comment[%s]=%s\n' % (loc
, desktop_translations
[loc
]['Comment']))
192 out_desktop
.write(line
)
195 def check_requirements(self
):
196 print 'Checking for python-gammu ...',
199 version
= gammu
.Version()
200 print 'found version %s using Gammu %s ...' % (version
[1], version
[0]),
202 pygver
= tuple(map(int, version
[1].split('.')))
203 if pygver
< PYTHONGAMMU_REQUIRED
:
205 print 'You need python-gammu at least %s!' % '.'.join(map(str, PYTHONGAMMU_REQUIRED
))
206 print 'You can get it from <http://wammu.eu/python-gammu/>'
209 except ImportError, message
:
211 print 'Could not import python-gammu!'
212 print 'You can get it from <http://wammu.eu/python-gammu/>'
213 print 'Import failed with following error: %s' % message
215 print 'Checking for wxPython ...',
218 print 'found version %s ...' % wx
.VERSION_STRING
,
219 if wx
.VERSION
< WXPYTHON_REQUIRED
:
221 print 'You need at least wxPython %s!' % '.'.join(map(str, WXPYTHON_REQUIRED
))
222 print 'You can get it from <http://www.wxpython.org>'
223 elif not wx
.USE_UNICODE
:
225 print 'You need at least wxPython %s with unicode enabled!' % '.'.join(map(str, WXPYTHON_REQUIRED
))
226 print 'You can get it from <http://www.wxpython.org>'
231 print 'You need wxPython!'
232 print 'You can get it from <http://www.wxpython.org>'
234 print 'Checking for Bluetooth stack ...',
240 print 'WARNING: PyBluez not found, without it you can not search for bluetooth devices'
241 print 'PyBluez can be downloaded from <http://org.csail.mit.edu/pybluez/>'
243 print 'Checking for xml stack ...',
249 print 'python-xml not found!'
251 if sys
.platform
== 'win32':
252 print 'Checking for PyWin32 ...',
254 import win32file
, win32com
, win32api
258 print 'This module is now needed for Windows!'
259 print 'PyWin32 can be downloaded from <https://sourceforge.net/projects/pywin32/>'
263 self
.build_message_files()
264 self
.check_requirements()
265 super(build_wammu
, self
).run()
267 class clean_wammu(distutils
.command
.clean
.clean
, object):
269 Custom clean command.
274 # remove share directory
275 directory
= os
.path
.join(self
.build_base
, 'share')
276 if os
.path
.exists(directory
):
277 distutils
.dir_util
.remove_tree(directory
, dry_run
=self
.dry_run
)
279 distutils
.log
.warn('\'%s\' does not exist -- can\'t clean it',
281 super(clean_wammu
, self
).run()
283 class install_data_wammu(distutils
.command
.install_data
.install_data
, object):
285 Install locales in addition to regullar data.
290 Install also .mo files.
292 # add .mo files to data files
293 for (_locale
, _src
, _dst
) in list_message_files():
294 _build_dst
= os
.path
.join('build', _dst
)
295 item
= [os
.path
.dirname(_dst
), [_build_dst
]]
296 self
.data_files
.append(item
)
299 if sys
.platform
!= 'win32':
300 self
.data_files
.append((os
.path
.join('share','applications'), [os
.path
.join('build', 'wammu.desktop')]))
303 super(install_data_wammu
, self
).run()
305 py2exepackages
= ['Wammu']
306 if sys
.version_info
>= (2, 5):
307 # Email module changed a lot in python 2.5 and we can not yet use new API
308 py2exepackages
.append('email')
309 py2exepackages
.append('email.mime')
311 # ModuleFinder can't handle runtime changes to __path__, but win32com uses them
313 # if this doesn't work, try import modulefinder
314 import py2exe
.mf
as modulefinder
316 for p
in win32com
.__path
__[1:]:
317 modulefinder
.AddPackagePath("win32com", p
)
318 for extra
in ["win32com.shell"]: #,"win32com.mapi"
320 m
= sys
.modules
[extra
]
321 for p
in m
.__path
__[1:]:
322 modulefinder
.AddPackagePath(extra
, p
)
324 # no build path setup, no worries.
330 addparams
['windows'] = [
332 'script': 'wammu.py',
333 'icon_resources': [(1, 'icon/wammu.ico')],
336 addparams
['zipfile'] = 'shared.lib'
339 (os
.path
.join('share','Wammu','images','icons'), glob
.glob('images/icons/*.png')),
340 (os
.path
.join('share','Wammu','images','misc'), glob
.glob('images/misc/*.png')),
343 data_files
.append((os
.path
.join('share','pixmaps'), [
349 data_files
.append((os
.path
.join('share','man','man1'), ['wammu.1', 'wammu-configure.1']))
350 data_files
.append((os
.path
.join('share','man','cs','man1'), ['man/cs/wammu.1', 'man/cs/wammu-configure.1']))
351 data_files
.append((os
.path
.join('share','man','nl','man1'), ['man/nl/wammu.1', 'man/nl/wammu-configure.1']))
353 distutils
.core
.setup(name
="wammu",
354 version
= Wammu
.__version
__,
355 description
= "Wammu Mobile Phone Manager",
356 long_description
= "Phone manager built on top of python-gammu. Supports many phones.",
357 author
= u
"Michal Cihar",
358 author_email
= "michal@cihar.com",
359 maintainer
= u
"Michal Cihar",
360 maintainer_email
= "michal@cihar.com",
361 platforms
= ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME'],
362 keywords
= ['mobile', 'phone', 'SMS', 'contact', 'gammu', 'calendar', 'todo'],
363 url
= "http://wammu.eu/wammu/",
364 download_url
= 'http://wammu.eu/download/wammu/',
367 'Development Status :: 5 - Production/Stable',
368 'Environment :: Win32 (MS Windows)',
369 'Environment :: X11 Applications :: GTK',
370 'Intended Audience :: End Users/Desktop',
371 'License :: OSI Approved :: GNU General Public License (GPL)',
372 'Operating System :: Microsoft :: Windows :: Windows 95/98/2000',
373 'Operating System :: Microsoft :: Windows :: Windows NT/2000',
374 'Operating System :: POSIX',
375 'Operating System :: Unix',
376 'Programming Language :: Python',
377 'Topic :: Communications :: Telephony',
378 'Topic :: Office/Business :: Scheduling',
379 'Topic :: Utilities',
380 'Natural Language :: English',
381 'Natural Language :: Afrikaans',
382 'Natural Language :: Catalan',
383 'Natural Language :: Czech',
384 'Natural Language :: German',
385 'Natural Language :: Greek',
386 'Natural Language :: Spanish',
387 # 'Natural Language :: Estonian',
388 'Natural Language :: Finnish',
389 'Natural Language :: French',
390 # 'Natural Language :: Galician',
391 'Natural Language :: Hebrew',
392 'Natural Language :: Hungarian',
393 'Natural Language :: Indonesian',
394 'Natural Language :: Italian',
395 'Natural Language :: Korean',
396 'Natural Language :: Dutch',
397 'Natural Language :: Polish',
398 'Natural Language :: Portuguese (Brazilian)',
399 'Natural Language :: Russian',
400 'Natural Language :: Slovak',
401 'Natural Language :: Swedish',
402 'Natural Language :: Chinese (Simplified)',
403 'Natural Language :: Chinese (Traditional)',
405 packages
= ['Wammu'],
406 scripts
= ['wammu.py', 'wammu-configure.py'],
407 data_files
= data_files
,
408 # Override certain command classes with our own ones
410 'build': build_wammu
,
411 'build_scripts': build_scripts_wammu
,
412 'clean': clean_wammu
,
413 'install_data': install_data_wammu
,
416 options
= {'py2exe': {
418 'packages': py2exepackages
,