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

📄 siputils.py

📁 这是关于RFC3261实现sip的源代码
💻 PY
📖 第 1 页 / 共 5 页
字号:
        mfile is the file object.        """        if not self._build:            raise ValueError, "pass a filename as build_file when generating a Makefile"        target = self._build["target"]        if sys.platform in ("win32", "cygwin"):            target = target + ".exe"        mfile.write("TARGET = %s\n" % target)        mfile.write("OFILES = %s\n" % self._build["objects"])        mfile.write("HFILES = %s\n" % self._build["headers"])        mfile.write("\n")        Makefile.generate_macros_and_rules(self, mfile)    def generate_target_default(self, mfile):        """Generate the default target.        mfile is the file object.        """        mfile.write("\n$(TARGET): $(OFILES)\n")        if self.generator in ("MSVC", "MSVC.NET"):            mfile.write("\t$(LINK) $(LFLAGS) /OUT:$(TARGET) @<<\n")            mfile.write("\t  $(OFILES) $(LIBS)\n")            mfile.write("<<\n")        elif self.generator == "BMAKE":            mfile.write("\t$(LINK) @&&|\n")            mfile.write("\t$(LFLAGS) $(OFILES) ,$(TARGET),,$(LIBS),,\n")            mfile.write("|\n")        else:            mfile.write("\t$(LINK) $(LFLAGS) -o $(TARGET) $(OFILES) $(LIBS)\n")        mfile.write("\n$(OFILES): $(HFILES)\n")        for mf in string.split(self._build["moc_headers"]):            root, discard = os.path.splitext(mf)            cpp = "moc_" + root + ".cpp"            mfile.write("\n%s: %s\n" % (cpp, mf))            mfile.write("\t$(MOC) -o %s %s\n" % (cpp, mf))    def generate_target_install(self, mfile):        """Generate the install target.        mfile is the file object.        """        if self._install_dir is None:            self._install_dir = self.config.default_bin_dir        mfile.write("\ninstall: $(TARGET)\n")        self.install_file(mfile, "$(TARGET)", self._install_dir)    def generate_target_clean(self, mfile):        """Generate the clean target.        mfile is the file object.        """        mfile.write("\nclean:\n")        self.clean_build_file_objects(mfile, self._build)def _quote(s):    """Return a string surrounded by double quotes it if contains a space.    s is the string.    """    if string.find(s, " ") >= 0:        s = '"' + s + '"'    return sdef version_to_string(v):    """Convert a 3 part version number encoded as a hexadecimal value to a    string.    """    return "%u.%u.%u" % (((v >> 16) & 0xff), ((v >> 8) & 0xff), (v & 0xff))def read_version(filename, description, numdefine=None, strdefine=None):    """Read the version information for a package from a file.  The information    is specified as #defines of a numeric (hexadecimal or decimal) value and/or    a string value.    filename is the name of the file.    description is the descriptive name of the package.    numdefine is the name of the #define of the numeric version.  It is ignored    if it is None.    strdefine is the name of the #define of the string version.  It is ignored    if it is None.    Returns a tuple of the version as a number and as a string.    """    need_num = numdefine is not None    need_str = strdefine is not None    vers = None    versstr = None    f = open(filename)    l = f.readline()    while l and (need_num or need_str):        wl = string.split(l)        if len(wl) >= 3 and wl[0] == "#define":            if need_num and wl[1] == numdefine:                v = wl[2]                if v[0:2] == "0x":                    vers = string.atoi(v,16)                else:                    dec = int(v)                    maj = dec / 100                    min = (dec % 100) / 10                    bug = (dec % 10)                    vers = (maj << 16) + (min << 8) + bug                need_num = 0            if need_str and wl[1] == strdefine:                # Take account of embedded spaces.                versstr = string.join(wl[2:])[1:-1]                need_str = 0        l = f.readline()    f.close()    if need_num or need_str:        error("The %s version number could not be determined by parsing %s." % (description, filename))    return (vers, versstr)def create_content(dict, macros=None):    """Convert a dictionary to a string (typically to use as the content to a    call to create_config_module()).  Dictionary values that are strings are    quoted.  Dictionary values that are lists are converted to quoted strings.    dict is the dictionary.    macros is the optional dictionary of platform specific build macros.    """    content = "_pkg_config = {\n"    keys = dict.keys()    keys.sort()    # Format it nicely.    width = 0    for k in keys:        klen = len(k)        if width < klen:            width = klen    for k in keys:        val = dict[k]        vtype = type(val)        if val is None:            val = "None"        elif vtype == types.ListType:            val = "'" + string.join(val) + "'"        elif vtype == types.StringType:            val = "'" + val + "'"        elif vtype == types.IntType:            if string.find(k, "version") >= 0:                # Assume it's a hexadecimal version number.  It doesn't matter                # if it isn't, we are just trying to make it look pretty.                val = "0x%06x" % val            else:                val = str(val)        else:            val = "'" + str(val) + "'"        content = content + "    '" + k + "':" + (" " * (width - len(k) + 2)) + string.replace(val, "\\", "\\\\")        if k != keys[-1]:            content = content + ","        content = content + "\n"    content = content + "}\n\n"    # Format the optional macros.    content = content + "_default_macros = "    if macros:        content = content + "{\n"        names = macros.keys()        names.sort()        width = 0        for c in names:            clen = len(c)            if width < clen:                width = clen        for c in names:            if c == names[-1]:                sep = ""            else:                sep = ","            k = "'" + c + "':"            content = content + "    %-*s  '%s'%s\n" % (1 + width + 2, k, string.replace(macros[c], "\\", "\\\\"), sep)        content = content + "}\n"    else:        content = content + "None\n"    return contentdef create_config_module(module, template, content, macros=None):    """Create a configuration module by replacing "@" followed by    "SIP_CONFIGURATION" followed by "@" in a template file with a content    string.    module is the name of the module file.    template is the name of the template file.    content is the content string.  If it is a dictionary it is first converted    to a string using create_content().    macros is an optional dictionary of platform specific build macros.  It is    only used if create_content() is called to convert the content to a string.    """    if type(content) == types.DictType:        content = create_content(content, macros)    # Allow this file to used as a template.    key = "@" + "SIP_CONFIGURATION" + "@"    df = open(module, "w")    sf = open(template, "r")    line = sf.readline()    while line:        if string.find(line, key) >= 0:            line = content        df.write(line)        line = sf.readline()def version_to_sip_tag(version, tags, description):    """Convert a version number to a SIP tag.    version is the version number.  If it is negative then the latest version    is assumed.  (This is typically useful if a snapshot is indicated by a    negative version number.)    tags is the dictionary of tags keyed by version number.  The tag used is    the one with the smallest key (ie. earliest version) that is greater than    the given version number.    description is the descriptive name of the package used for error messages.    Returns the corresponding tag.    """    vl = tags.keys()    vl.sort()    # For a snapshot use the latest tag.    if version < 0:        tag = tags[vl[-1]]    else:        for v in vl:            if version < v:                tag = tags[v]                break        else:            error("Unsupported %s version: 0x%06x." % (description, version))    return tagdef error(msg):    """Display an error message and terminate.    msg is the text of the error message.    """    sys.stderr.write(format("Error: " + msg) + "\n")    sys.exit(1) def inform(msg):    """Display an information message.    msg is the text of the error message.    """    sys.stdout.write(format(msg) + "\n")def format(msg, leftmargin=0, rightmargin=78):    """Format a message by inserting line breaks at appropriate places.    msg is the text of the message.    leftmargin is the position of the left margin.    rightmargin is the position of the right margin.    Return the formatted message.    """    curs = leftmargin    fmsg = " " * leftmargin    for w in string.split(msg):        l = len(w)        if curs != leftmargin and curs + l > rightmargin:            fmsg = fmsg + "\n" + (" " * leftmargin)            curs = leftmargin        if curs > leftmargin:            fmsg = fmsg + " "            curs = curs + 1        fmsg = fmsg + w        curs = curs + l    return fmsgdef parse_build_macros(filename, names, overrides=None, properties=None):    """Parse a qmake compatible file of build system macros and convert it to a    dictionary.  A macro is a name/value pair.  The dictionary is returned or    None if any of the overrides was invalid.    filename is the name of the file to parse.    names is a list of the macro names to extract from the file.    overrides is an optional list of macro names and values that modify those    found in the file.  They are of the form "name=value" (in which case the    value replaces the value found in the file) or "name+=value" (in which case    the value is appended to the value found in the file).    properties is an optional dictionary of property name and values that are    used to resolve any expressions of the form "$[name]" in the file.    """    # Validate and convert the overrides to a dictionary.    orides = {}    if overrides is not None:        for oride in overrides:            prefix = ""            name_end = string.find(oride, "+=")            if name_end >= 0:                prefix = "+"                val_start = name_end + 2            else:                name_end = string.find(oride, "=")                if name_end >= 0:                    val_start = name_end + 1                else:                    return None            name = oride[:name_end]            if name not in names:                return None            orides[name] = prefix + oride[val_start:]    try:        f = open(filename, "r")    except IOError, detail:        error("Unable to open %s: %s" % (filename, detail))    # Get everything into a dictionary.    raw = {        "DIR_SEPARATOR":        os.sep,        "LITERAL_WHITESPACE":   " ",        "LITERAL_DOLLAR":       "$",        "LITERAL_HASH":         "#"    }    line = f.readline()    while line:        # Handle line continuations.        while len(line) > 1 and line[-2] == "\\":            line = line[:-2]            next = f.readline()            if next:                line = line + next            else:                break        line = string.strip(line)        # Ignore comments.        if line and line[0] != "#":            assstart = string.find(line, "+")    

⌨️ 快捷键说明

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