⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 siputils.py

📁 这是关于RFC3261实现sip的源代码
💻 PY
📖 第 1 页 / 共 5 页
字号:
# This module is intended to be used by the build/installation scripts of# extension modules created with SIP.  It provides information about file# locations, version numbers etc., and provides some classes and functions.## Copyright (c) 2006# 	Riverbank Computing Limited <info@riverbankcomputing.co.uk># # This file is part of SIP.# # This copy of SIP is licensed for use under the terms of the SIP License# Agreement.  See the file LICENSE for more details.# # SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.import sysimport osimport stringimport typesimport stat# These are installation specific values created when SIP was configured.# @SIP_CONFIGURATION@# The stack of configuration dictionaries._config_stack = []class Configuration(object):    """The class that represents SIP configuration values.    """    def __init__(self, sub_cfg=None):        """Initialise an instance of the class.        sub_cfg is the list of sub-class configurations.  It should be None        when called normally.        """        # Find the build macros in the closest imported module from where this        # was originally defined.        self._macros = None        for cls in self.__class__.__mro__:            if cls is object:                continue            mod = sys.modules[cls.__module__]            if hasattr(mod, "_default_macros"):                self._macros = mod._default_macros                break        if sub_cfg:            cfg = sub_cfg        else:            cfg = []        cfg.append(_pkg_config)        global _config_stack        _config_stack = cfg    def __getattr__(self, name):        """Allow configuration values and user options to be handled as        instance variables.        name is the name of the configuration value or user option.        """        for cfg in _config_stack:            try:                return cfg[name]            except KeyError:                pass        raise AttributeError, "\"%s\" is not a valid configuration value or user option" % name    def build_macros(self):        """Return the dictionary of platform specific build macros.        """        return self._macros    def set_build_macros(self, macros):        """Set the dictionary of build macros to be use when generating        Makefiles.        macros is the dictionary of platform specific build macros.        """        self._macros = macrosclass _UniqueList:    """A limited list that ensures all its elements are unique.    """    def __init__(self, value=None):        """Initialise the instance.        value is the initial value of the list.        """        if value is None:            self._list = []        else:            self._list = value    def append(self, value):        """Append a value to the list if it isn't already present.        value is the value to append.        """        if value not in self._list:            self._list.append(value)    def extend(self, value):        """Append each element of a value to a list if it isn't already        present.        value is the list of elements to append.        """        for el in value:            self.append(el)    def as_list(self):        """Return the list as a raw list.        """        return self._listclass _Macro:    """A macro that can be manipulated as a list.    """    def __init__(self, name, value):        """Initialise the instance.        name is the name of the macro.        value is the initial value of the macro.        """        self._name = name        self.set(value)    def set(self, value):        """Explicitly set the value of the macro.        value is the new value.  It may be a string, a list of strings or a        _UniqueList instance.        """        self._macro = []        if isinstance(value, _UniqueList):            value = value.as_list()        if type(value) == types.ListType:            self.extend(value)        else:            self.append(value)    def append(self, value):        """Append a value to the macro.        value is the value to append.        """        if value:            self._macro.append(value)    def extend(self, value):        """Append each element of a value to the macro.        value is the list of elements to append.        """        for el in value:            self.append(el)    def as_list(self):        """Return the macro as a list.        """        return self._macroclass Makefile:    """The base class for the different types of Makefiles.    """    def __init__(self, configuration, console=0, qt=0, opengl=0, python=0,                 threaded=0, warnings=1, debug=0, dir=None,                 makefile="Makefile", installs=None):        """Initialise an instance of the target.  All the macros are left        unchanged allowing scripts to manipulate them at will.        configuration is the current configuration.        console is set if the target is a console (rather than windows) target.        qt is set if the target uses Qt.  For Qt v4 a list of Qt libraries may        be specified and a simple non-zero value implies QtCore and QtGui.        opengl is set if the target uses OpenGL.        python is set if the target #includes Python.h.        debug is set to generated a debugging version of the target.        threaded is set if the target requires thread support.  It is        automatically set if the target uses Qt and Qt has thread support        enabled.        warnings is set if compiler warning messages are required.        debug is set if debugging symbols should be generated.        dir is the directory for build files and Makefiles.        makefile is the name of the Makefile.        installs is a list of extra install targets.  Each element is a two        part list, the first of which is the source and the second is the        destination.  If the source is another list then it is a set of source        files and the destination is a directory.        """        if qt:            if not hasattr(configuration, "qt_version"):                error("The target uses Qt but pyqtconfig has not been imported.")            # For Qt v4 interpret Qt support as meaning link against the core            # and GUI libraries (which corresponds to the default qmake            # configuration).  Also allow a list of Qt v4 modules to be            # specified.            if configuration.qt_version >= 0x040000:                if type(qt) != types.ListType:                    qt = ["QtCore", "QtGui"]            self._threaded = configuration.qt_threaded        else:            self._threaded = threaded        self.config = configuration        self.console = console        self._qt = qt        self._opengl = opengl        self._python = python        self._warnings = warnings        self._debug = debug        self._dir = dir        self._makefile = makefile        self._installs = installs        self._finalised = 0        # Copy the macros and convert them all to instance lists.        macros = configuration.build_macros()        for m in macros.keys():            # Allow the user to override the default.            try:                val = getattr(configuration, m)            except AttributeError:                val = macros[m]            # These require special handling as they are (potentially) a set of            # space separated values rather than a single value that might            # contain spaces.            if m == "DEFINES" or m[:6] in ("INCDIR", "LIBDIR"):                val = string.split(val)            # We also want to treat lists of libraries in the same way so that            # duplicates get eliminated.            if m[:4] == "LIBS":                val = string.split(val)            self.__dict__[m] = _Macro(m, val)        # This is used to alter the configuration more significantly than can        # be done with just configuration files.        self.generator = self.optional_string("MAKEFILE_GENERATOR", "UNIX")        # These are what configuration scripts normally only need to change.        self.extra_cflags = []        self.extra_cxxflags = []        self.extra_defines = []        self.extra_include_dirs = []        self.extra_lflags = []        self.extra_lib_dirs = []        self.extra_libs = []        # Get these once and make them available to sub-classes.        if sys.platform == "win32":            def_copy = "copy"            def_rm = "del"            def_mkdir = "mkdir"            def_chk_dir_exists = "if not exist"        else:            def_copy = "cp -f"            def_rm = "rm -f"            def_mkdir = "mkdir -p"            def_chk_dir_exists = "test -d"        self.copy = self.optional_string("COPY", def_copy)        self.rm = self.optional_string("DEL_FILE", def_rm)        self.mkdir = self.optional_string("MKDIR", def_mkdir)        self.chkdir = self.optional_string("CHK_DIR_EXISTS", def_chk_dir_exists)    def finalise(self):        """Finalise the macros by doing any consolidation that isn't specific        to a Makefile.        """        # Extract the things we might need from the Windows Qt configuration.        if self._qt:            wcfg = string.split(self.config.qt_winconfig)            win_shared = ("shared" in wcfg)            win_exceptions = ("exceptions" in wcfg)            win_rtti = ("rtti" in wcfg)            win_stl = ("stl" in wcfg)        else:            win_shared = 1            win_exceptions = 0            win_rtti = 0            win_stl = 0        # Get what we are going to transform.        cflags = _UniqueList()        cflags.extend(self.extra_cflags)        cflags.extend(self.optional_list("CFLAGS"))        cxxflags = _UniqueList()        cxxflags.extend(self.extra_cxxflags)        cxxflags.extend(self.optional_list("CXXFLAGS"))        defines = _UniqueList()        defines.extend(self.extra_defines)        defines.extend(self.optional_list("DEFINES"))        incdir = _UniqueList(["."])        incdir.extend(self.extra_include_dirs)        incdir.extend(self.optional_list("INCDIR"))        lflags = _UniqueList()        lflags.extend(self.extra_lflags)        lflags.extend(self.optional_list("LFLAGS"))        libdir = _UniqueList()        libdir.extend(self.extra_lib_dirs)        libdir.extend(self.optional_list("LIBDIR"))        # Don't use a unique list as libraries may need to be searched more        # than once.  Also MacOS/X uses the form "-framework lib" so we don't        # want to lose the multiple "-framework".        libs = []        for l in self.extra_libs:            libs.append(self.platform_lib(l))            if self._qt:                libs.extend(self._dependent_libs(l))        libs.extend(self.optional_list("LIBS"))        rpaths = _UniqueList()        for l in self.extra_lib_dirs:            # Ignore relative directories.  This is really a hack to handle            # SIP v3 inter-module linking.            if os.path.dirname(l) not in ("", ".", ".."):                rpaths.append(l)        if self._python:            incdir.append(self.config.py_inc_dir)            incdir.append(self.config.py_conf_inc_dir)            if sys.platform == "cygwin":                libdir.append(self.config.py_lib_dir)                py_lib = "python%u.%u" % ((self.config.py_version >> 16), ((self.config.py_version >> 8) & 0xff))                libs.append(self.platform_lib(py_lib))            elif sys.platform == "win32":                libdir.append(self.config.py_lib_dir)                py_lib = "python%u%u" % ((self.config.py_version >> 16), ((self.config.py_version >> 8) & 0xff))                # For Borland use the OMF version of the Python library if it                # exists, otherwise assume that Python was built with Borland                # and use the normal library.                if self.generator == "BMAKE":                    bpy_lib = py_lib + "_bcpp"                    bpy_lib_path = os.path.join(self.config.py_lib_dir, self.platform_lib(bpy_lib))                    if os.access(bpy_lib_path, os.F_OK):                        py_lib = bpy_lib                if self._debug:                    py_lib = py_lib + "_d"                    if self.generator != "MINGW":                        cflags.append("/D_DEBUG")                        cxxflags.append("/D_DEBUG")                libs.append(self.platform_lib(py_lib))        if self.generator in ("MSVC", "MSVC.NET", "BMAKE"):            if win_exceptions:                cflags_exceptions = "CFLAGS_EXCEPTIONS_ON"                cxxflags_exceptions = "CXXFLAGS_EXCEPTIONS_ON"            else:                cflags_exceptions = "CFLAGS_EXCEPTIONS_OFF"                cxxflags_exceptions = "CXXFLAGS_EXCEPTIONS_OFF"            cflags.extend(self.optional_list(cflags_exceptions))            cxxflags.extend(self.optional_list(cxxflags_exceptions))            if win_rtti:                cflags_rtti = "CFLAGS_RTTI_ON"                cxxflags_rtti = "CXXFLAGS_RTTI_ON"            else:                cflags_rtti = "CFLAGS_RTTI_OFF"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -