home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / var / lib / python-support / python2.4 / gtk-2.0 / dsextras.pyc (.txt)
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  13.0 KB  |  403 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from distutils.command.build_ext import build_ext
  5. from distutils.command.install_lib import install_lib
  6. from distutils.command.install_data import install_data
  7. from distutils.extension import Extension
  8. import fnmatch
  9. import os
  10. import re
  11. import string
  12. import sys
  13. GLOBAL_INC = []
  14. GLOBAL_MACROS = []
  15.  
  16. def get_m4_define(varname):
  17.     '''Return the value of a m4_define variable as set in configure.in.'''
  18.     pattern = re.compile('m4_define\\(' + varname + '\\,\\s*(.+)\\)')
  19.     if os.path.exists('configure.ac'):
  20.         fname = 'configure.ac'
  21.     elif os.path.exists('configure.in'):
  22.         fname = 'configure.in'
  23.     else:
  24.         raise SystemExit('could not find configure file')
  25.     for line in open(fname).readlines():
  26.         match_obj = pattern.match(line)
  27.         if match_obj:
  28.             return match_obj.group(1)
  29.             continue
  30.     
  31.  
  32.  
  33. def getoutput(cmd):
  34.     '''Return output (stdout or stderr) of executing cmd in a shell.'''
  35.     return getstatusoutput(cmd)[1]
  36.  
  37.  
  38. def getstatusoutput(cmd):
  39.     '''Return (status, output) of executing cmd in a shell.'''
  40.     if sys.platform == 'win32':
  41.         pipe = os.popen(cmd, 'r')
  42.         text = pipe.read()
  43.         if not pipe.close():
  44.             pass
  45.         sts = 0
  46.         if text[-1:] == '\n':
  47.             text = text[:-1]
  48.         
  49.         return (sts, text)
  50.     else:
  51.         getstatusoutput = getstatusoutput
  52.         import commands
  53.         return getstatusoutput(cmd)
  54.  
  55.  
  56. def have_pkgconfig():
  57.     '''Checks for the existence of pkg-config'''
  58.     if sys.platform == 'win32' and os.system('pkg-config --version > NUL') == 0:
  59.         return 1
  60.     elif getstatusoutput('pkg-config')[0] == 256:
  61.         return 1
  62.     
  63.  
  64.  
  65. def list_files(dir):
  66.     '''List all files in a dir, with filename match support:
  67.     for example: glade/*.glade will return all files in the glade directory
  68.     that matches *.glade. It also looks up the full path'''
  69.     if dir.find(os.sep) != -1:
  70.         parts = dir.split(os.sep)
  71.         dir = string.join(parts[:-1], os.sep)
  72.         pattern = parts[-1]
  73.     else:
  74.         pattern = dir
  75.         dir = '.'
  76.     dir = os.path.abspath(dir)
  77.     retval = []
  78.     for file in os.listdir(dir):
  79.         if fnmatch.fnmatch(file, pattern):
  80.             retval.append(os.path.join(dir, file))
  81.             continue
  82.     
  83.     return retval
  84.  
  85.  
  86. def pkgc_version_check(name, longname, req_version):
  87.     is_installed = not os.system('pkg-config --exists %s' % name)
  88.     if not is_installed:
  89.         print 'Could not find %s' % longname
  90.         return 0
  91.     
  92.     orig_version = getoutput('pkg-config --modversion %s' % name)
  93.     version = map(int, orig_version.split('.'))
  94.     pkc_version = map(int, req_version.split('.'))
  95.     if version >= pkc_version:
  96.         return 1
  97.     else:
  98.         print 'Warning: Too old version of %s' % longname
  99.         print '         Need %s, but %s is installed' % (pkc_version, orig_version)
  100.         self.can_build_ok = 0
  101.         return 0
  102.  
  103.  
  104. class BuildExt(build_ext):
  105.     
  106.     def init_extra_compile_args(self):
  107.         self.extra_compile_args = []
  108.         if sys.platform == 'win32' and self.compiler.compiler_type == 'mingw32':
  109.             msnative_struct = {
  110.                 '2': '-fnative-struct',
  111.                 '3': '-mms-bitfields' }
  112.             gcc_version = getoutput('gcc -dumpversion')
  113.             print 'using MinGW GCC version %s with %s option' % (gcc_version, msnative_struct[gcc_version[0]])
  114.             self.extra_compile_args.append(msnative_struct[gcc_version[0]])
  115.         
  116.  
  117.     
  118.     def modify_compiler(self):
  119.         if sys.platform == 'win32' and self.compiler.compiler_type == 'mingw32':
  120.             if self.compiler.linker_so.count('-static'):
  121.                 self.compiler.linker_so.remove('-static')
  122.             
  123.         
  124.  
  125.     
  126.     def build_extensions(self):
  127.         self.init_extra_compile_args()
  128.         self.modify_compiler()
  129.         build_ext.build_extensions(self)
  130.  
  131.     
  132.     def build_extension(self, ext):
  133.         ext.extra_compile_args += self.extra_compile_args
  134.         if hasattr(ext, 'generate'):
  135.             ext.generate()
  136.         
  137.         build_ext.build_extension(self, ext)
  138.         if save_libs != None and save_libs != ext.libraries:
  139.             ext.libraries = save_libs
  140.         
  141.  
  142.  
  143.  
  144. class InstallLib(install_lib):
  145.     local_outputs = []
  146.     local_inputs = []
  147.     
  148.     def set_install_dir(self, install_dir):
  149.         self.install_dir = install_dir
  150.  
  151.     
  152.     def get_outputs(self):
  153.         return install_lib.get_outputs(self) + self.local_outputs
  154.  
  155.     
  156.     def get_inputs(self):
  157.         return install_lib.get_inputs(self) + self.local_inputs
  158.  
  159.  
  160.  
  161. class InstallData(install_data):
  162.     local_outputs = []
  163.     local_inputs = []
  164.     template_options = { }
  165.     
  166.     def prepare(self):
  167.         if os.name == 'nt':
  168.             self.prefix = os.sep.join(self.install_dir.split(os.sep)[:-3])
  169.         else:
  170.             self.prefix = os.sep.join(self.install_dir.split(os.sep)[:-4])
  171.         self.exec_prefix = '${prefix}/bin'
  172.         self.includedir = '${prefix}/include'
  173.         self.libdir = '${prefix}/lib'
  174.         self.datarootdir = '${prefix}/share'
  175.         self.datadir = '${prefix}/share'
  176.         self.add_template_option('prefix', self.prefix)
  177.         self.add_template_option('exec_prefix', self.exec_prefix)
  178.         self.add_template_option('includedir', self.includedir)
  179.         self.add_template_option('libdir', self.libdir)
  180.         self.add_template_option('datarootdir', self.datarootdir)
  181.         self.add_template_option('datadir', self.datadir)
  182.         self.add_template_option('PYTHON', sys.executable)
  183.         self.add_template_option('THREADING_CFLAGS', '')
  184.  
  185.     
  186.     def set_install_dir(self, install_dir):
  187.         self.install_dir = install_dir
  188.  
  189.     
  190.     def add_template_option(self, name, value):
  191.         self.template_options['@%s@' % name] = value
  192.  
  193.     
  194.     def install_template(self, filename, install_dir):
  195.         '''Install template filename into target directory install_dir.'''
  196.         output_file = os.path.split(filename)[-1][:-3]
  197.         template = open(filename).read()
  198.         for key, value in self.template_options.items():
  199.             template = template.replace(key, value)
  200.         
  201.         output = os.path.join(install_dir, output_file)
  202.         self.mkpath(install_dir)
  203.         open(output, 'w').write(template)
  204.         self.local_inputs.append(filename)
  205.         self.local_outputs.append(output)
  206.         return output
  207.  
  208.     
  209.     def get_outputs(self):
  210.         return install_lib.get_outputs(self) + self.local_outputs
  211.  
  212.     
  213.     def get_inputs(self):
  214.         return install_lib.get_inputs(self) + self.local_inputs
  215.  
  216.  
  217.  
  218. class PkgConfigExtension(Extension):
  219.     pygobject_pkc = 'pygobject-2.0'
  220.     can_build_ok = None
  221.     
  222.     def __init__(self, **kwargs):
  223.         name = kwargs['pkc_name']
  224.         kwargs['include_dirs'] = self.get_include_dirs(name) + GLOBAL_INC
  225.         kwargs['define_macros'] = GLOBAL_MACROS
  226.         kwargs['libraries'] = self.get_libraries(name)
  227.         kwargs['library_dirs'] = self.get_library_dirs(name)
  228.         if 'pygobject_pkc' in kwargs:
  229.             self.pygobject_pkc = kwargs.pop('pygobject_pkc')
  230.         
  231.         if self.pygobject_pkc:
  232.             kwargs['include_dirs'] += self.get_include_dirs(self.pygobject_pkc)
  233.             kwargs['libraries'] += self.get_libraries(self.pygobject_pkc)
  234.             kwargs['library_dirs'] += self.get_library_dirs(self.pygobject_pkc)
  235.         
  236.         self.name = kwargs['name']
  237.         self.pkc_name = kwargs['pkc_name']
  238.         self.pkc_version = kwargs['pkc_version']
  239.         del kwargs['pkc_name']
  240.         del kwargs['pkc_version']
  241.         Extension.__init__(self, **kwargs)
  242.  
  243.     
  244.     def get_include_dirs(self, names):
  245.         if type(names) != tuple:
  246.             names = (names,)
  247.         
  248.         retval = []
  249.         for name in names:
  250.             output = getoutput('pkg-config --cflags-only-I %s' % name)
  251.             retval.extend(output.replace('-I', '').split())
  252.         
  253.         return retval
  254.  
  255.     
  256.     def get_libraries(self, names):
  257.         if type(names) != tuple:
  258.             names = (names,)
  259.         
  260.         retval = []
  261.         for name in names:
  262.             output = getoutput('pkg-config --libs-only-l %s' % name)
  263.             retval.extend(output.replace('-l', '').split())
  264.         
  265.         return retval
  266.  
  267.     
  268.     def get_library_dirs(self, names):
  269.         if type(names) != tuple:
  270.             names = (names,)
  271.         
  272.         retval = []
  273.         for name in names:
  274.             output = getoutput('pkg-config --libs-only-L %s' % name)
  275.             retval.extend(output.replace('-L', '').split())
  276.         
  277.         return retval
  278.  
  279.     
  280.     def can_build(self):
  281.         '''If the pkg-config version found is good enough'''
  282.         if self.can_build_ok != None:
  283.             return self.can_build_ok
  284.         
  285.         if type(self.pkc_name) != tuple:
  286.             reqs = [
  287.                 (self.pkc_name, self.pkc_version)]
  288.         else:
  289.             reqs = zip(self.pkc_name, self.pkc_version)
  290.         for package, version in reqs:
  291.             retval = os.system('pkg-config --exists %s' % package)
  292.             if retval:
  293.                 print '* %s.pc could not be found, bindings for %s will not be built.' % (package, self.name)
  294.                 self.can_build_ok = 0
  295.                 return 0
  296.             
  297.             orig_version = getoutput('pkg-config --modversion %s' % package)
  298.             if map(int, orig_version.split('.')) >= map(int, version.split('.')):
  299.                 self.can_build_ok = 1
  300.                 return 1
  301.                 continue
  302.             print 'Warning: Too old version of %s' % self.pkc_name
  303.             print '         Need %s, but %s is installed' % (package, orig_version)
  304.             self.can_build_ok = 0
  305.             return 0
  306.         
  307.  
  308.     
  309.     def generate(self):
  310.         pass
  311.  
  312.  
  313.  
  314. class Template:
  315.     
  316.     def __init__(self, override, output, defs, prefix, register = [], load_types = None):
  317.         self.override = override
  318.         self.defs = defs
  319.         self.register = register
  320.         self.output = output
  321.         self.prefix = prefix
  322.         self.load_types = load_types
  323.  
  324.     
  325.     def check_dates(self):
  326.         if not os.path.exists(self.output):
  327.             return 0
  328.         
  329.         files = self.register[:]
  330.         files.append(self.override)
  331.         files.append(self.defs)
  332.         newest = 0
  333.         for file in files:
  334.             test = os.stat(file)[8]
  335.             if test > newest:
  336.                 newest = test
  337.                 continue
  338.         
  339.         if newest < os.stat(self.output)[8]:
  340.             return 1
  341.         
  342.         return 0
  343.  
  344.     
  345.     def generate(self):
  346.         sys.path.insert(0, 'codegen')
  347.         Overrides = Overrides
  348.         import override
  349.         DefsParser = DefsParser
  350.         import defsparser
  351.         register_types = register_types
  352.         write_source = write_source
  353.         FileOutput = FileOutput
  354.         import codegen
  355.         if self.check_dates():
  356.             return None
  357.         
  358.         for item in self.register:
  359.             dp = DefsParser(item, dict(GLOBAL_MACROS))
  360.             dp.startParsing()
  361.             register_types(dp)
  362.         
  363.         if self.load_types:
  364.             globals = { }
  365.             execfile(self.load_types, globals)
  366.         
  367.         dp = DefsParser(self.defs, dict(GLOBAL_MACROS))
  368.         dp.startParsing()
  369.         register_types(dp)
  370.         fd = open(self.output, 'w')
  371.         write_source(dp, Overrides(self.override), self.prefix, FileOutput(fd, self.output))
  372.         fd.close()
  373.  
  374.  
  375.  
  376. class TemplateExtension(PkgConfigExtension):
  377.     
  378.     def __init__(self, **kwargs):
  379.         name = kwargs['name']
  380.         defs = kwargs['defs']
  381.         output = defs[:-5] + '.c'
  382.         override = kwargs['override']
  383.         load_types = kwargs.get('load_types')
  384.         self.templates = []
  385.         self.templates.append(Template(override, output, defs, 'py' + name, kwargs['register'], load_types))
  386.         del kwargs['register']
  387.         del kwargs['override']
  388.         del kwargs['defs']
  389.         if load_types:
  390.             del kwargs['load_types']
  391.         
  392.         if kwargs.has_key('output'):
  393.             kwargs['name'] = kwargs['output']
  394.             del kwargs['output']
  395.         
  396.         PkgConfigExtension.__init__(self, **kwargs)
  397.  
  398.     
  399.     def generate(self):
  400.         map((lambda x: x.generate()), self.templates)
  401.  
  402.  
  403.