예제 #1
0
def get_tree_from_cix(yui_version):
    cix_file = glob("%s%syui_v%s.cix" % (join(dirname(abspath(__file__)), "apicatalogs"), os.sep, yui_version))[0]
    try:
        return ET.parse(cix_file).getroot()
    except:
        log.exception("Unable to load cix file: %r", cix_file)
    return None
예제 #2
0
def main():
    # More robust for determining the perforce script location
    cix_filename = "javascript.cix"
    scriptpath = os.path.dirname(__file__)
    if not scriptpath:
        scriptpath = "."
    scriptpath = os.path.abspath(scriptpath)
    cix_directory = scriptpath
    # Get main codeintel directory, 3 up from this script location!
    for i in range(3):
        cix_directory = os.path.dirname(cix_directory)
    cix_filename = os.path.join(cix_directory, "lib", "codeintel2", "stdlibs",
                                cix_filename)

    # Generate the cix files
    for filename in ("ecmaToCodeintel.py", "dom0_to_cix.py", "dom2_to_cix.py"):
        p = os.popen("python %s" % (os.path.join(scriptpath, filename))).read()
    # Combine the libraries
    cixtree = ciElementTree.parse(os.path.join(scriptpath, "javascript.cix"))
    cixscope = cixtree.find("file/scope")

    # Note: XMLHttpRequest cix comes from the Mozilla implementation in:
    #       nsIXMLHttpRequest.idl
    for domname in ("XMLHttpRequest", "dom0", "dom2"):
        # cixscope.append(ciElementTree.Comment(" %s structure " % (domname)))
        et = ciElementTree.parse("%s.cix" %
                                 (os.path.join(scriptpath, domname)))
        for scope in et.findall("//file/scope"):
            for child in scope.getchildren():
                # Ensure we remove from the dom tree first, otherwise
                # we generate double elements
                scope.remove(child)
                cixscope.append(child)

    pretty_tree_from_tree(cixtree.getroot())

    update_documentation_sentences(cixtree)

    p4update(cix_filename, ciElementTree.tostring(cixtree.getroot()))

    # Update libraries
    for dirname, filename in (("dojo", "dojo_json_to_cix.py"),
                              ("MochiKit", "mochikit_to_cix.py"),
                              ("prototype", "prototype_to_cix.py"),
                              ("yui", "yui_to_cix.py")):
        library_script_path = os.path.join(scriptpath, dirname, filename)
        p = os.popen("python %s -u" % (library_script_path)).read()
예제 #3
0
def main():
    # More robust for determining the perforce script location
    cix_filename = "javascript.cix"
    scriptpath = os.path.dirname(__file__)
    if not scriptpath:
        scriptpath = "."
    scriptpath = os.path.abspath(scriptpath)
    cix_directory = scriptpath
    # Get main codeintel directory, 3 up from this script location!
    for i in range(3):
        cix_directory = os.path.dirname(cix_directory)
    cix_filename = os.path.join(
        cix_directory, "lib", "codeintel2", "stdlibs", cix_filename)

    # Generate the cix files
    for filename in ("ecmaToCodeintel.py", "dom0_to_cix.py", "dom2_to_cix.py"):
        p = os.popen("python %s" % (os.path.join(scriptpath, filename))).read()
    # Combine the libraries
    cixtree = ciElementTree.parse(os.path.join(scriptpath, "javascript.cix"))
    cixscope = cixtree.find("file/scope")

    # Note: XMLHttpRequest cix comes from the Mozilla implementation in:
    #       nsIXMLHttpRequest.idl
    for domname in ("XMLHttpRequest", "dom0", "dom2"):
        # cixscope.append(ciElementTree.Comment(" %s structure " % (domname)))
        et = ciElementTree.parse("%s.cix" % (
            os.path.join(scriptpath, domname)))
        for scope in et.findall("//file/scope"):
            for child in scope.getchildren():
                # Ensure we remove from the dom tree first, otherwise
                # we generate double elements
                scope.remove(child)
                cixscope.append(child)

    pretty_tree_from_tree(cixtree.getroot())

    update_documentation_sentences(cixtree)

    p4update(cix_filename, ciElementTree.tostring(cixtree.getroot()))

    # Update libraries
    for dirname, filename in (("dojo", "dojo_json_to_cix.py"),
                              ("MochiKit", "mochikit_to_cix.py"),
                              ("prototype", "prototype_to_cix.py"),
                              ("yui", "yui_to_cix.py")):
        library_script_path = os.path.join(scriptpath, dirname, filename)
        p = os.popen("python %s -u" % (library_script_path)).read()
예제 #4
0
def get_tree_from_cix(yui_version):
    cix_file = glob("%s%syui_v%s.cix" % (join(dirname(
        abspath(__file__)), "apicatalogs"), os.sep, yui_version))[0]
    try:
        return ET.parse(cix_file).getroot()
    except:
        log.exception("Unable to load cix file: %r", cix_file)
    return None
예제 #5
0
 def parse(self):
     self.tree = ElementTree.parse(self.filename, NamespaceParser())
     self.root = self.tree.getroot()
     if self.root.tagName != "grammar":
         raise "Invalid RNG file [%s] root tag [%s]" % (self.filename, self.root.tagName)
     self.parent_map = dict((c, p) for p in self.tree.getiterator() for c in p)
     self.parseNode(self.root)
     self.dataset.resolveRefs()
예제 #6
0
 def parse(self):
     # XXX support HTTP URI's
     self.tree = ElementTree.parse(self.uri, NamespaceParser())
     self.root = self.tree.getroot()
     if self.root.tagName != "catalog":
         raise "Invalid catalog file [%s] root tag [%s]" % (self.uri, self.root.tagName)
     self.parent_map = dict((c, p) for p in self.tree.getiterator() for c in p)
     self._parseNode(self.root)
예제 #7
0
 def parse(self):
     self.tree = ElementTree.parse(self.filename, NamespaceParser())
     self.root = self.tree.getroot()
     if self.root.tagName != "grammar":
         raise "Invalid RNG file [%s] root tag [%s]" % (self.filename,
                                                        self.root.tagName)
     self.parent_map = dict(
         (c, p) for p in self.tree.getiterator() for c in p)
     self.parseNode(self.root)
     self.dataset.resolveRefs()
예제 #8
0
def mergeCixFiles(opts, filename1, filename2, outputfilename):
    e1 = parse(filename1).getroot().getchildren()[0]
    mergedcixroot = parse(filename2).getroot()
    e2 = mergedcixroot.getchildren()[0]
    elems1 = []
    elems2 = []
    if opts.lpath:
        for lpath in opts.lpath:
            elem1 = e1
            elem2 = e2
            lpath_split = lpath.split(".")
            for i in range(len(lpath_split)):
                name = lpath_split[i]
                new_elem1 = elem1.names.get(name)
                new_elem2 = elem2.names.get(name)
                if new_elem1 is None and new_elem2 is None:
                    print "lpath not found in either cix file: %r (skipping it)" % (
                        lpath, )
                    break
                elif new_elem2 is None:
                    answer = raw_input(
                        "lpath %r only found in first cix file, copy over? [Yn]"
                        % (lpath, ))
                    if answer.lower() not in ("n", "no"):
                        merge_missing(elem1, [name], lpath_split[:i - 1], e2)
                    break
                # elif new_elem1 is None:
                #    print "lpath not found in either cix files: %r" % (lpath, )
                #    break
                elem1 = new_elem1
                elem2 = new_elem2
            else:
                elems1.append(elem1)
                elems2.append(elem2)
    else:
        elems1 = [e1]
        elems2 = [e2]
    for e1, e2 in zip(elems1, elems2):
        print "Diffing elements: %r, %r" % (e1, e2)
        diffElements(opts, [], e1, e2)

    pretty_tree_from_tree(mergedcixroot)
    file(outputfilename, "w").write(cixtostring(mergedcixroot))
예제 #9
0
def mergeCixFiles(opts, filename1, filename2, outputfilename):
    e1 = parse(filename1).getroot().getchildren()[0]
    mergedcixroot = parse(filename2).getroot()
    e2 = mergedcixroot.getchildren()[0]
    elems1 = []
    elems2 = []
    if opts.lpath:
        for lpath in opts.lpath:
            elem1 = e1
            elem2 = e2
            lpath_split = lpath.split(".")
            for i in range(len(lpath_split)):
                name = lpath_split[i]
                new_elem1 = elem1.names.get(name)
                new_elem2 = elem2.names.get(name)
                if new_elem1 is None and new_elem2 is None:
                    print "lpath not found in either cix file: %r (skipping it)" % (lpath, )
                    break
                elif new_elem2 is None:
                    answer = raw_input(
                        "lpath %r only found in first cix file, copy over? [Yn]" % (lpath, ))
                    if answer.lower() not in ("n", "no"):
                        merge_missing(elem1, [name], lpath_split[:i-1], e2)
                    break
                # elif new_elem1 is None:
                #    print "lpath not found in either cix files: %r" % (lpath, )
                #    break
                elem1 = new_elem1
                elem2 = new_elem2
            else:
                elems1.append(elem1)
                elems2.append(elem2)
    else:
        elems1 = [e1]
        elems2 = [e2]
    for e1, e2 in zip(elems1, elems2):
        print "Diffing elements: %r, %r" % (e1, e2)
        diffElements(opts, [], e1, e2)

    pretty_tree_from_tree(mergedcixroot)
    file(outputfilename, "w").write(cixtostring(mergedcixroot))
예제 #10
0
def tree_from_cix_path(cix_path):
    """Return a (ci)tree for the CIX content in the given path.

    Raises pyexpat.ExpatError if the CIX content could not be parsed.
    """
    tree = ET.parse(cix_path).getroot()
    version = tree.get("version")
    if version == CIX_VERSION:
        return tree
    elif version == "0.1":
        return tree_2_0_from_tree_0_1(tree)
    else:
        raise CodeIntelError("unknown CIX version: %r" % version)
예제 #11
0
def tree_from_cix_path(cix_path):
    """Return a (ci)tree for the CIX content in the given path.

    Raises pyexpat.ExpatError if the CIX content could not be parsed.
    """
    tree = ET.parse(cix_path).getroot()
    version = tree.get("version")
    if version == CIX_VERSION:
        return tree
    elif version == "0.1":
        return tree_2_0_from_tree_0_1(tree)
    else:
        raise CodeIntelError("unknown CIX version: %r" % version)
예제 #12
0
 def load_blob(self, dbsubpath):
     """Load the blob and all persisted blob cache keys from disk."""
     log.debug("fs-read: load blob `%s'", dbsubpath[len(self.base_dir) + 1 :])
     blob = ET.parse(dbsubpath + ".blob").getroot()
     blob_files = glob(dbsubpath + ".*")
     for blob_cache_file in blob_files:
         ext = splitext(blob_cache_file)[1]
         if ext == ".blob":
             continue  # this is the blob ET itself
         cache_key = ext[1:]
         try:
             blob.cache[cache_key] = self.load_pickle(blob_cache_file)
         except (UnpicklingError, ImportError) as ex:
             log.warn("error unpickling `%s' (skipping): %s", blob_cache_file, ex)
     return blob
예제 #13
0
 def load_blob(self, dbsubpath):
     """Load the blob and all persisted blob cache keys from disk."""
     log.debug("fs-read: load blob `%s'", dbsubpath[len(self.base_dir)+1:])
     blob = ET.parse(dbsubpath+".blob").getroot()
     blob_files = glob(dbsubpath+".*")
     for blob_cache_file in blob_files:
         ext = splitext(blob_cache_file)[1]
         if ext == ".blob": continue # this is the blob ET itself
         cache_key = ext[1:]
         try:
             blob.cache[cache_key] = self.load_pickle(blob_cache_file)
         except (UnpicklingError, ImportError) as ex:
             log.warn("error unpickling `%s' (skipping): %s",
                      blob_cache_file, ex)
     return blob
예제 #14
0
def diffCixFiles(opts, filename1, filename2):
    e1 = parse(filename1).getroot().getchildren()[0]
    e2 = parse(filename2).getroot().getchildren()[0]
    elems1 = []
    elems2 = []
    if opts.lpath:
        for lpath in opts.lpath:
            elem1 = e1
            elem2 = e2
            for name in lpath.split("."):
                try:
                    elem1 = elem1.names[name]
                    elem2 = elem2.names[name]
                except KeyError:
                    print "lpath not found in both cix files: %r" % (lpath, )
                    return
            elems1.append(elem1)
            elems2.append(elem2)
    else:
        elems1 = [e1]
        elems2 = [e2]
    for e1, e2 in zip(elems1, elems2):
        print "Diffing elements: %r, %r" % (e1, e2)
        diffElements(opts, [], e1, e2)
예제 #15
0
def diffCixFiles(opts, filename1, filename2):
    e1 = parse(filename1).getroot().getchildren()[0]
    e2 = parse(filename2).getroot().getchildren()[0]
    elems1 = []
    elems2 = []
    if opts.lpath:
        for lpath in opts.lpath:
            elem1 = e1
            elem2 = e2
            for name in lpath.split("."):
                try:
                    elem1 = elem1.names[name]
                    elem2 = elem2.names[name]
                except KeyError:
                    print "lpath not found in both cix files: %r" % (lpath, )
                    return
            elems1.append(elem1)
            elems2.append(elem2)
    else:
        elems1 = [e1]
        elems2 = [e2]
    for e1, e2 in zip(elems1, elems2):
        print "Diffing elements: %r, %r" % (e1, e2)
        diffElements(opts, [], e1, e2)
예제 #16
0
        except Exception:
            import traceback
            print("\nEXCEPTION:", sys.exc_info()[1], "when processing", mod)
            traceback.print_exc()

    gencix.writeCixFileForElement(fname, root)

    print("done writing generic bits: %r." % fname)


fname = '../../../lib/codeintel2/stdlibs/%s-%d.%d.cix' % (lang.lower(), major, minor)
pywin32fname = '../../../lib/codeintel2/catalogs/pywin32.cix' 

# Remember the original cix, we'll merge with it after the current scan.
try:
    orig_root = parse(fname).getroot()
except (IOError, SyntaxError):
    # When the CIX file does not yet exist (new scan), create an empty root.
    orig_root = Element("codeintel", version="2.0")
    SubElement(orig_root, "file", lang=lang, mtime=str(0),
               path=os.path.basename(fname))

process_module_list(module_names, fname)

if sys.platform.startswith('win'):
    # Generate the windows specific bits into separate CIX files.
    process_module_list(pywin32_module_names, pywin32fname, 
                        catalog_name="PyWin32",
                        catalog_description="Python Extensions for Windows")

# Read in the just generated CIX.
예제 #17
0
version = "%prog 0.1"
desc = """Blend the XML files into one."""
parser = OptionParser(prog="platinfo", usage=usage,
                      version=version,
                      description=desc)

parser.add_option("--orig-file", dest="origfile")
parser.add_option("-q", "--quiet",
                  action="store_false", dest="verbose", default=True,
                  help="don't print status messages to stdout")
(options, args) = parser.parse_args()
if not options.origfile:
    print "Usage: combine_cixes.py --orig-file file file..."
    sys.exit()

origTree = ET.parse(options.origfile)
origTopLevel = origTree.getroot()
origFile = origTopLevel.getchildren()[0]
origBlobStar = origFile.getchildren()[0]
if origBlobStar.get("ilk") != "blob" or origBlobStar.get("name") != "*":
    raise "Unexpected orig tree"

newTrees = [ET.parse(x) for x in args]

# Priority:
# yaml - all
# reflection - buildints
# reflection - binary
# parse - stdlib

# Trees:
if options.outfile:
    if len(args) > 0:
        Usage()
    else:
        outfile = options.outfile
elif len(args) == 0:
    Usage()
else:
    outfile = args[0]

if infile == outfile:
    print "Trying to overwrite file %s" % outfile
    Usage()

origTree = ET.parse(infile)

adjusted_node = 0


def check_redundant_namespace(elem):
    global adjusted_node
    if not elem:
        return
    elif elem.get("ilk") == "namespace":
        top_name = elem.get("name")
        if top_name:
            top_name_double_colon = top_name + "::"
            for child in elem:
                name = child.get("name")
                if name and name.startswith(top_name_double_colon):
예제 #19
0
version = "%prog 0.1"
desc = """Blend the XML files into one."""
parser = OptionParser(prog="platinfo", usage=usage,
                                    version=version,
                                    description=desc)

parser.add_option("--orig-file", dest="origfile")
parser.add_option("-q", "--quiet",
                  action="store_false", dest="verbose", default=True,
                  help="don't print status messages to stdout")
(options, args) = parser.parse_args()
if not options.origfile:
    print "Usage: combine_cixes.py --orig-file file file..."
    sys.exit()

origTree = ET.parse(options.origfile)
origTopLevel = origTree.getroot()
origFile = origTopLevel.getchildren()[0]
origBlobStar = origFile.getchildren()[0]
if origBlobStar.get("ilk") != "blob" or origBlobStar.get("name") != "*":
    raise "Unexpected orig tree"

newTrees = [ET.parse(x) for x in args]

# Priority:
# yaml - all
# reflection - buildints
# reflection - binary
# parse - stdlib

# Trees:
예제 #20
0
This is expected to be run manually, and generates node.js.cix
"""

from ciElementTree import parse
import os
import subprocess
import sys
import time
from os.path import abspath, dirname, join

# make sure python can find ../ecmaToCodeintel.py
scriptdir = dirname(abspath(__file__))
sys.path.append(dirname(scriptdir))

# parse the pre-written Node.js cix
tree = parse(join(scriptdir, "node_globals.cix"))
tree.find("/file").set("mtime", str(int(time.time())))

# generate ../javascript.cix
import ecmaToCodeintel
ecmaToCodeintel.performXSLTransform()
ecmaToCodeintel.fixTags()

# parse ../javascript.cix
jstree = parse(join(dirname(scriptdir), "javascript.cix"))

# copy all elements over
scope = tree.find("/file/scope")
for elem in jstree.find("/file/scope"):
    scope.append(elem)
if options.outfile:
    if len(args) > 0:
        Usage()
    else:
        outfile = options.outfile
elif len(args) == 0:
    Usage()
else:
    outfile = args[0]

if infile == outfile:
    print "Trying to overwrite file %s" % outfile
    Usage()

origTree = ET.parse(infile)

adjusted_node = 0


def check_redundant_namespace(elem):
    global adjusted_node
    if not elem:
        return
    elif elem.get("ilk") == "namespace":
        top_name = elem.get("name")
        if top_name:
            top_name_double_colon = top_name + "::"
            for child in elem:
                name = child.get("name")
                if name and name.startswith(top_name_double_colon):