Module package
[hide private]
[frames] | no frames]

Source Code for Module package

  1  #!/usr/bin/env python 
  2  ### BITPIM 
  3  ### 
  4  ### Copyright (C) 2003-2006 Roger Binns <rogerb@rogerbinns.com> 
  5  ### Copyright (C) 2003-2004 Steven Palm <n9yty@n9yty.com> 
  6  ### 
  7  ### This program is free software; you can redistribute it and/or modify 
  8  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  9  ### 
 10  ### $Id: package.py 4702 2008-08-26 02:13:48Z djpham $ 
 11   
 12  # This file provides the packaging definitions used by the buildrelease system 
 13   
 14  import sys 
 15  import os 
 16  import os.path 
 17  import shutil 
 18   
 19  import version 
 20   
21 -def sanitycheck():
22 "Check all dependencies are present and at the correct version" 23 24 print "=== Sanity check ===" 25 26 print "svn location", 27 if not "$HeadURL: https://bitpim.svn.sourceforge.net/svnroot/bitpim/releases/1.0.7/src/package.py $".split(":",1)[1].strip().startswith("https://bitpim.svn.sourceforge.net"): 28 raise Exception("Needs to be checked out from https://bitpim.svn.sourceforge.net") 29 print " OK" 30 31 print "python version", 32 if sys.version_info[:2]!=(2,5): 33 raise Exception("Should be Python 2.5 - this is "+sys.version) 34 print " OK" 35 36 print "wxPython version", 37 import wx 38 if wx.VERSION[:4]!=(2,8,8,1): 39 raise Exception("Should be wxPython 2.8.8.1. This is "+`wx.VERSION`) 40 print " OK" 41 42 print "wxPython is unicode build", 43 if not wx.USE_UNICODE: 44 raise Exception("You need a unicode build of wxPython") 45 print " OK" 46 47 if sys.platform!='win32': 48 print "native.usb", 49 import native.usb 50 print " OK" 51 52 print "pycrypto version", 53 expect='2.0.1' 54 import Crypto 55 if Crypto.__version__!=expect: 56 raise Exception("Should be %s version of pycrypto - you have %s" % (expect, Crypto.__version__)) 57 print " OK" 58 59 print "paramiko version", 60 expect='1.7.4 (Desmond)' 61 import paramiko 62 if paramiko.__version__!=expect: 63 raise Exception("Should be %s version of paramiko - you have %s" % (expect, paramiko.__version__)) 64 print " OK" 65 66 print "bitfling", 67 import bitfling 68 print " OK" 69 70 print "pyserial", 71 import serial 72 print " OK" 73 74 print "apsw", 75 import apsw 76 ver="3.5.9-r2" 77 if apsw.apswversion()!=ver: 78 raise Exception("Should be apsw version %s - you have %s" % (ver, apsw.apswversion())) 79 print " OK" 80 81 print "sqlite", 82 ver="3.6.1" 83 if apsw.sqlitelibversion()!=ver: 84 raise Exception("Should be sqlite version %s - you have %s" % (ver, apsw.sqlitelibversion())) 85 print " OK" 86 87 print "jaro/winkler string matcher", 88 import native.strings.jarow 89 print " OK" 90 91 # bsddb (Linux only, for evolution) 92 if sys.platform=="linux2": 93 print "bsddb ", 94 import bsddb 95 print " OK" 96 97 # win32com.shell - See http://starship.python.net/crew/theller/moin.cgi/WinShell 98 if sys.platform=='win32': 99 import py2exe.mf as modulefinder # in py2exe < 0.6.4 use "import modulefinder" 100 import win32com 101 for p in win32com.__path__[1:]: 102 modulefinder.AddPackagePath("win32com", p) 103 for extra in ["win32com.shell"]: #,"win32com.mapi" 104 __import__(extra) 105 m = sys.modules[extra] 106 for p in m.__path__[1:]: 107 modulefinder.AddPackagePath(extra, p) 108 109 print "=== All checks out ==="
110
111 -def resources():
112 """Get a list of the resources (images, executables, sounds etc) we ship 113 114 @rtype: dict 115 @return: The key for each entry in the dict is a directory name, and the value 116 is a list of files within that directory""" 117 tbl={} 118 # list of files 119 exts=[ '*.xy', '*.png', '*.ttf', '*.wav', '*.jpg', '*.css', '*.pdc', '*.ids'] 120 if sys.platform=='win32': 121 # on windows we also want the chm help file and the manifest needed to get Xp style widgets 122 exts=exts+['*.chm', '*.manifest', '*.ico'] 123 exts=exts+['helpers/*.exe','helpers/*.dll'] 124 if sys.platform=='linux2': 125 exts=exts+['helpers/*.lbin', '*.htb'] 126 if sys.platform=='darwin': 127 exts=exts+['helpers/*.mbin', '*.htb'] 128 # list of directories to look in 129 dirs=[ os.path.join('.', 'resources'), '.' ] 130 # don't ship list 131 dontship.append("pvconv.exe") # Qualcomm won't answer if I can ship this 132 for wildcard in exts: 133 for dir in dirs: 134 for file in glob.glob(os.path.join(dir, wildcard)): 135 if os.path.basename(file).lower() in dontship: continue 136 d=os.path.dirname(file) 137 if not tbl.has_key(d): 138 tbl[d]=[] 139 tbl[d].append(file) 140 141 files=[] 142 for i in tbl.keys(): 143 files.append( (i, tbl[i]) ) 144 145 return files
146
147 -def isofficialbuild():
148 "Work out if this is an official build" 149 import socket 150 h=socket.gethostname().lower() 151 # not built by rogerb (or stevep/n9yty) are unofficial 152 return h in ('rh9bitpim.rogerbinns.com', "roger-ba470eb54", 153 "rogerbmac.rogerbinns.com", 154 # Joe's build machines 155 "tinyone", "tiny2one", 156 # Sean's 157 "leviathan.local", 158 )
159
160 -def ensureofficial():
161 """If this is not an official build then ensure that version.vendor doesn't say it is""" 162 # First do a freeze 163 version.__freeze() 164 print "Reloading version" 165 reload(version) 166 officialbuild=isofficialbuild() 167 if officialbuild and version.vendor=='unofficial': 168 vendor='official' 169 elif not officialbuild and version.vendor=='official': 170 vendor='unofficial' 171 else: 172 vendor=None 173 if vendor: 174 # so modify file 175 versionpy=os.path.join(os.path.dirname(__file__), "version.py") 176 out=[] 177 for line in open(versionpy, "rt"): 178 if line.startswith('vendor="'): 179 line='vendor="$%s %s $"\n' % ("Id:", vendor) 180 out.append(line) 181 182 open(versionpy, "wt").write("".join(out)) 183 reload(version)
184
185 -def getversion():
186 return version.version
187 -def setversion(versionstring, vendorstring='Test'):
188 version.setversion(versionstring, vendorstring)
189 190 import phones 191 import encodings 192 import glob
193 -def getallencodingsmodules():
194 # work-around for cx_freeze: add all encodings modules 195 _res=[] 196 _dir=os.path.dirname(encodings.__file__) 197 _glob_name=os.path.join(_dir, '*.py') 198 _modules=[os.path.basename(os.path.splitext(x)[0]) for x in glob.glob(_glob_name) \ 199 if os.path.basename(x) != '__init__.py'] 200 for _key in _modules: 201 # collect what we have 202 try: 203 _mod_name='encodings.'+_key 204 __import__(_mod_name) 205 _res.append(_mod_name) 206 except (ImportError,AttributeError): 207 pass 208 return _res
209 210 lazyimportmodules=['email.iterators'] 211 if sys.platform=='darwin': 212 lazyimportmodules.append('Carbon.CF') 213 elif sys.platform=='linux2': 214 try: 215 import _md5, _sha 216 lazyimportmodules.append('_md5') 217 lazyimportmodules.append('_sha') 218 except ImportError: 219 pass 220
221 -def getcxfreezeoptions(defaults):
222 global lazyimportmodules 223 defaults.update( 224 { 225 'app': [{'script': 'src/bp.py', 'dest_base': 'bitpim'}], 226 } 227 ) 228 defaults['options']['cxfreeze']['includes']=phones.getallmodulenames()+\ 229 getallencodingsmodules()+\ 230 lazyimportmodules 231 return defaults
232
233 -def getpy2appoptions(defaults):
234 global lazyimportmodules 235 defaults.update( 236 { 237 'app': [{'script': 'src/bp.py',}], 238 } 239 ) 240 defaults['options']['py2app']['includes']=phones.getallmodulenames()+\ 241 lazyimportmodules 242 defaults['options']['py2app']['plist']['CFBundleHelpBookFolder']="BitPim Help" 243 defaults['options']['py2app']['plist']['CFBundleHelpBookName']="BitPim Help" 244 return defaults
245
246 -def getpy2exeoptions(defaults):
247 global lazyimportmodules 248 defaults.update( 249 { 250 'windows': [{ 'script': 'src/bp.py', 'dest_base': 'bitpimw', }], 251 'console': [{ 'script': 'src/bp.py', 'dest_base': 'bitpim', }], 252 } 253 ) 254 defaults['options']['py2exe']['includes']=phones.getallmodulenames()+\ 255 lazyimportmodules 256 defaults['options']['py2exe']['compressed']=0 # make setup.exe smaller but installed code larger 257 return defaults
258 259 udevrules_filename='60-bitpim.rules' 260 udevrules_line='ACTION=="add", SYSFS{idProduct}=="%04x", SYSFS{idVendor}=="%04x", RUN+="/usr/bin/bpudev $env{DEVNAME} $number $sysfs{devnum}"' 261 from common import importas
262 -def generate_udevrules():
263 """Generate the udev rules file based on all the known VIDs and PIDs""" 264 global udevrules_filename, udevrules_line 265 _ids={} 266 for _f in phones.getallmodulenames(): 267 _profile=importas(_f) 268 if hasattr(_profile.Profile, 'usbids'): 269 for _id in _profile.Profile.usbids: 270 _ids[_id]=True 271 _rules=[] 272 for _entry in _ids: 273 _rules.append(udevrules_line%(_entry[1], _entry[0])) 274 _f=file('resources/%s'%udevrules_filename, 'wt').write('\n'.join(_rules))
275
276 -def copyresources(destdir):
277 if sys.platform=='linux2': 278 generate_udevrules() 279 import packageutils 280 packageutils.copysvndir('resources', os.path.join(destdir, 'resources'), resourcefilter) 281 packageutils.copysvndir('helpers', os.path.join(destdir, 'helpers'), resourcefilter)
282
283 -def resourcefilter(srcfilename, destfilename):
284 global udevrules_filename 285 exts=[ '.xy', '.png', '.ttf', '.wav', '.jpg', '.css', '.pdc', '.ids', '.ico'] 286 files=[] 287 if sys.platform=='win32': 288 # on windows we also want the chm help file 289 exts=exts+['.chm', '.exe', '.dll'] 290 if sys.platform=='linux2': 291 exts=exts+['.lbin', '.htb'] 292 files+=['bpudev', udevrules_filename] 293 if sys.platform=='darwin': 294 exts=exts+['.mbin', '.htb'] 295 if os.path.splitext(srcfilename)[1] in exts or \ 296 os.path.basename(srcfilename) in files: 297 return srcfilename, destfilename 298 return None
299
300 -def build_dependences():
301 # build modules 302 import buildmodules 303 # rebuild all the prototocol (*.p) files 304 import protogen 305 for f in glob.glob("src/phones/*.p"): 306 protogen.processfile(f, f+"y")
307
308 -def finalize(destdir):
309 if sys.platform=='win32': 310 for f in ("w9xpopen.exe",): 311 if os.path.exists(os.path.join(destdir, f)): 312 os.remove(os.path.join(destdir, f)) 313 if sys.platform=='darwin': 314 # do apple help 315 import zipfile 316 helpdir=os.path.join(destdir, "English.lproj", "BitPim Help") 317 os.makedirs(helpdir) 318 f=zipfile.ZipFile(os.path.join(destdir, "resources", "bitpim.htb"), "r") 319 for name in f.namelist(): 320 if os.path.splitext(name)[1] in ('.htm', '.html', '.jpg', '.png'): 321 open(os.path.join(helpdir, name), "wb").write(f.read(name)) 322 os.chmod(os.path.join(helpdir, name), 0444) 323 else: 324 print "skipping help file",name 325 # the idiots at apple decided to make it impossible to automate the help indexer 326 # how about giving it command line options? 327 v=os.popen("sw_vers -productVersion", "r").read() 328 if v.startswith("10.3"): 329 res=os.system("open -a \"Apple Help Indexing Tool\" \""+helpdir+"\"") 330 assert res==0 331 # we do this stupid loop monitoring cpu consumption and once it is 332 # unchanged for 2 seconds, assume that the indexing is complete 333 print "Waiting for indexing tool to stop by monitoring CPU consumption" 334 import time 335 lastval="" 336 val="x" 337 pid=0 338 while val!=lastval: 339 print ".", 340 sys.stdout.flush() 341 time.sleep(2) 342 for line in os.popen("ps cx", "r"): 343 line=line.split() 344 line=line[:4]+[" ".join(line[4:])] 345 if line[4]!="Apple Help Indexing Tool": 346 continue 347 pid=line[0] 348 lastval=val 349 val=line[3] 350 break 351 print "\nIt would appear to be done" 352 os.system("kill "+pid) 353 elif v.startswith("10.4"): 354 #use Help Indexer 355 res=os.system("\"/Developer/Applications/Utilities/Help Indexer.app/Contents/MacOS/Help Indexer\" \""+helpdir+"\" -PantherIndexing YES -Tokenizer 1 -ShowProgress YES -TigerIndexing YES") 356 assert res==0 357 # copy the css file in 358 shutil.copy2(os.path.join(destdir, "resources", "bitpim.css"), os.path.join(helpdir, "..")) 359 # don't need the wx style help any more 360 os.remove(os.path.join(destdir, "resources", "bitpim.htb")) 361 if sys.platform!='win32': 362 os.system("find \""+destdir+"\" -depth -print0 | xargs -0 chmod a-w")
363
364 -def getvals():
365 "Return various values about this product" 366 res={ 367 'NAME': version.name, 368 'VERSION': version.version, 369 'RELEASE': version.release, 370 'DQVERSION': version.dqverstr, 371 'COMMENTS': "Provided under the GNU Public License (GPL)", 372 'DESCRIPTION': "Open Source Mobile Phone Tool", 373 'COPYRIGHT': "Copyright (C) 2003-2006 The BitPim developers", 374 'URL': version.url, 375 'SUPPORTURL': "http://www.bitpim.org/help/support.htm", 376 'GUID': "{FA61D601-A0FC-48BD-AE7A-54946BCD7FB6}", 377 'VENDOR': version.vendor, 378 'ISSFILE': 'packaging/bitpim.iss', 379 'SPECFILE': 'packaging/bitpim.spec', 380 } 381 if sys.platform=='win32': 382 res['ICONFILE']="packaging/bitpim.ico" 383 384 if sys.platform=="darwin": 385 res['GUID']='org.bitpim.bitpim' # Java style less opaque than the guid style above! 386 res['ICONFILE']="packaging/bitpim.icns" 387 # prefix with macos versiopn 388 v=os.popen("sw_vers -productVersion", "r").read() 389 if v.startswith("10.3"): 390 res['OUTFILEPREFIX']='PANTHER-' 391 elif v.startswith("10.4"): 392 res['OUTFILEPREFIX']='TIGER-' 393 elif v.startswith("10.2"): 394 res['OUTFILEPREFIX']='JAGUAR-' 395 elif v.startswith("10.5"): 396 res['OUTFILEPREFIX']='LEOPARD-' 397 return res
398