home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / makedist.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  22.4 KB  |  708 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import os
  5. import shutil
  6. import sys
  7. import glob
  8. import re
  9. import StringIO
  10. import traceback
  11. import distutils.core as distutils
  12. import email.Utils as email
  13. import time
  14. import zipfile
  15. import getopt
  16. import subprocess
  17. import config
  18. sys.setrecursionlimit(5000)
  19. sys.path += map(os.path.abspath, [
  20.     './src',
  21.     './ext',
  22.     './ext/' + config.platformName,
  23.     './lib',
  24.     './platlib/' + config.platformName])
  25. import digsbypaths
  26. sys.path.insert(0, digsbypaths.get_platlib_dir())
  27. ops = os.path.split
  28. opj = os.path.join
  29. opd = os.path.dirname
  30. opb = os.path.basename
  31. BUILDDIR = 'packagebuild'
  32. DISTDIR = 'dist'
  33. PATH_CXFREEZE = '/opt/cx_Freeze-3.0.3'
  34. program_files = os.environ.get('ProgramFiles(x86)', os.environ.get('ProgramFiles', 'c:\\Program Files'))
  35. PATH_INNOSETUP = opj(program_files, 'inno setup 5\\compil32.exe')
  36. PATH_NSIS = opj(program_files, 'nsis\\makensis.exe')
  37. if sys.platform.startswith('win'):
  38.     
  39.     try:
  40.         pass
  41.     except AssertionError:
  42.         sys
  43.         sys
  44.         print >>sys.stderr, 'NSIS not found: %r' % PATH_NSIS
  45.     except:
  46.         sys<EXCEPTION MATCH>AssertionError
  47.     
  48.  
  49. sys
  50. RT_MANIFEST = 24
  51. DEBUG = hasattr(sys, 'gettotalrefcount')
  52. if DEBUG:
  53.     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>'
  54. else:
  55.     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    '
  56.  
  57. def rmrf(path):
  58.     if sys.platform != 'win32':
  59.         os.system('find "' + path + '" -type d -print0 | xargs -0 chmod +w ; true')
  60.     
  61.     print 'removing: %r' % path
  62.     entries = os.listdir(path)
  63.     for e in entries:
  64.         fullname = opj(path, e)
  65.         if os.path.isdir(fullname):
  66.             rmrf(fullname)
  67.             continue
  68.         os.remove(fullname)
  69.     
  70.     os.rmdir(path)
  71.  
  72.  
  73. def recursiveglob(pattern):
  74.     res = []
  75.     dir = opd(pattern)
  76.     if len(dir):
  77.         for d in os.listdir(dir):
  78.             if os.path.isdir(opj(dir, d)):
  79.                 res += recursiveglob(opj(dir, d, opb(pattern)))
  80.                 continue
  81.         
  82.     
  83.     return [] + _[1]
  84.  
  85.  
  86. def run(*args, **kwargs):
  87.     verbose = kwargs.get('verbose', True)
  88.     if verbose:
  89.         print `args`
  90.     
  91.     if not verbose:
  92.         popen_kwargs = dict(stdout = subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines = True)
  93.     else:
  94.         popen_kwargs = { }
  95.     p = subprocess.Popen(args, **popen_kwargs)
  96.     (stdout, stderr) = p.communicate()
  97.     if verbose:
  98.         print stdout
  99.         print stderr
  100.         print 'returned', p.returncode
  101.     
  102.     if p.returncode:
  103.         if not verbose:
  104.             print `args`
  105.             print 'returned', p.returncode
  106.         
  107.         raise Exception('The command failed')
  108.     p.returncode
  109.     return stdout
  110.  
  111.  
  112. def clean():
  113.     if os.path.isdir(DISTDIR):
  114.         rmrf(DISTDIR)
  115.     
  116.     if os.path.exists('build'):
  117.         for dir in os.listdir('build'):
  118.             if 'bdist' in dir:
  119.                 rmrf(opj('build', dir))
  120.                 continue
  121.         
  122.     
  123.     if os.path.isdir(BUILDDIR):
  124.         rmrf(BUILDDIR)
  125.     
  126.  
  127.  
  128. def dosubs(subs, infile, outfile = None):
  129.     if outfile is None:
  130.         stuff = infile
  131.     else:
  132.         stuff = open(infile, 'rt').read()
  133.     for k in subs:
  134.         stuff = re.sub('%%' + k + '%%', '%s' % (subs[k],), stuff)
  135.     
  136.     if outfile:
  137.         open(outfile, 'w').write(stuff)
  138.     else:
  139.         return stuff
  140.     return outfile
  141.  
  142.  
  143. def windowsbuild(pkg, vals):
  144.     clean()
  145.     import py2exe
  146.     defaults = {
  147.         'options': {
  148.             'py2exe': {
  149.                 'optimize': 2,
  150.                 'compressed': 1,
  151.                 'dist_dir': DISTDIR + '/files' } },
  152.         'windows': [],
  153.         'console': [],
  154.         'script_args': ('py2exe',) }
  155.     opts = pkg.getpy2exeoptions(defaults)
  156.     w = []
  157.     for i in opts['windows']:
  158.         i['other_resources'] = [
  159.             (RT_MANIFEST, 1, WINXP_MANIFEST)] + i.get('other_resources', [])
  160.         for k, v in (('icon_resources', [
  161.             (1, '%%ICONFILE%%')]), ('product_version', '%%VERSION%%'), ('version', '%%DQVERSION%%'), ('comments', '%%COMMENTS%%'), ('company_name', '%%URL%%'), ('copyright', '%%COPYRIGHT%%'), ('name', '%%NAME%%'), ('description', '%%DESCRIPTION%%')):
  162.             if k not in i:
  163.                 i[k] = v
  164.                 continue
  165.         
  166.         w.append(i)
  167.     
  168.     opts['windows'] = w
  169.     if 'RELEASE' not in vals:
  170.         vals['RELEASE'] = 0
  171.     
  172.     if 'OUTFILE' not in vals:
  173.         if vals['RELEASE']:
  174.             rstr = '-r' + repr(vals['RELEASE']) + '-'
  175.         else:
  176.             rstr = ''
  177.         vals['OUTFILE'] = '%s%s-%s-%ssetup.exe' % (vals['OUTFILEPREFIX'], vals['NAME'].lower(), vals['VERSION'], rstr)
  178.     
  179.     opts = eval(dosubs(vals, repr(opts)))
  180.     if hasattr(pkg, 'pre_setup'):
  181.         pkg.pre_setup(opts)
  182.     
  183.     distutils.core.setup(**opts)
  184.     distdir = opts['options']['py2exe']['dist_dir']
  185.     if hasattr(pkg, 'copyresources'):
  186.         pkg.copyresources(distdir)
  187.     
  188.     if hasattr(pkg, 'finalize'):
  189.         pkg.finalize(distdir)
  190.     
  191.     check_no_sources(distdir)
  192.     vals['GUID'] = vals['GUID'].replace('{', '{{')
  193.     while vals['OUTFILE'].endswith('.exe'):
  194.         vals['OUTFILE'] = vals['OUTFILE'][:-4]
  195.     if 'ISSFILE' in vals:
  196.         dosubs(vals, vals['ISSFILE'], opj(DISTDIR, opb(vals['ISSFILE'])))
  197.         run('c:\\program files\\inno setup 5\\compil32.exe', '/cc', opj(DISTDIR, opb(vals['ISSFILE'])))
  198.     elif 'NSISFILES' in vals:
  199.         nsis_configs = vals['NSISFILES']
  200.         _targetdir = os.path.abspath(distdir)
  201.         cwd = os.getcwd()
  202.         for nsis_config in nsis_configs:
  203.             (nsis_fullpath, nsis_opts) = nsis_config
  204.             (nsis_dir, nsis_file) = ops(nsis_fullpath)
  205.             os.chdir(nsis_dir)
  206.             if hasattr(pkg, 'prep_nsis'):
  207.                 pkg.prep_nsis(nsis_dir, _targetdir, nsis_opts, tag = tag)
  208.             
  209.             print '*** running makensis with options %r ***' % (nsis_opts,)
  210.             run(PATH_NSIS, '/V4', nsis_file)
  211.             os.chdir(cwd)
  212.             if hasattr(pkg, 'post_nsis'):
  213.                 pkg.post_nsis(_targetdir, nsis_opts)
  214.                 continue
  215.         
  216.     else:
  217.         print '*** no installer (NSIS/InnoSetup) key present, skipping installer build ***'
  218.     if pkg.upload_files:
  219.         if hasattr(pkg, 'prep_upload'):
  220.             distdir = pkg.prep_upload(distdir)
  221.         
  222.         if hasattr(pkg, 'upload'):
  223.             pkg.upload(distdir)
  224.         
  225.         if hasattr(pkg, 'post_upload'):
  226.             pkg.post_upload(distdir, tag)
  227.         
  228.     else:
  229.         print '*** upload disabled ***'
  230.     print '*** windowsbuild finished ***'
  231.  
  232.  
  233. def linuxcommonbuild(pkg, vals):
  234.     clean()
  235.     defaults = {
  236.         'options': {
  237.             'cxfreeze': {
  238.                 'compressed': 1,
  239.                 'optimize': 2,
  240.                 'dist_dir': DISTDIR + '/files',
  241.                 'base-name': 'Console',
  242.                 'init-script': 'ConsoleSetLibPath.py' } } }
  243.     opts = pkg.getcxfreezeoptions(defaults)
  244.     for app in opts['app']:
  245.         if 'dest_base' not in app:
  246.             app['dest_base'] = opb(os.path.splitext(app['script'])[0])
  247.         
  248.         if 'lib_path' not in app:
  249.             app['lib_path'] = '/usr/lib/%%NAME%%-%%VERSION%%'
  250.         
  251.         if 'bin_path' not in app:
  252.             app['bin_path'] = '/usr/bin/' + app['dest_base']
  253.         
  254.         if 'bin_ver_path' not in app:
  255.             app['bin_ver_path'] = '/usr/bin/' + app['dest_base'] + '-%%VERSION%%'
  256.             continue
  257.     
  258.     if 'RPMNAME' not in vals:
  259.         vals['RPMNAME'] = vals['NAME'].lower()
  260.     
  261.     if 'RPMVERSION' not in vals:
  262.         vals['RPMVERSION'] = vals['VERSION'].lower().replace('-', '.')
  263.     
  264.     opts = eval(dosubs(vals, repr(opts)))
  265.     app = opts['app'][0]
  266.     args = [
  267.         opj(PATH_CXFREEZE, 'FreezePython')]
  268.     if opts['options']['cxfreeze']['compressed']:
  269.         args.append('-c')
  270.     
  271.     o = opts['options']['cxfreeze']['optimize']
  272.     if o == 1:
  273.         args.append('-O')
  274.     
  275.     if o == 2:
  276.         args.append('-OO')
  277.     
  278.     args.append('--base-name=%s' % opts['options']['cxfreeze']['base-name'])
  279.     args.append('--init-script=%s' % opts['options']['cxfreeze']['init-script'])
  280.     if 'includes' in opts['options']['cxfreeze']:
  281.         args.append('--include-modules=' + ','.join(opts['options']['cxfreeze']['includes']))
  282.     
  283.     args.append('--target-dir=%s' % (opj(opts['options']['cxfreeze']['dist_dir'], app['lib_path'][1:]),))
  284.     args.append('--target-name=%s' % (app['dest_base'],))
  285.     args.append(app['script'])
  286.     run(*args)
  287.     distdir = opj(opts['options']['cxfreeze']['dist_dir'], app['lib_path'][1:])
  288.     if hasattr(pkg, 'copyresources'):
  289.         pkg.copyresources(distdir)
  290.     
  291.     for f in ('bin_path', 'bin_ver_path'):
  292.         p = opj(opts['options']['cxfreeze']['dist_dir'], app[f][1:])
  293.         if not os.path.isdir(opd(p)):
  294.             os.makedirs(opd(p))
  295.         
  296.         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'])))
  297.         os.chmod(p, 365)
  298.     
  299.     copy = { }
  300.     for so in recursiveglob(opj(opts['options']['cxfreeze']['dist_dir'], '*.so')) + recursiveglob(opj(opts['options']['cxfreeze']['dist_dir'], app['dest_base'])):
  301.         for line in os.popen('ldd ' + so, 'r'):
  302.             line = line.split()
  303.             if line[-2].startswith('/usr/lib/wxPython-') or line[-2].startswith('/usr/lib/libpython'):
  304.                 pd = opd(so)
  305.                 libs = copy.get(pd, [])
  306.                 if line[2] not in libs:
  307.                     copy[pd] = libs + [
  308.                         line[2]]
  309.                 
  310.             line[2] not in libs
  311.         
  312.     
  313.     for d in copy:
  314.         for lib in copy[d]:
  315.             print lib, '==>', d
  316.             shutil.copy2(lib, d)
  317.         
  318.     
  319.     for so in recursiveglob(opj(opts['options']['cxfreeze']['dist_dir'], '*.so')):
  320.         run('chrpath', '-d', so, verbose = False)
  321.         run('strip', so, verbose = False)
  322.     
  323.     if hasattr(pkg, 'finalize'):
  324.         pkg.finalize(distdir)
  325.     
  326.     return opts
  327.  
  328.  
  329. def linuxrpmbuild(pkg, vals):
  330.     opts = linuxcommonbuild(pkg, vals)
  331.     import tarfile
  332.     distfilesdir = opj(opts['options']['cxfreeze']['dist_dir'])
  333.     distdir = opd(distfilesdir)
  334.     builddir = opj(distdir, BUILDDIR)
  335.     os.mkdir(builddir)
  336.     tf = tarfile.open(opj(builddir, 'dist.tar'), 'w')
  337.     tf.add(distfilesdir, '', recursive = True)
  338.     tf.close()
  339.     fl = open(opj(builddir, 'FILELIST'), 'wt')
  340.     for f in recursiveglob(opj(distfilesdir, '*')):
  341.         print >>fl, f[len(distfilesdir):]
  342.     
  343.     fl.close()
  344.     dosubs(vals, vals['SPECFILE'], opj(builddir, opb(vals['SPECFILE'])))
  345.     n = '%s-%s' % (vals['RPMNAME'], vals['RPMVERSION'])
  346.     tf = tarfile.open(opj(builddir, n + '.tar.gz'), 'w:gz')
  347.     tf.add(opj(builddir, 'dist.tar'), opj(n, 'dist.tar'))
  348.     tf.add(opj(builddir, 'FILELIST'), opj(n, 'FILELIST'))
  349.     tf.add(opj(builddir, opb(vals['SPECFILE'])), opb(vals['SPECFILE']))
  350.     tf.close()
  351.     rpmdir = opj(builddir, 'rpmtopdir')
  352.     os.mkdir(rpmdir)
  353.     for i in ('BUILD', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS'):
  354.         os.mkdir(opj(rpmdir, i))
  355.     
  356.     run('rpmbuild', '-ta', '--define=_topdir ' + os.path.abspath(rpmdir), opj(builddir, n + '.tar.gz'))
  357.     for rpm in recursiveglob(opj(rpmdir, 'RPMS', '*.rpm')):
  358.         shutil.copy2(rpm, distdir)
  359.     
  360.  
  361.  
  362. def linuxdebbuild(pkg, vals):
  363.     opts = linuxcommonbuild(pkg, vals)
  364.     distfilesdir = opj(opts['options']['cxfreeze']['dist_dir'])
  365.     distdir = opd(distfilesdir)
  366.     builddir = opj(distdir, BUILDDIR)
  367.     os.mkdir(builddir)
  368.     _debiandir = opj(builddir, 'debian')
  369.     _debianbitpimdir = opj(_debiandir, 'bitpim')
  370.     shutil.copytree(opj('packaging', 'debian'), _debiandir)
  371.     file(opj(_debiandir, 'versionhistory.htm'), 'wt').write(zipfile.ZipFile(opj('resources', 'bitpim.htb'), 'r').read('versionhistory.htm'))
  372.     shutil.copytree(distfilesdir, _debianbitpimdir)
  373.     for _file in ('changelog', 'postinst', 'postrm'):
  374.         _filename = opj(_debiandir, _file)
  375.         dosubs(vals, _filename, _filename)
  376.     
  377.     print 'Building deb package'
  378.     _pwd = os.getcwd()
  379.     os.chdir(builddir)
  380.     run(opj('debian', 'rules'), 'binary')
  381.     os.chdir(_pwd)
  382.  
  383.  
  384. def linuxebuildbuild(pkg, vals):
  385.     opts = linuxcommonbuild(pkg, vals)
  386.     distfilesdir = opj(opts['options']['cxfreeze']['dist_dir'])
  387.     distdir = opd(distfilesdir)
  388.     builddir = opj(distdir, BUILDDIR)
  389.     os.mkdir(builddir)
  390.     _pwd = os.getcwd()
  391.     vals['FILESDIR'] = os.path.abspath(distfilesdir)
  392.     vals['BUILDDIR'] = os.path.abspath(builddir)
  393.     _portage_dist_dir = '/usr/portage/distfiles'
  394.     _portage_overlay_bitpim_dir = '/usr/local/portage/app-mobilephone/bitpim'
  395.     _portage_packages_dir = '/usr/portage/packages/All'
  396.     os.chdir(distfilesdir)
  397.     _basename = opts['app'][0]['dest_base']
  398.     run('tar', 'cjf', opj(_portage_dist_dir, '%s-%s.tar.bz2' % (_basename, vals['VERSION'])), '.')
  399.     os.chdir(_pwd)
  400.     _ebuildfile = opj(_portage_overlay_bitpim_dir, '%s-%s.ebuild' % (_basename, vals['VERSION']))
  401.     shutil.copy2(opj('packaging', 'gentoo', '%s.ebuild' % _basename), _ebuildfile)
  402.     dosubs(vals, _ebuildfile, _ebuildfile)
  403.     os.chdir(_portage_overlay_bitpim_dir)
  404.     run('ebuild', _ebuildfile, 'digest', 'package', 'clean')
  405.     os.chdir(_pwd)
  406.     shutil.copy2(opj(_portage_packages_dir, '%s-%s.tbz2' % (_basename, vals['VERSION'])), distdir)
  407.  
  408.  
  409. def macbuild(pkg, vals):
  410.     opts = ''
  411.     if not pkg.upload_files:
  412.         opts += ' --argv-inject="--noupdate"'
  413.     
  414.     retval = os.system('%s build/mac/build-appbundle.py py2app %s' % (sys.executable, opts))
  415.     if retval != 0:
  416.         print 'Error building app bundle!'
  417.         sys.exit(1)
  418.     
  419.     if pkg.upload_files:
  420.         if hasattr(pkg, 'prep_upload'):
  421.             distdir = pkg.prep_upload(os.path.abspath(os.path.join('.', 'dist', 'Digsby.app')))
  422.             os.rename(os.path.join('.', 'dist', 'manifest.mac'), os.path.join(distdir, 'manifest.mac'))
  423.             print 'distdir is: ' + distdir
  424.         
  425.         if hasattr(pkg, 'upload'):
  426.             pkg.upload(distdir)
  427.         
  428.         if hasattr(pkg, 'post_upload'):
  429.             pkg.post_upload(distdir, 'mac')
  430.         
  431.     else:
  432.         print '*** upload disabled ***'
  433.  
  434.  
  435. def sanitycheck():
  436.     if sys.platform == 'win32':
  437.         print 'py2exe version',
  438.         import py2exe
  439.         expect = '0.6.6'
  440.         print '  OK'
  441.     
  442.     if sys.platform == 'darwin':
  443.         print 'py2app version',
  444.         import py2app
  445.         expect = '0.3.6'
  446.         print '  OK'
  447.     
  448.     if sys.platform.startswith('linux'):
  449.         print 'cx_Freeze',
  450.         fname = opj(PATH_CXFREEZE, 'FreezePython')
  451.         if not os.path.exists(fname):
  452.             raise Exception("Can't find " + fname)
  453.         os.path.exists(fname)
  454.         print '  OK'
  455.     
  456.  
  457.  
  458. def formatexception(excinfo = None, lastframes = 8):
  459.     if excinfo is None:
  460.         excinfo = sys.exc_info()
  461.     
  462.     s = StringIO.StringIO()
  463.     traceback.print_exception(*excinfo, **{
  464.         'file': s })
  465.     tb = excinfo[2]
  466.     while True:
  467.         if not tb.tb_next:
  468.             break
  469.         
  470.         tb = tb.tb_next
  471.     stack = []
  472.     f = tb.tb_frame
  473.     while f:
  474.         stack.append(f)
  475.         f = f.f_back
  476.     stack.reverse()
  477.     if len(stack) > lastframes:
  478.         stack = stack[-lastframes:]
  479.     
  480.     print >>s, '\nVariables by last %d frames, innermost last' % (lastframes,)
  481.     for frame in stack:
  482.         print >>s, ''
  483.         print >>s, 'Frame %s in %s at line %s' % (frame.f_code.co_name, frame.f_code.co_filename, frame.f_lineno)
  484.         for key, value in frame.f_locals.items():
  485.             if type(value) == type(sys):
  486.                 continue
  487.             
  488.             print >>s, '%15s = ' % (key,),
  489.             
  490.             try:
  491.                 if type(value) == type({ }):
  492.                     kk = value.keys()
  493.                     kk.sort()
  494.                     print >>s, 'Keys', kk
  495.                     print >>s, '%15s   ' % ('',),
  496.                     print >>s, `value`[:80]
  497.             continue
  498.             print >>s, '(Exception occurred printing value)'
  499.             continue
  500.  
  501.         
  502.     
  503.     return s.getvalue()
  504.  
  505.  
  506. def setupconfig():
  507.     global _theconfig
  508.     import ConfigParser
  509.     _theconfig = ConfigParser.RawConfigParser()
  510.     _theconfig.read([
  511.         os.path.expanduser('~/.makedist_py.ini')])
  512.  
  513.  
  514. def getconfig(key, default = None):
  515.     if _theconfig.has_option('default', key):
  516.         return _theconfig.get('default', key)
  517.     return default
  518.  
  519.  
  520. def setconfig(key, value):
  521.     _theconfig.set('default', key, value)
  522.  
  523.  
  524. def saveconfig():
  525.     _theconfig.write(open(os.path.expanduser('~/.makedist_py.ini'), 'wt'))
  526.  
  527.  
  528. def makeconfig(key, description):
  529.     while True:
  530.         print description
  531.         v = getconfig(key)
  532.         if v is not None:
  533.             print 'DEFAULT (hit return):', v
  534.         
  535.         entered = raw_input('--> ')
  536.         if len(entered):
  537.             setconfig(key, entered)
  538.             saveconfig()
  539.             return entered
  540.         if len(v) and len(entered) == 0:
  541.             return v
  542.         print 'You must enter a value'
  543.         continue
  544.         len(entered)
  545.  
  546. tag = None
  547.  
  548. def main():
  549.     global tag
  550.     __start = time.clock()
  551.     
  552.     def eh(*args):
  553.         print >>sys.stderr, formatexception(args)
  554.         sys.exit(127)
  555.  
  556.     sys.excepthook = eh
  557.     
  558.     try:
  559.         (_options, _args) = getopt.gnu_getopt(sys.argv[1:], 'p:v:l:', [
  560.             'upload',
  561.             'noinstaller',
  562.             'tag='])
  563.         if _args:
  564.             raise getopt.GetoptError('Invalid argument')
  565.         _args
  566.         _invalid_opt = False
  567.     except getopt.GetoptError:
  568.         _error_str = sys.exc_info()[1].msg
  569.         _invalid_opt = True
  570.  
  571.     if _invalid_opt:
  572.         print _error_str
  573.         print 'Usage: %s [-p <package module>] [-v <version>] [-l redhat|debian|gentoo]' % sys.argv[0]
  574.         sys.exit(1)
  575.     
  576.     pkg = 'src/package.py'
  577.     _thisversion = None
  578.     _platformname = None
  579.     upload_files = False
  580.     installer = True
  581.     for _k, _v in _options:
  582.         if _k == '-p':
  583.             pkg = _v
  584.             continue
  585.         if _k == '-v':
  586.             _thisversion = _v
  587.             continue
  588.         if _k == '-l':
  589.             _platformname = _v.lower()
  590.             continue
  591.         if _k == '--upload':
  592.             upload_files = True
  593.             continue
  594.         if _k == '--noinstaller':
  595.             installer = False
  596.             continue
  597.         if _k == '--tag':
  598.             tag = _v
  599.             print 'Installer will have tag %r' % tag
  600.             continue
  601.     
  602.     print 'Using package file', pkg
  603.     sys.path = [
  604.         os.path.abspath(os.path.dirname(pkg))] + sys.path
  605.     pkg = __import__(os.path.splitext(os.path.basename(pkg))[0])
  606.     pkg.upload_files = upload_files
  607.     pkg.build_installer = installer
  608.     if _thisversion:
  609.         pkg.setversion(_thisversion)
  610.     
  611.     sanitycheck()
  612.     if hasattr(pkg, 'sanitycheck'):
  613.         pkg.sanitycheck()
  614.     
  615.     if hasattr(pkg, 'ensureofficial'):
  616.         pkg.ensureofficial()
  617.     
  618.     vals = pkg.getvals()
  619.     print 'version', vals['VERSION']
  620.     if 'OUTFILEPREFIX' not in vals:
  621.         vals['OUTFILEPREFIX'] = ''
  622.     
  623.     if 'GUID' not in vals:
  624.         raise Exception('You must supply a guid in the vals')
  625.     'GUID' not in vals
  626.     setupconfig()
  627.     if 'PUBLISHER' not in vals:
  628.         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>')
  629.     
  630.     vals['BUILDDATETIME'] = email.Utils.formatdate(time.time(), True)
  631.     build_func = None
  632.     if sys.platform == 'win32':
  633.         build_func = windowsbuild
  634.     elif sys.platform.startswith('linux'):
  635.         if not _platformname:
  636.             import platform
  637.             _platformname = platform.dist()[0].lower()
  638.         
  639.         if _platformname in ('redhat', 'suse', 'mandrake'):
  640.             build_func = linuxrpmbuild
  641.         elif _platformname == 'debian':
  642.             build_func = linuxdebbuild
  643.         elif _platformname == 'gentoo':
  644.             build_func = linuxebuildbuild
  645.         else:
  646.             raise Exception("Don't know what to do with " + `platform.dist()`)
  647.     _platformname in ('redhat', 'suse', 'mandrake')
  648.     if sys.platform == 'darwin':
  649.         build_func = macbuild
  650.     else:
  651.         print 'Unknown platform', sys.platform
  652.     
  653.     try:
  654.         build_func(pkg, vals)
  655.     finally:
  656.         if hasattr(pkg, 'cleanup'):
  657.             pkg.cleanup()
  658.         
  659.  
  660.     __end = time.clock()
  661.     __duration = __end - __start
  662.     nicetimecount = nicetimecount
  663.     import util
  664.     print 'Duration: %s (%s)' % (nicetimecount(__duration), __duration)
  665.  
  666. disallowed_extensions = [ e.lower() for e in [
  667.     '.py',
  668.     '.pyc',
  669.     '.cpp',
  670.     '.c',
  671.     '.h',
  672.     '.erl',
  673.     '.hrl',
  674.     '.php',
  675.     '.cs',
  676.     '.pl',
  677.     '.gitignore'] ]
  678.  
  679. def check_no_sources(distdir):
  680.     for root, dirs, files in os.walk(distdir):
  681.         for file in files:
  682.             for ext in disallowed_extensions:
  683.                 if file.lower().endswith(ext):
  684.                     raise AssertionError('found a %s file in %s: %s' % (ext, distdir, os.path.join(root, file)))
  685.                 file.lower().endswith(ext)
  686.             
  687.         
  688.     
  689.  
  690. if __name__ == '__main__':
  691.     
  692.     try:
  693.         main()
  694.     except ImportError:
  695.         []
  696.         []
  697.         []
  698.         from traceback import print_exc
  699.         import sys
  700.         print_exc()
  701.         from pprint import pformat
  702.         print >>sys.stderr, '\n\nsys.path = \n%s' % pformat(sys.path)
  703.     except:
  704.         []<EXCEPTION MATCH>ImportError
  705.     
  706.  
  707. []
  708.