home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / sipdistutils.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  5.1 KB  |  142 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  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 = 'Compile SIP descriptions, then build C/C++ extensions (compile/link to build directory)'
  17.     user_options = build_ext_base.user_options[:]
  18.     user_options = [ opt for opt in user_options if opt[0].startswith('swig') ]
  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._sip_output_dir(), 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 not os.name == 'nt' and os.path.splitext(os.path.basename(cfg.sip_bin))[1]:
  52.             return cfg.sip_bin + '.exe'
  53.         return cfg.sip_bin
  54.  
  55.     
  56.     def _sip_inc_dir(self):
  57.         import sipconfig
  58.         cfg = sipconfig.Configuration()
  59.         return cfg.sip_inc_dir
  60.  
  61.     
  62.     def _sip_sipfiles_dir(self):
  63.         import sipconfig
  64.         cfg = sipconfig.Configuration()
  65.         return cfg.default_sip_dir
  66.  
  67.     
  68.     def _sip_calc_signature(self):
  69.         sip_bin = self._find_sip()
  70.         return sha1(open(sip_bin, 'rb').read()).hexdigest()
  71.  
  72.     
  73.     def _sip_signature_file(self):
  74.         return os.path.join(self._sip_output_dir(), 'sip.signature')
  75.  
  76.     
  77.     def _sip_output_dir(self):
  78.         return self.build_temp
  79.  
  80.     
  81.     def build_extension(self, ext):
  82.         oldforce = self.force
  83.         if not self.force:
  84.             sip_sources = [ source for source in ext.sources if source.endswith('.sip') ]
  85.             if sip_sources:
  86.                 sigfile = self._sip_signature_file()
  87.                 if not os.path.isfile(sigfile):
  88.                     self.force = True
  89.                 else:
  90.                     old_sig = open(sigfile).read()
  91.                     new_sig = self._sip_calc_signature()
  92.                     if old_sig != new_sig:
  93.                         self.force = True
  94.                     
  95.             
  96.         build_ext_base.build_extension(self, ext)
  97.         self.force = oldforce
  98.  
  99.     
  100.     def swig_sources(self, sources, extension = None):
  101.         if not self.extensions:
  102.             return None
  103.         if None is not None:
  104.             extension.include_dirs.append(self._sip_inc_dir())
  105.             depends = extension.depends
  106.         else:
  107.             self.include_dirs.append(self._sip_inc_dir())
  108.             depends = []
  109.         depends = [ f for f in depends if os.path.splitext(f)[1] == '.sip' ]
  110.         if not os.path.isdir(self._sip_output_dir()):
  111.             os.makedirs(self._sip_output_dir())
  112.         sip_sources = []
  113.         sip_sources = [ source for source in sources if source.endswith('.sip') ]
  114.         other_sources = [ source for source in sources if source.endswith('.sip') ]
  115.         generated_sources = []
  116.         sip_bin = self._find_sip()
  117.         for sip in sip_sources:
  118.             sipbasename = os.path.basename(sip)
  119.             sbf = os.path.join(self._sip_output_dir(), replace_suffix(sipbasename, '.sbf'))
  120.             if newer_group([
  121.                 sip] + depends, sbf) or self.force:
  122.                 self._sip_compile(sip_bin, sip, sbf)
  123.                 open(self._sip_signature_file(), 'w').write(self._sip_calc_signature())
  124.             out = self._get_sip_output_list(sbf)
  125.             generated_sources.extend(out)
  126.         
  127.         return generated_sources + other_sources
  128.  
  129.     
  130.     def _sip_compile(self, sip_bin, source, sbf):
  131.         self.spawn([
  132.             sip_bin] + self.sip_opts + [
  133.             '-c',
  134.             self._sip_output_dir(),
  135.             '-b',
  136.             sbf,
  137.             '-I',
  138.             self._sip_sipfiles_dir(),
  139.             source])
  140.  
  141.  
  142.