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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import distutils.command.build_ext as distutils
  5. from distutils.dep_util import newer, newer_group
  6. import os
  7. import sys
  8. from hashlib import sha1
  9. build_ext_base = distutils.command.build_ext.build_ext
  10.  
  11. def replace_suffix(path, new_suffix):
  12.     return os.path.splitext(path)[0] + new_suffix
  13.  
  14.  
  15. class build_ext(build_ext_base):
  16.     description = 'Compiler SIP descriptions, then build C/C++ extensions (compile/link to build directory)'
  17.     user_options = build_ext_base.user_options[:]
  18.     user_options = _[1]
  19.     user_options += [
  20.         ('sip-opts=', None, 'list of sip command line options')]
  21.     
  22.     def initialize_options(self):
  23.         build_ext_base.initialize_options(self)
  24.         self.sip_opts = None
  25.  
  26.     
  27.     def finalize_options(self):
  28.         build_ext_base.finalize_options(self)
  29.         if self.sip_opts is None:
  30.             self.sip_opts = []
  31.         else:
  32.             self.sip_opts = self.sip_opts.split(' ')
  33.  
  34.     
  35.     def _get_sip_output_list(self, sbf):
  36.         for L in file(sbf):
  37.             (key, value) = L.split('=', 1)
  38.             if key.strip() == 'sources':
  39.                 out = []
  40.                 for o in value.split():
  41.                     out.append(os.path.join(self.build_temp, o))
  42.                 
  43.                 return out
  44.         
  45.         raise RuntimeError("cannot parse SIP-generated '%s'" % sbf)
  46.  
  47.     
  48.     def _find_sip(self):
  49.         import sipconfig
  50.         cfg = sipconfig.Configuration()
  51.         if os.name == 'nt':
  52.             if not os.path.splitext(os.path.basename(cfg.sip_bin))[1]:
  53.                 return cfg.sip_bin + '.exe'
  54.         
  55.         return cfg.sip_bin
  56.  
  57.     
  58.     def _sip_inc_dir(self):
  59.         import sipconfig
  60.         cfg = sipconfig.Configuration()
  61.         return cfg.sip_inc_dir
  62.  
  63.     
  64.     def _sip_sipfiles_dir(self):
  65.         import sipconfig
  66.         cfg = sipconfig.Configuration()
  67.         return cfg.default_sip_dir
  68.  
  69.     
  70.     def _sip_calc_signature(self):
  71.         sip_bin = self._find_sip()
  72.         return sha1(open(sip_bin, 'rb').read()).hexdigest()
  73.  
  74.     
  75.     def _sip_signature_file(self):
  76.         return os.path.join(self.build_temp, 'sip.signature')
  77.  
  78.     
  79.     def build_extension(self, ext):
  80.         oldforce = self.force
  81.         build_ext_base.build_extension(self, ext)
  82.         self.force = oldforce
  83.  
  84.     
  85.     def swig_sources(self, sources, extension = None):
  86.         if not self.extensions:
  87.             return None
  88.         if extension is not None:
  89.             extension.include_dirs.append(self._sip_inc_dir())
  90.             depends = extension.depends
  91.         else:
  92.             self.include_dirs.append(self._sip_inc_dir())
  93.             depends = []
  94.         depends = _[1]
  95.         sip_sources = []
  96.         sip_sources = _[2]
  97.         other_sources = _[3]
  98.         generated_sources = []
  99.         sip_bin = self._find_sip()
  100.         for sip in sip_sources:
  101.             sipbasename = os.path.basename(sip)
  102.             sbf = os.path.join(self.build_temp, replace_suffix(sipbasename, '.sbf'))
  103.             out = self._get_sip_output_list(sbf)
  104.             generated_sources.extend(out)
  105.         
  106.         return generated_sources + other_sources
  107.  
  108.     
  109.     def _sip_compile(self, sip_bin, source, sbf):
  110.         self.spawn([
  111.             sip_bin] + self.sip_opts + [
  112.             '-c',
  113.             self.build_temp,
  114.             '-b',
  115.             sbf,
  116.             '-I',
  117.             self._sip_sipfiles_dir(),
  118.             source])
  119.  
  120.  
  121.