home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2407 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  10.0 KB  |  284 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from distutils.command.build_ext import build_ext as _du_build_ext
  5.  
  6. try:
  7.     from Pyrex.Distutils.build_ext import build_ext as _build_ext
  8. except ImportError:
  9.     _build_ext = _du_build_ext
  10.  
  11. import os
  12. import sys
  13. from distutils.file_util import copy_file
  14. from setuptools.extension import Library
  15. from distutils.ccompiler import new_compiler
  16. from distutils.sysconfig import customize_compiler, get_config_var
  17. get_config_var('LDSHARED')
  18. from distutils.sysconfig import _config_vars
  19. from distutils import log
  20. from distutils.errors import *
  21. have_rtld = False
  22. use_stubs = False
  23. libtype = 'shared'
  24. if sys.platform == 'darwin':
  25.     use_stubs = True
  26. elif os.name != 'nt':
  27.     
  28.     try:
  29.         from dl import RTLD_NOW
  30.         have_rtld = True
  31.         use_stubs = True
  32.     except ImportError:
  33.         pass
  34.     except:
  35.         None<EXCEPTION MATCH>ImportError
  36.     
  37.  
  38. None<EXCEPTION MATCH>ImportError
  39.  
  40. def if_dl(s):
  41.     if have_rtld:
  42.         return s
  43.     return ''
  44.  
  45.  
  46. class build_ext(_build_ext):
  47.     
  48.     def run(self):
  49.         old_inplace = self.inplace
  50.         self.inplace = 0
  51.         _build_ext.run(self)
  52.         self.inplace = old_inplace
  53.         if old_inplace:
  54.             self.copy_extensions_to_source()
  55.         
  56.  
  57.     
  58.     def copy_extensions_to_source(self):
  59.         build_py = self.get_finalized_command('build_py')
  60.         for ext in self.extensions:
  61.             fullname = self.get_ext_fullname(ext.name)
  62.             filename = self.get_ext_filename(fullname)
  63.             modpath = fullname.split('.')
  64.             package = '.'.join(modpath[:-1])
  65.             package_dir = build_py.get_package_dir(package)
  66.             dest_filename = os.path.join(package_dir, os.path.basename(filename))
  67.             src_filename = os.path.join(self.build_lib, filename)
  68.             copy_file(src_filename, dest_filename, verbose = self.verbose, dry_run = self.dry_run)
  69.             if ext._needs_stub:
  70.                 if not package_dir:
  71.                     pass
  72.                 self.write_stub(os.curdir, ext, True)
  73.                 continue
  74.         
  75.  
  76.     if _build_ext is not _du_build_ext and not hasattr(_build_ext, 'pyrex_sources'):
  77.         
  78.         def swig_sources(self, sources, *otherargs):
  79.             if not _build_ext.swig_sources(self, sources):
  80.                 pass
  81.             sources = sources
  82.             return _du_build_ext.swig_sources(self, sources, *otherargs)
  83.  
  84.     
  85.     
  86.     def get_ext_filename(self, fullname):
  87.         filename = _build_ext.get_ext_filename(self, fullname)
  88.         ext = self.ext_map[fullname]
  89.         if isinstance(ext, Library):
  90.             (fn, ext) = os.path.splitext(filename)
  91.             return self.shlib_compiler.library_filename(fn, libtype)
  92.         if use_stubs and ext._links_to_dynamic:
  93.             (d, fn) = os.path.split(filename)
  94.             return os.path.join(d, 'dl-' + fn)
  95.         return filename
  96.  
  97.     
  98.     def initialize_options(self):
  99.         _build_ext.initialize_options(self)
  100.         self.shlib_compiler = None
  101.         self.shlibs = []
  102.         self.ext_map = { }
  103.  
  104.     
  105.     def finalize_options(self):
  106.         _build_ext.finalize_options(self)
  107.         if not self.extensions:
  108.             pass
  109.         self.extensions = []
  110.         self.check_extensions_list(self.extensions)
  111.         self.shlibs = _[1]
  112.         for ext in self.extensions:
  113.             ext._full_name = self.get_ext_fullname(ext.name)
  114.         
  115.         for ext in self.extensions:
  116.             fullname = ext._full_name
  117.             self.ext_map[fullname] = ext
  118.             if not self.shlibs or self.links_to_dynamic(ext):
  119.                 pass
  120.             if ltd and use_stubs:
  121.                 pass
  122.             ext._needs_stub = not isinstance(ext, Library)
  123.             libdir = os.path.dirname(os.path.join(self.build_lib, filename))
  124.             if ltd and use_stubs and os.curdir not in ext.runtime_library_dirs:
  125.                 ext.runtime_library_dirs.append(os.curdir)
  126.                 continue
  127.             None if self.shlibs else [] if ltd and libdir not in ext.library_dirs else ltd = ext._links_to_dynamic = False
  128.         
  129.  
  130.     
  131.     def setup_shlib_compiler(self):
  132.         compiler = self.shlib_compiler = new_compiler(compiler = self.compiler, dry_run = self.dry_run, force = self.force)
  133.         if sys.platform == 'darwin':
  134.             tmp = _config_vars.copy()
  135.             
  136.             try:
  137.                 _config_vars['LDSHARED'] = 'gcc -Wl,-x -dynamiclib -undefined dynamic_lookup'
  138.                 _config_vars['CCSHARED'] = ' -dynamiclib'
  139.                 _config_vars['SO'] = '.dylib'
  140.                 customize_compiler(compiler)
  141.             finally:
  142.                 _config_vars.clear()
  143.                 _config_vars.update(tmp)
  144.  
  145.         else:
  146.             customize_compiler(compiler)
  147.         if self.include_dirs is not None:
  148.             compiler.set_include_dirs(self.include_dirs)
  149.         
  150.         if self.define is not None:
  151.             for name, value in self.define:
  152.                 compiler.define_macro(name, value)
  153.             
  154.         
  155.         if self.undef is not None:
  156.             for macro in self.undef:
  157.                 compiler.undefine_macro(macro)
  158.             
  159.         
  160.         if self.libraries is not None:
  161.             compiler.set_libraries(self.libraries)
  162.         
  163.         if self.library_dirs is not None:
  164.             compiler.set_library_dirs(self.library_dirs)
  165.         
  166.         if self.rpath is not None:
  167.             compiler.set_runtime_library_dirs(self.rpath)
  168.         
  169.         if self.link_objects is not None:
  170.             compiler.set_link_objects(self.link_objects)
  171.         
  172.         compiler.link_shared_object = link_shared_object.__get__(compiler)
  173.  
  174.     
  175.     def get_export_symbols(self, ext):
  176.         if isinstance(ext, Library):
  177.             return ext.export_symbols
  178.         return _build_ext.get_export_symbols(self, ext)
  179.  
  180.     
  181.     def build_extension(self, ext):
  182.         _compiler = self.compiler
  183.         
  184.         try:
  185.             if isinstance(ext, Library):
  186.                 self.compiler = self.shlib_compiler
  187.             
  188.             _build_ext.build_extension(self, ext)
  189.             if ext._needs_stub:
  190.                 self.write_stub(self.get_finalized_command('build_py').build_lib, ext)
  191.         finally:
  192.             self.compiler = _compiler
  193.  
  194.  
  195.     
  196.     def links_to_dynamic(self, ext):
  197.         libnames = []([ lib._full_name for lib in self.shlibs ])
  198.         pkg = '.'.join(ext._full_name.split('.')[:-1] + [
  199.             ''])
  200.         for libname in ext.libraries:
  201.             if pkg + libname in libnames:
  202.                 return True
  203.         
  204.         return False
  205.  
  206.     
  207.     def get_outputs(self):
  208.         outputs = _build_ext.get_outputs(self)
  209.         optimize = self.get_finalized_command('build_py').optimize
  210.         for ext in self.extensions:
  211.             if ext._needs_stub:
  212.                 base = os.path.join(self.build_lib, *ext._full_name.split('.'))
  213.                 outputs.append(base + '.py')
  214.                 outputs.append(base + '.pyc')
  215.                 if optimize:
  216.                     outputs.append(base + '.pyo')
  217.                 
  218.             optimize
  219.         
  220.         return outputs
  221.  
  222.     
  223.     def write_stub(self, output_dir, ext, compile = False):
  224.         log.info('writing stub loader for %s to %s', ext._full_name, output_dir)
  225.         stub_file = os.path.join(output_dir, *ext._full_name.split('.')) + '.py'
  226.         if compile and os.path.exists(stub_file):
  227.             raise DistutilsError(stub_file + ' already exists! Please delete.')
  228.         os.path.exists(stub_file)
  229.         if not self.dry_run:
  230.             f = open(stub_file, 'w')
  231.             f.write('\n'.join([
  232.                 'def __bootstrap__():',
  233.                 '   global __bootstrap__, __file__, __loader__',
  234.                 '   import sys, os, pkg_resources, imp' + if_dl(', dl'),
  235.                 '   __file__ = pkg_resources.resource_filename(__name__,%r)' % os.path.basename(ext._file_name),
  236.                 '   del __bootstrap__',
  237.                 "   if '__loader__' in globals():",
  238.                 '       del __loader__',
  239.                 if_dl('   old_flags = sys.getdlopenflags()'),
  240.                 '   old_dir = os.getcwd()',
  241.                 '   try:',
  242.                 '     os.chdir(os.path.dirname(__file__))',
  243.                 if_dl('     sys.setdlopenflags(dl.RTLD_NOW)'),
  244.                 '     imp.load_dynamic(__name__,__file__)',
  245.                 '   finally:',
  246.                 if_dl('     sys.setdlopenflags(old_flags)'),
  247.                 '     os.chdir(old_dir)',
  248.                 '__bootstrap__()',
  249.                 '']))
  250.             f.close()
  251.         
  252.         if compile:
  253.             byte_compile = byte_compile
  254.             import distutils.util
  255.             byte_compile([
  256.                 stub_file], optimize = 0, force = True, dry_run = self.dry_run)
  257.             optimize = self.get_finalized_command('install_lib').optimize
  258.             if optimize > 0:
  259.                 byte_compile([
  260.                     stub_file], optimize = optimize, force = True, dry_run = self.dry_run)
  261.             
  262.             if os.path.exists(stub_file) and not (self.dry_run):
  263.                 os.unlink(stub_file)
  264.             
  265.         
  266.  
  267.  
  268. if use_stubs or os.name == 'nt':
  269.     
  270.     def link_shared_object(self, objects, output_libname, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  271.         self.link(self.SHARED_LIBRARY, objects, output_libname, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
  272.  
  273. else:
  274.     libtype = 'static'
  275.     
  276.     def link_shared_object(self, objects, output_libname, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  277.         (output_dir, filename) = os.path.split(output_libname)
  278.         (basename, ext) = os.path.splitext(filename)
  279.         if self.library_filename('x').startswith('lib'):
  280.             basename = basename[3:]
  281.         
  282.         self.create_static_lib(objects, basename, output_dir, debug, target_lang)
  283.  
  284.