PyXR

c:\projects\bitpim\src \ package.py



0001 #!/usr/bin/env python
0002 ### BITPIM
0003 ###
0004 ### Copyright (C) 2003-2006 Roger Binns <rogerb@rogerbinns.com>
0005 ### Copyright (C) 2003-2004 Steven Palm <n9yty@n9yty.com>
0006 ###
0007 ### This program is free software; you can redistribute it and/or modify
0008 ### it under the terms of the BitPim license as detailed in the LICENSE file.
0009 ###
0010 ### $Id: package.py 4654 2008-07-31 21:47:50Z djpham $
0011 
0012 # This file provides the packaging definitions used by the buildrelease system
0013 
0014 import sys
0015 import os
0016 import os.path
0017 import shutil
0018 
0019 import version
0020 
0021 def sanitycheck():
0022     "Check all dependencies are present and at the correct version"
0023     
0024     print "=== Sanity check ==="
0025 
0026     print "svn location",
0027     if not "$HeadURL: https://bitpim.svn.sourceforge.net/svnroot/bitpim/releases/1.0.6/src/package.py $".split(":",1)[1].strip().startswith("https://bitpim.svn.sourceforge.net"):
0028         raise Exception("Needs to be checked out from https://bitpim.svn.sourceforge.net")
0029     print "  OK"
0030 
0031     print "python version",
0032     if sys.version_info[:2]!=(2,5):
0033        raise Exception("Should be  Python 2.5 - this is "+sys.version)
0034     print "  OK"
0035 
0036     print "wxPython version",
0037     import wx
0038     if wx.VERSION[:4]!=(2,8,7,1):
0039         raise Exception("Should be wxPython 2.8.7.1.  This is "+`wx.VERSION`)
0040     print "  OK"
0041 
0042     print "wxPython is unicode build",
0043     if not wx.USE_UNICODE:
0044         raise Exception("You need a unicode build of wxPython")
0045     print "  OK"
0046 
0047     if sys.platform!='win32':
0048         print "native.usb",
0049         import native.usb
0050         print "  OK"
0051 
0052     print "pycrypto version",
0053     expect='2.0.1'
0054     import Crypto
0055     if Crypto.__version__!=expect:
0056         raise Exception("Should be %s version of pycrypto - you have %s" % (expect, Crypto.__version__))
0057     print "  OK"
0058 
0059     print "paramiko version",
0060     expect='1.7.1 (Amy)'
0061     import paramiko
0062     if paramiko.__version__!=expect:
0063         raise Exception("Should be %s version of paramiko - you have %s" % (expect, paramiko.__version__))
0064     print "  OK"
0065     
0066     print "bitfling",
0067     import bitfling
0068     print "  OK"
0069 
0070     print "pyserial",
0071     import serial
0072     print "  OK"
0073 
0074     print "apsw",
0075     import apsw
0076     ver="3.3.13-r1"
0077     if apsw.apswversion()!=ver:
0078         raise Exception("Should be apsw version %s - you have %s" % (ver, apsw.apswversion()))
0079     print "  OK"
0080 
0081     print "sqlite",
0082     ver="3.5.4"
0083     if apsw.sqlitelibversion()!=ver:
0084         raise Exception("Should be sqlite version %s - you have %s" % (ver, apsw.sqlitelibversion()))
0085     print "  OK"
0086         
0087     print "jaro/winkler string matcher",
0088     import native.strings.jarow
0089     print "  OK"
0090 
0091     # bsddb (Linux only, for evolution)
0092     if sys.platform=="linux2":
0093         print "bsddb ",
0094         import bsddb
0095         print "  OK"
0096 
0097     # win32com.shell - See http://starship.python.net/crew/theller/moin.cgi/WinShell
0098     if sys.platform=='win32':
0099         import py2exe.mf as modulefinder # in py2exe < 0.6.4 use "import modulefinder"
0100         import win32com
0101         for p in win32com.__path__[1:]:
0102             modulefinder.AddPackagePath("win32com", p)
0103         for extra in ["win32com.shell"]: #,"win32com.mapi"
0104             __import__(extra)
0105             m = sys.modules[extra]
0106             for p in m.__path__[1:]:
0107                 modulefinder.AddPackagePath(extra, p)
0108 
0109     print "=== All checks out ==="
0110 
0111 def resources():
0112     """Get a list of the resources (images, executables, sounds etc) we ship
0113 
0114     @rtype: dict
0115     @return: The key for each entry in the dict is a directory name, and the value
0116              is a list of files within that directory"""
0117     tbl={}
0118     # list of files
0119     exts=[ '*.xy', '*.png', '*.ttf', '*.wav', '*.jpg', '*.css', '*.pdc', '*.ids']
0120     if sys.platform=='win32':
0121         # on windows we also want the chm help file and the manifest needed to get Xp style widgets
0122         exts=exts+['*.chm', '*.manifest', '*.ico']
0123         exts=exts+['helpers/*.exe','helpers/*.dll']
0124     if sys.platform=='linux2':
0125         exts=exts+['helpers/*.lbin', '*.htb']
0126     if sys.platform=='darwin':
0127         exts=exts+['helpers/*.mbin', '*.htb']
0128     # list of directories to look in
0129     dirs=[ os.path.join('.', 'resources'), '.' ]
0130     # don't ship list
0131     dontship.append("pvconv.exe")  # Qualcomm won't answer if I can ship this
0132     for wildcard in exts:
0133         for dir in dirs:
0134             for file in glob.glob(os.path.join(dir, wildcard)):
0135                 if os.path.basename(file).lower() in dontship: continue 
0136                 d=os.path.dirname(file)
0137                 if not tbl.has_key(d):
0138                     tbl[d]=[]
0139                 tbl[d].append(file)
0140 
0141     files=[]
0142     for i in tbl.keys():
0143         files.append( (i, tbl[i]) )
0144 
0145     return files
0146 
0147 def isofficialbuild():
0148     "Work out if this is an official build"
0149     import socket
0150     h=socket.gethostname().lower()
0151     # not built by rogerb (or stevep/n9yty) are unofficial
0152     return h in ('rh9bitpim.rogerbinns.com', "roger-ba470eb54",
0153                  "rogerbmac.rogerbinns.com",
0154                  # Joe's build machines
0155                  "tinyone", "tiny2one",
0156                  # Sean's
0157                  "leviathan.local",
0158                  )
0159 
0160 def ensureofficial():
0161     """If this is not an official build then ensure that version.vendor doesn't say it is"""
0162     # First do a freeze
0163     version.__freeze()
0164     print "Reloading version"
0165     reload(version)
0166     officialbuild=isofficialbuild()
0167     if officialbuild and version.vendor=='unofficial':
0168         vendor='official'
0169     elif not officialbuild and version.vendor=='official':
0170         vendor='unofficial'
0171     else:
0172         vendor=None
0173     if vendor:
0174         # so modify file
0175         versionpy=os.path.join(os.path.dirname(__file__), "version.py")
0176         out=[]
0177         for line in open(versionpy, "rt"):
0178             if line.startswith('vendor="'):
0179                 line='vendor="$%s %s $"\n' % ("Id:", vendor)
0180             out.append(line)
0181                 
0182         open(versionpy, "wt").write("".join(out))
0183         reload(version)
0184 
0185 def getversion():
0186     return version.version
0187 def setversion(versionstring, vendorstring='Test'):
0188     version.setversion(versionstring, vendorstring)
0189 
0190 import phones
0191 import encodings
0192 import glob
0193 def getallencodingsmodules():
0194     # work-around for cx_freeze: add all encodings modules
0195     _res=[]
0196     _dir=os.path.dirname(encodings.__file__)
0197     _glob_name=os.path.join(_dir, '*.py')
0198     _modules=[os.path.basename(os.path.splitext(x)[0]) for x in glob.glob(_glob_name) \
0199               if os.path.basename(x) != '__init__.py']
0200     for _key in _modules:
0201         # collect what we have
0202         try:
0203             _mod_name='encodings.'+_key
0204             __import__(_mod_name)
0205             _res.append(_mod_name)
0206         except (ImportError,AttributeError):
0207             pass
0208     return _res
0209 
0210 lazyimportmodules=['email.iterators']
0211 if sys.platform=='darwin':
0212     lazyimportmodules.append('Carbon.CF')
0213 elif sys.platform=='linux2':
0214     try:
0215         import _md5, _sha
0216         lazyimportmodules.append('_md5')
0217         lazyimportmodules.append('_sha')
0218     except ImportError:
0219         pass
0220 
0221 def getcxfreezeoptions(defaults):
0222     global lazyimportmodules
0223     defaults.update(
0224         {
0225         'app': [{'script': 'src/bp.py', 'dest_base': 'bitpim'}],
0226         }
0227         )
0228     defaults['options']['cxfreeze']['includes']=phones.getallmodulenames()+\
0229                                                  getallencodingsmodules()+\
0230                                                  lazyimportmodules
0231     return defaults
0232 
0233 def getpy2appoptions(defaults):
0234     global lazyimportmodules
0235     defaults.update(
0236         {
0237         'app': [{'script': 'src/bp.py',}],
0238         }
0239         )
0240     defaults['options']['py2app']['includes']=phones.getallmodulenames()+\
0241                                                lazyimportmodules
0242     defaults['options']['py2app']['plist']['CFBundleHelpBookFolder']="BitPim Help"
0243     defaults['options']['py2app']['plist']['CFBundleHelpBookName']="BitPim Help"
0244     return defaults
0245 
0246 def getpy2exeoptions(defaults):
0247     global lazyimportmodules
0248     defaults.update(
0249         {
0250         'windows': [{ 'script': 'src/bp.py', 'dest_base': 'bitpimw', }],
0251         'console': [{ 'script': 'src/bp.py', 'dest_base': 'bitpim', }],
0252         }
0253         )
0254     defaults['options']['py2exe']['includes']=phones.getallmodulenames()+\
0255                                                lazyimportmodules
0256     defaults['options']['py2exe']['compressed']=0 # make setup.exe smaller but installed code larger
0257     return defaults
0258 
0259 udevrules_filename='60-bitpim.rules'
0260 udevrules_line='ACTION=="add", SYSFS{idProduct}=="%04x", SYSFS{idVendor}=="%04x", RUN+="/usr/bin/bpudev $env{DEVNAME} $number $sysfs{devnum}"'
0261 from common import importas
0262 def generate_udevrules():
0263     """Generate the udev rules file based on all the known VIDs and PIDs"""
0264     global udevrules_filename, udevrules_line
0265     _ids={}
0266     for _f in phones.getallmodulenames():
0267         _profile=importas(_f)
0268         if hasattr(_profile.Profile, 'usbids'):
0269             for _id in _profile.Profile.usbids:
0270                 _ids[_id]=True
0271     _rules=[]
0272     for _entry in _ids:
0273         _rules.append(udevrules_line%(_entry[1], _entry[0]))
0274     _f=file('resources/%s'%udevrules_filename, 'wt').write('\n'.join(_rules))
0275     
0276 def copyresources(destdir):
0277     if sys.platform=='linux2':
0278         generate_udevrules()
0279     import packageutils
0280     packageutils.copysvndir('resources', os.path.join(destdir, 'resources'), resourcefilter)
0281     packageutils.copysvndir('helpers', os.path.join(destdir, 'helpers'), resourcefilter)
0282 
0283 def resourcefilter(srcfilename, destfilename):
0284     global udevrules_filename
0285     exts=[ '.xy', '.png', '.ttf', '.wav', '.jpg', '.css', '.pdc', '.ids', '.ico']
0286     files=[]
0287     if sys.platform=='win32':
0288         # on windows we also want the chm help file 
0289         exts=exts+['.chm', '.exe', '.dll']
0290     if sys.platform=='linux2':
0291         exts=exts+['.lbin', '.htb']
0292         files+=['bpudev', udevrules_filename]
0293     if sys.platform=='darwin':
0294         exts=exts+['.mbin', '.htb']
0295     if os.path.splitext(srcfilename)[1] in exts or \
0296        os.path.basename(srcfilename) in files:
0297         return srcfilename, destfilename
0298     return None
0299 
0300 def build_dependences():
0301     # build modules
0302     import buildmodules
0303     # rebuild all the prototocol (*.p) files
0304     import protogen
0305     for f in glob.glob("src/phones/*.p"):
0306         protogen.processfile(f, f+"y")
0307 
0308 def finalize(destdir):
0309     if sys.platform=='win32':
0310         for f in ("w9xpopen.exe",):
0311             if os.path.exists(os.path.join(destdir, f)):
0312                 os.remove(os.path.join(destdir, f))
0313     if sys.platform=='darwin':
0314         # do apple help
0315         import zipfile
0316         helpdir=os.path.join(destdir, "English.lproj", "BitPim Help")
0317         os.makedirs(helpdir)
0318         f=zipfile.ZipFile(os.path.join(destdir, "resources", "bitpim.htb"), "r")
0319         for name in f.namelist():
0320             if os.path.splitext(name)[1] in ('.htm', '.html', '.jpg', '.png'):
0321                 open(os.path.join(helpdir, name), "wb").write(f.read(name))
0322                 os.chmod(os.path.join(helpdir, name), 0444)
0323             else:
0324                 print "skipping help file",name
0325         # the idiots at apple decided to make it impossible to automate the help indexer
0326         # how about giving it command line options?
0327         v=os.popen("sw_vers -productVersion", "r").read()
0328         if v.startswith("10.3"):
0329             res=os.system("open -a \"Apple Help Indexing Tool\" \""+helpdir+"\"")
0330             assert res==0
0331             # we do this stupid loop monitoring cpu consumption and once it is
0332             # unchanged for 2 seconds, assume that the indexing is complete
0333             print "Waiting for indexing tool to stop by monitoring CPU consumption"
0334             import time
0335             lastval=""
0336             val="x"
0337             pid=0
0338             while val!=lastval:
0339                 print ".",
0340                 sys.stdout.flush()
0341                 time.sleep(2)
0342                 for line in os.popen("ps cx", "r"):
0343                     line=line.split()
0344                     line=line[:4]+[" ".join(line[4:])]
0345                     if line[4]!="Apple Help Indexing Tool":
0346                         continue
0347                     pid=line[0]
0348                     lastval=val
0349                     val=line[3]
0350                     break
0351             print "\nIt would appear to be done"
0352             os.system("kill "+pid)
0353         elif v.startswith("10.4"):
0354             #use Help Indexer
0355             res=os.system("\"/Developer/Applications/Utilities/Help Indexer.app/Contents/MacOS/Help Indexer\" \""+helpdir+"\" -PantherIndexing YES -Tokenizer 1 -ShowProgress YES -TigerIndexing YES")
0356             assert res==0
0357         # copy the css file in
0358         shutil.copy2(os.path.join(destdir, "resources", "bitpim.css"), os.path.join(helpdir, ".."))
0359         # don't need the wx style help any more
0360         os.remove(os.path.join(destdir, "resources", "bitpim.htb"))
0361     if sys.platform!='win32':
0362         os.system("find \""+destdir+"\" -depth -print0 | xargs -0 chmod a-w")
0363 
0364 def getvals():
0365     "Return various values about this product"
0366     res={
0367         'NAME': version.name,
0368         'VERSION': version.version,
0369         'RELEASE': version.release,
0370         'DQVERSION': version.dqverstr,
0371         'COMMENTS': "Provided under the GNU Public License (GPL)",
0372         'DESCRIPTION': "Open Source Mobile Phone Tool",
0373         'COPYRIGHT': "Copyright (C) 2003-2006 The BitPim developers",
0374         'URL': version.url,
0375         'SUPPORTURL': "http://www.bitpim.org/help/support.htm",
0376         'GUID': "{FA61D601-A0FC-48BD-AE7A-54946BCD7FB6}",
0377         'VENDOR': version.vendor,
0378         'ISSFILE': 'packaging/bitpim.iss',
0379         'SPECFILE': 'packaging/bitpim.spec',
0380         }
0381     if sys.platform=='win32':
0382         res['ICONFILE']="packaging/bitpim.ico"
0383 
0384     if sys.platform=="darwin":
0385         res['GUID']='org.bitpim.bitpim' # Java style less opaque than the guid style above!
0386         res['ICONFILE']="packaging/bitpim.icns"
0387         # prefix with macos versiopn
0388         v=os.popen("sw_vers -productVersion", "r").read()
0389         if v.startswith("10.3"):
0390             res['OUTFILEPREFIX']='PANTHER-'
0391         elif v.startswith("10.4"):
0392             res['OUTFILEPREFIX']='TIGER-'
0393         elif v.startswith("10.2"):
0394             res['OUTFILEPREFIX']='JAGUAR-'
0395         elif v.startswith("10.5"):
0396             res['OUTFILEPREFIX']='LEOPARD-'
0397     return res
0398 

Generated by PyXR 0.9.4