home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.6) import os import shutil import sys import glob import re import StringIO import traceback import distutils.core as distutils import email.Utils as email import time import zipfile import getopt import subprocess import config sys.setrecursionlimit(5000) sys.path += map(os.path.abspath, [ './src', './ext', './ext/' + config.platformName, './lib', './platlib/' + config.platformName]) import digsbypaths sys.path.insert(0, digsbypaths.get_platlib_dir()) ops = os.path.split opj = os.path.join opd = os.path.dirname opb = os.path.basename BUILDDIR = 'packagebuild' DISTDIR = 'dist' PATH_CXFREEZE = '/opt/cx_Freeze-3.0.3' program_files = os.environ.get('ProgramFiles(x86)', os.environ.get('ProgramFiles', 'c:\\Program Files')) PATH_INNOSETUP = opj(program_files, 'inno setup 5\\compil32.exe') PATH_NSIS = opj(program_files, 'nsis\\makensis.exe') if sys.platform.startswith('win'): try: pass except AssertionError: sys sys print >>sys.stderr, 'NSIS not found: %r' % PATH_NSIS except: sys<EXCEPTION MATCH>AssertionError sys RT_MANIFEST = 24 DEBUG = hasattr(sys, 'gettotalrefcount') if DEBUG: WINXP_MANIFEST = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">\n <noInheritable></noInheritable>\n <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.30729.1" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>\n <file name="msvcr90d.dll" hashalg="SHA1" hash="77c2dcb12982a6855302844f8803e68ce360fcc9"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>WA59/AbhIDaZgmB1cN9MFlDi2g4=</dsig:DigestValue></asmv2:hash></file> <file name="msvcp90d.dll" hashalg="SHA1" hash="b2fa2a05ee7e6a2595c16547246753a62e9bf398"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>Rxofhw9S95owIW2MDmCg2zStQgs=</dsig:DigestValue></asmv2:hash></file> <file name="msvcm90d.dll" hashalg="SHA1" hash="6cfc0c6330724d86db3e2ef295d4e1d75a43514a"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>iOxEMZK3fufMDQFuKGZ4VdAYzWY=</dsig:DigestValue></asmv2:hash></file>\n</assembly>' else: WINXP_MANIFEST = '\n <?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">\n <assemblyIdentity\n version="5.0.0.0"\n processorArchitecture="x86"\n name="Program"\n type="win32"\n />\n <description>Program</description>\n <dependency>\n <dependentAssembly>\n <assemblyIdentity\n type="win32"\n name="Microsoft.Windows.Common-Controls"\n version="6.0.0.0"\n processorArchitecture="X86"\n publicKeyToken="6595b64144ccf1df"\n language="*"\n />\n </dependentAssembly>\n </dependency>\n </assembly>\n ' def rmrf(path): if sys.platform != 'win32': os.system('find "' + path + '" -type d -print0 | xargs -0 chmod +w ; true') print 'removing: %r' % path entries = os.listdir(path) for e in entries: fullname = opj(path, e) if os.path.isdir(fullname): rmrf(fullname) continue os.remove(fullname) os.rmdir(path) def recursiveglob(pattern): res = [] dir = opd(pattern) if len(dir): for d in os.listdir(dir): if os.path.isdir(opj(dir, d)): res += recursiveglob(opj(dir, d, opb(pattern))) continue return [] + _[1] def run(*args, **kwargs): verbose = kwargs.get('verbose', True) if verbose: print `args` if not verbose: popen_kwargs = dict(stdout = subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines = True) else: popen_kwargs = { } p = subprocess.Popen(args, **popen_kwargs) (stdout, stderr) = p.communicate() if verbose: print stdout print stderr print 'returned', p.returncode if p.returncode: if not verbose: print `args` print 'returned', p.returncode raise Exception('The command failed') p.returncode return stdout def clean(): if os.path.isdir(DISTDIR): rmrf(DISTDIR) if os.path.exists('build'): for dir in os.listdir('build'): if 'bdist' in dir: rmrf(opj('build', dir)) continue if os.path.isdir(BUILDDIR): rmrf(BUILDDIR) def dosubs(subs, infile, outfile = None): if outfile is None: stuff = infile else: stuff = open(infile, 'rt').read() for k in subs: stuff = re.sub('%%' + k + '%%', '%s' % (subs[k],), stuff) if outfile: open(outfile, 'w').write(stuff) else: return stuff return outfile def windowsbuild(pkg, vals): clean() import py2exe defaults = { 'options': { 'py2exe': { 'optimize': 2, 'compressed': 1, 'dist_dir': DISTDIR + '/files' } }, 'windows': [], 'console': [], 'script_args': ('py2exe',) } opts = pkg.getpy2exeoptions(defaults) w = [] for i in opts['windows']: i['other_resources'] = [ (RT_MANIFEST, 1, WINXP_MANIFEST)] + i.get('other_resources', []) for k, v in (('icon_resources', [ (1, '%%ICONFILE%%')]), ('product_version', '%%VERSION%%'), ('version', '%%DQVERSION%%'), ('comments', '%%COMMENTS%%'), ('company_name', '%%URL%%'), ('copyright', '%%COPYRIGHT%%'), ('name', '%%NAME%%'), ('description', '%%DESCRIPTION%%')): if k not in i: i[k] = v continue w.append(i) opts['windows'] = w if 'RELEASE' not in vals: vals['RELEASE'] = 0 if 'OUTFILE' not in vals: if vals['RELEASE']: rstr = '-r' + repr(vals['RELEASE']) + '-' else: rstr = '' vals['OUTFILE'] = '%s%s-%s-%ssetup.exe' % (vals['OUTFILEPREFIX'], vals['NAME'].lower(), vals['VERSION'], rstr) opts = eval(dosubs(vals, repr(opts))) if hasattr(pkg, 'pre_setup'): pkg.pre_setup(opts) distutils.core.setup(**opts) distdir = opts['options']['py2exe']['dist_dir'] if hasattr(pkg, 'copyresources'): pkg.copyresources(distdir) if hasattr(pkg, 'finalize'): pkg.finalize(distdir) check_no_sources(distdir) vals['GUID'] = vals['GUID'].replace('{', '{{') while vals['OUTFILE'].endswith('.exe'): vals['OUTFILE'] = vals['OUTFILE'][:-4] if 'ISSFILE' in vals: dosubs(vals, vals['ISSFILE'], opj(DISTDIR, opb(vals['ISSFILE']))) run('c:\\program files\\inno setup 5\\compil32.exe', '/cc', opj(DISTDIR, opb(vals['ISSFILE']))) elif 'NSISFILES' in vals: nsis_configs = vals['NSISFILES'] _targetdir = os.path.abspath(distdir) cwd = os.getcwd() for nsis_config in nsis_configs: (nsis_fullpath, nsis_opts) = nsis_config (nsis_dir, nsis_file) = ops(nsis_fullpath) os.chdir(nsis_dir) if hasattr(pkg, 'prep_nsis'): pkg.prep_nsis(nsis_dir, _targetdir, nsis_opts, tag = tag) print '*** running makensis with options %r ***' % (nsis_opts,) run(PATH_NSIS, '/V4', nsis_file) os.chdir(cwd) if hasattr(pkg, 'post_nsis'): pkg.post_nsis(_targetdir, nsis_opts) continue else: print '*** no installer (NSIS/InnoSetup) key present, skipping installer build ***' if pkg.upload_files: if hasattr(pkg, 'prep_upload'): distdir = pkg.prep_upload(distdir) if hasattr(pkg, 'upload'): pkg.upload(distdir) if hasattr(pkg, 'post_upload'): pkg.post_upload(distdir, tag) else: print '*** upload disabled ***' print '*** windowsbuild finished ***' def linuxcommonbuild(pkg, vals): clean() defaults = { 'options': { 'cxfreeze': { 'compressed': 1, 'optimize': 2, 'dist_dir': DISTDIR + '/files', 'base-name': 'Console', 'init-script': 'ConsoleSetLibPath.py' } } } opts = pkg.getcxfreezeoptions(defaults) for app in opts['app']: if 'dest_base' not in app: app['dest_base'] = opb(os.path.splitext(app['script'])[0]) if 'lib_path' not in app: app['lib_path'] = '/usr/lib/%%NAME%%-%%VERSION%%' if 'bin_path' not in app: app['bin_path'] = '/usr/bin/' + app['dest_base'] if 'bin_ver_path' not in app: app['bin_ver_path'] = '/usr/bin/' + app['dest_base'] + '-%%VERSION%%' continue if 'RPMNAME' not in vals: vals['RPMNAME'] = vals['NAME'].lower() if 'RPMVERSION' not in vals: vals['RPMVERSION'] = vals['VERSION'].lower().replace('-', '.') opts = eval(dosubs(vals, repr(opts))) app = opts['app'][0] args = [ opj(PATH_CXFREEZE, 'FreezePython')] if opts['options']['cxfreeze']['compressed']: args.append('-c') o = opts['options']['cxfreeze']['optimize'] if o == 1: args.append('-O') if o == 2: args.append('-OO') args.append('--base-name=%s' % opts['options']['cxfreeze']['base-name']) args.append('--init-script=%s' % opts['options']['cxfreeze']['init-script']) if 'includes' in opts['options']['cxfreeze']: args.append('--include-modules=' + ','.join(opts['options']['cxfreeze']['includes'])) args.append('--target-dir=%s' % (opj(opts['options']['cxfreeze']['dist_dir'], app['lib_path'][1:]),)) args.append('--target-name=%s' % (app['dest_base'],)) args.append(app['script']) run(*args) distdir = opj(opts['options']['cxfreeze']['dist_dir'], app['lib_path'][1:]) if hasattr(pkg, 'copyresources'): pkg.copyresources(distdir) for f in ('bin_path', 'bin_ver_path'): p = opj(opts['options']['cxfreeze']['dist_dir'], app[f][1:]) if not os.path.isdir(opd(p)): os.makedirs(opd(p)) open(p, 'wt').write('#!/bin/sh\n LD_LIBRARY_PATH=%s:$LD_LIBRARY_PATH exec %s "$@"\n' % (app['lib_path'], opj(app['lib_path'], app['dest_base']))) os.chmod(p, 365) copy = { } for so in recursiveglob(opj(opts['options']['cxfreeze']['dist_dir'], '*.so')) + recursiveglob(opj(opts['options']['cxfreeze']['dist_dir'], app['dest_base'])): for line in os.popen('ldd ' + so, 'r'): line = line.split() if line[-2].startswith('/usr/lib/wxPython-') or line[-2].startswith('/usr/lib/libpython'): pd = opd(so) libs = copy.get(pd, []) if line[2] not in libs: copy[pd] = libs + [ line[2]] line[2] not in libs for d in copy: for lib in copy[d]: print lib, '==>', d shutil.copy2(lib, d) for so in recursiveglob(opj(opts['options']['cxfreeze']['dist_dir'], '*.so')): run('chrpath', '-d', so, verbose = False) run('strip', so, verbose = False) if hasattr(pkg, 'finalize'): pkg.finalize(distdir) return opts def linuxrpmbuild(pkg, vals): opts = linuxcommonbuild(pkg, vals) import tarfile distfilesdir = opj(opts['options']['cxfreeze']['dist_dir']) distdir = opd(distfilesdir) builddir = opj(distdir, BUILDDIR) os.mkdir(builddir) tf = tarfile.open(opj(builddir, 'dist.tar'), 'w') tf.add(distfilesdir, '', recursive = True) tf.close() fl = open(opj(builddir, 'FILELIST'), 'wt') for f in recursiveglob(opj(distfilesdir, '*')): print >>fl, f[len(distfilesdir):] fl.close() dosubs(vals, vals['SPECFILE'], opj(builddir, opb(vals['SPECFILE']))) n = '%s-%s' % (vals['RPMNAME'], vals['RPMVERSION']) tf = tarfile.open(opj(builddir, n + '.tar.gz'), 'w:gz') tf.add(opj(builddir, 'dist.tar'), opj(n, 'dist.tar')) tf.add(opj(builddir, 'FILELIST'), opj(n, 'FILELIST')) tf.add(opj(builddir, opb(vals['SPECFILE'])), opb(vals['SPECFILE'])) tf.close() rpmdir = opj(builddir, 'rpmtopdir') os.mkdir(rpmdir) for i in ('BUILD', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS'): os.mkdir(opj(rpmdir, i)) run('rpmbuild', '-ta', '--define=_topdir ' + os.path.abspath(rpmdir), opj(builddir, n + '.tar.gz')) for rpm in recursiveglob(opj(rpmdir, 'RPMS', '*.rpm')): shutil.copy2(rpm, distdir) def linuxdebbuild(pkg, vals): opts = linuxcommonbuild(pkg, vals) distfilesdir = opj(opts['options']['cxfreeze']['dist_dir']) distdir = opd(distfilesdir) builddir = opj(distdir, BUILDDIR) os.mkdir(builddir) _debiandir = opj(builddir, 'debian') _debianbitpimdir = opj(_debiandir, 'bitpim') shutil.copytree(opj('packaging', 'debian'), _debiandir) file(opj(_debiandir, 'versionhistory.htm'), 'wt').write(zipfile.ZipFile(opj('resources', 'bitpim.htb'), 'r').read('versionhistory.htm')) shutil.copytree(distfilesdir, _debianbitpimdir) for _file in ('changelog', 'postinst', 'postrm'): _filename = opj(_debiandir, _file) dosubs(vals, _filename, _filename) print 'Building deb package' _pwd = os.getcwd() os.chdir(builddir) run(opj('debian', 'rules'), 'binary') os.chdir(_pwd) def linuxebuildbuild(pkg, vals): opts = linuxcommonbuild(pkg, vals) distfilesdir = opj(opts['options']['cxfreeze']['dist_dir']) distdir = opd(distfilesdir) builddir = opj(distdir, BUILDDIR) os.mkdir(builddir) _pwd = os.getcwd() vals['FILESDIR'] = os.path.abspath(distfilesdir) vals['BUILDDIR'] = os.path.abspath(builddir) _portage_dist_dir = '/usr/portage/distfiles' _portage_overlay_bitpim_dir = '/usr/local/portage/app-mobilephone/bitpim' _portage_packages_dir = '/usr/portage/packages/All' os.chdir(distfilesdir) _basename = opts['app'][0]['dest_base'] run('tar', 'cjf', opj(_portage_dist_dir, '%s-%s.tar.bz2' % (_basename, vals['VERSION'])), '.') os.chdir(_pwd) _ebuildfile = opj(_portage_overlay_bitpim_dir, '%s-%s.ebuild' % (_basename, vals['VERSION'])) shutil.copy2(opj('packaging', 'gentoo', '%s.ebuild' % _basename), _ebuildfile) dosubs(vals, _ebuildfile, _ebuildfile) os.chdir(_portage_overlay_bitpim_dir) run('ebuild', _ebuildfile, 'digest', 'package', 'clean') os.chdir(_pwd) shutil.copy2(opj(_portage_packages_dir, '%s-%s.tbz2' % (_basename, vals['VERSION'])), distdir) def macbuild(pkg, vals): opts = '' if not pkg.upload_files: opts += ' --argv-inject="--noupdate"' retval = os.system('%s build/mac/build-appbundle.py py2app %s' % (sys.executable, opts)) if retval != 0: print 'Error building app bundle!' sys.exit(1) if pkg.upload_files: if hasattr(pkg, 'prep_upload'): distdir = pkg.prep_upload(os.path.abspath(os.path.join('.', 'dist', 'Digsby.app'))) os.rename(os.path.join('.', 'dist', 'manifest.mac'), os.path.join(distdir, 'manifest.mac')) print 'distdir is: ' + distdir if hasattr(pkg, 'upload'): pkg.upload(distdir) if hasattr(pkg, 'post_upload'): pkg.post_upload(distdir, 'mac') else: print '*** upload disabled ***' def sanitycheck(): if sys.platform == 'win32': print 'py2exe version', import py2exe expect = '0.6.6' print ' OK' if sys.platform == 'darwin': print 'py2app version', import py2app expect = '0.3.6' print ' OK' if sys.platform.startswith('linux'): print 'cx_Freeze', fname = opj(PATH_CXFREEZE, 'FreezePython') if not os.path.exists(fname): raise Exception("Can't find " + fname) os.path.exists(fname) print ' OK' def formatexception(excinfo = None, lastframes = 8): if excinfo is None: excinfo = sys.exc_info() s = StringIO.StringIO() traceback.print_exception(*excinfo, **{ 'file': s }) tb = excinfo[2] while True: if not tb.tb_next: break tb = tb.tb_next stack = [] f = tb.tb_frame while f: stack.append(f) f = f.f_back stack.reverse() if len(stack) > lastframes: stack = stack[-lastframes:] print >>s, '\nVariables by last %d frames, innermost last' % (lastframes,) for frame in stack: print >>s, '' print >>s, 'Frame %s in %s at line %s' % (frame.f_code.co_name, frame.f_code.co_filename, frame.f_lineno) for key, value in frame.f_locals.items(): if type(value) == type(sys): continue print >>s, '%15s = ' % (key,), try: if type(value) == type({ }): kk = value.keys() kk.sort() print >>s, 'Keys', kk print >>s, '%15s ' % ('',), print >>s, `value`[:80] continue print >>s, '(Exception occurred printing value)' continue return s.getvalue() def setupconfig(): global _theconfig import ConfigParser _theconfig = ConfigParser.RawConfigParser() _theconfig.read([ os.path.expanduser('~/.makedist_py.ini')]) def getconfig(key, default = None): if _theconfig.has_option('default', key): return _theconfig.get('default', key) return default def setconfig(key, value): _theconfig.set('default', key, value) def saveconfig(): _theconfig.write(open(os.path.expanduser('~/.makedist_py.ini'), 'wt')) def makeconfig(key, description): while True: print description v = getconfig(key) if v is not None: print 'DEFAULT (hit return):', v entered = raw_input('--> ') if len(entered): setconfig(key, entered) saveconfig() return entered if len(v) and len(entered) == 0: return v print 'You must enter a value' continue len(entered) tag = None def main(): global tag __start = time.clock() def eh(*args): print >>sys.stderr, formatexception(args) sys.exit(127) sys.excepthook = eh try: (_options, _args) = getopt.gnu_getopt(sys.argv[1:], 'p:v:l:', [ 'upload', 'noinstaller', 'tag=']) if _args: raise getopt.GetoptError('Invalid argument') _args _invalid_opt = False except getopt.GetoptError: _error_str = sys.exc_info()[1].msg _invalid_opt = True if _invalid_opt: print _error_str print 'Usage: %s [-p <package module>] [-v <version>] [-l redhat|debian|gentoo]' % sys.argv[0] sys.exit(1) pkg = 'src/package.py' _thisversion = None _platformname = None upload_files = False installer = True for _k, _v in _options: if _k == '-p': pkg = _v continue if _k == '-v': _thisversion = _v continue if _k == '-l': _platformname = _v.lower() continue if _k == '--upload': upload_files = True continue if _k == '--noinstaller': installer = False continue if _k == '--tag': tag = _v print 'Installer will have tag %r' % tag continue print 'Using package file', pkg sys.path = [ os.path.abspath(os.path.dirname(pkg))] + sys.path pkg = __import__(os.path.splitext(os.path.basename(pkg))[0]) pkg.upload_files = upload_files pkg.build_installer = installer if _thisversion: pkg.setversion(_thisversion) sanitycheck() if hasattr(pkg, 'sanitycheck'): pkg.sanitycheck() if hasattr(pkg, 'ensureofficial'): pkg.ensureofficial() vals = pkg.getvals() print 'version', vals['VERSION'] if 'OUTFILEPREFIX' not in vals: vals['OUTFILEPREFIX'] = '' if 'GUID' not in vals: raise Exception('You must supply a guid in the vals') 'GUID' not in vals setupconfig() if 'PUBLISHER' not in vals: vals['PUBLISHER'] = makeconfig('PUBLISHER', 'Enter your name and email address as the packager/publisher of this build\nFor example Joe Acme <joe.acme@example.com>') vals['BUILDDATETIME'] = email.Utils.formatdate(time.time(), True) build_func = None if sys.platform == 'win32': build_func = windowsbuild elif sys.platform.startswith('linux'): if not _platformname: import platform _platformname = platform.dist()[0].lower() if _platformname in ('redhat', 'suse', 'mandrake'): build_func = linuxrpmbuild elif _platformname == 'debian': build_func = linuxdebbuild elif _platformname == 'gentoo': build_func = linuxebuildbuild else: raise Exception("Don't know what to do with " + `platform.dist()`) _platformname in ('redhat', 'suse', 'mandrake') if sys.platform == 'darwin': build_func = macbuild else: print 'Unknown platform', sys.platform try: build_func(pkg, vals) finally: if hasattr(pkg, 'cleanup'): pkg.cleanup() __end = time.clock() __duration = __end - __start nicetimecount = nicetimecount import util print 'Duration: %s (%s)' % (nicetimecount(__duration), __duration) disallowed_extensions = [ e.lower() for e in [ '.py', '.pyc', '.cpp', '.c', '.h', '.erl', '.hrl', '.php', '.cs', '.pl', '.gitignore'] ] def check_no_sources(distdir): for root, dirs, files in os.walk(distdir): for file in files: for ext in disallowed_extensions: if file.lower().endswith(ext): raise AssertionError('found a %s file in %s: %s' % (ext, distdir, os.path.join(root, file))) file.lower().endswith(ext) if __name__ == '__main__': try: main() except ImportError: [] [] [] from traceback import print_exc import sys print_exc() from pprint import pformat print >>sys.stderr, '\n\nsys.path = \n%s' % pformat(sys.path) except: []<EXCEPTION MATCH>ImportError []