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()
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()
def do_play(self, subcmd, opts): """Run my current play/dev code. ${cmd_usage} ${cmd_option_list} """ import pprint import random import ciElementTree as ET from codeintel2.manager import Manager from codeintel2.tree import pretty_tree_from_tree from codeintel2.common import LogEvalController, Error from codeintel2.util import tree_from_cix, dedent, unmark_text, banner from ci2 import _escaped_text_from_text if False: lang = "CSS" markedup_content = dedent(""" /* http://www.w3.org/TR/REC-CSS2/fonts.html#propdef-font-weight */ h1 { border: 1px solid black; font-weight /* hi */: <|> !important } """) content, data = unmark_text(markedup_content) pos = data["pos"] mgr = Manager() # mgr.upgrade() # Don't need it for just CSS usage. mgr.initialize() try: buf = mgr.buf_from_content(content, lang=lang, path="play.css") trg = buf.trg_from_pos(pos) if trg is None: raise Error("unexpected trigger: %r" % trg) completions = buf.cplns_from_trg(trg) print("COMPLETIONS: %r" % completions) finally: mgr.finalize() elif False: lang = "Python" path = os.path.join("<Unsaved>", "rand%d.py" % random.randint(0, 100)) markedup_content = dedent(""" import sys, os class Foo: def bar(self): pass sys.<|>path # should have path in completion list f = Foo() """) content, data = unmark_text(markedup_content) print(banner(path)) print(_escaped_text_from_text(content, "whitespace")) pos = data["pos"] mgr = Manager() mgr.upgrade() mgr.initialize() try: buf = mgr.buf_from_content(content, lang=lang, path=path) print(banner("cix", '-')) print(buf.cix) trg = buf.trg_from_pos(pos) if trg is None: raise Error("unexpected trigger: %r" % trg) print(banner("completions", '-')) ctlr = LogEvalController(self.log) buf.async_eval_at_trg(trg, ctlr) ctlr.wait(2) # XXX if not ctlr.is_done(): ctlr.abort() raise Error("XXX async eval timed out") pprint.pprint(ctlr.cplns) print(banner(None)) finally: mgr.finalize() elif False: lang = "Ruby" path = os.path.join("<Unsaved>", "rand%d.py" % random.randint(0, 100)) markedup_content = dedent("""\ r<1>equire 'net/http' include Net req = HTTPRequest.new req.<2>get() """) content, data = unmark_text(markedup_content) print(banner(path)) print(_escaped_text_from_text(content, "whitespace")) pos = data[1] mgr = Manager() mgr.upgrade() mgr.initialize() try: buf = mgr.buf_from_content(content, lang=lang, path=path) print(banner("cix", '-')) cix = buf.cix print(ET.tostring(pretty_tree_from_tree(tree_from_cix(cix)))) trg = buf.trg_from_pos(pos, implicit=False) if trg is None: raise Error("unexpected trigger: %r" % trg) print(banner("completions", '-')) ctlr = LogEvalController(self.log) buf.async_eval_at_trg(trg, ctlr) ctlr.wait(30) # XXX if not ctlr.is_done(): ctlr.abort() raise Error("XXX async eval timed out") pprint.pprint(ctlr.cplns) print(banner(None)) finally: mgr.finalize()
def cix(self): """The CIX for this buffer. Will lazily scan if necessary.""" return ET.tostring(self.tree)
def do_play(self, subcmd, opts): """Run my current play/dev code. ${cmd_usage} ${cmd_option_list} """ if False: lang = "CSS" markedup_content = dedent(""" /* http://www.w3.org/TR/REC-CSS2/fonts.html#propdef-font-weight */ h1 { border: 1px solid black; font-weight /* hi */: <|> !important } """) content, data = unmark_text(markedup_content) pos = data["pos"] mgr = Manager() #mgr.upgrade() # Don't need it for just CSS usage. mgr.initialize() try: buf = mgr.buf_from_content(content, lang=lang, path="play.css") trg = buf.trg_from_pos(pos) if trg is None: raise Error("unexpected trigger: %r" % trg) completions = buf.cplns_from_trg(trg) print("COMPLETIONS: %r" % completions) finally: mgr.finalize() elif False: lang = "Python" path = join("<Unsaved>", "rand%d.py" % random.randint(0, 100)) markedup_content = dedent(""" import sys, os class Foo: def bar(self): pass sys.<|>path # should have path in completion list f = Foo() """) content, data = unmark_text(markedup_content) print(banner(path)) print(_escaped_text_from_text(content, "whitespace")) pos = data["pos"] mgr = Manager() mgr.upgrade() mgr.initialize() try: buf = mgr.buf_from_content(content, lang=lang, path=path) print(banner("cix", '-')) print(buf.cix) trg = buf.trg_from_pos(pos) if trg is None: raise Error("unexpected trigger: %r" % trg) print(banner("completions", '-')) ctlr = LogEvalController(log) buf.async_eval_at_trg(trg, ctlr) ctlr.wait(2) #XXX if not ctlr.is_done(): ctlr.abort() raise Error("XXX async eval timed out") pprint(ctlr.cplns) print(banner(None)) finally: mgr.finalize() elif False: lang = "Ruby" path = join("<Unsaved>", "rand%d.py" % random.randint(0, 100)) markedup_content = dedent("""\ r<1>equire 'net/http' include Net req = HTTPRequest.new req.<2>get() """) content, data = unmark_text(markedup_content) print(banner(path)) print(_escaped_text_from_text(content, "whitespace")) pos = data[1] mgr = Manager() mgr.upgrade() mgr.initialize() try: buf = mgr.buf_from_content(content, lang=lang, path=path) print(banner("cix", '-')) cix = buf.cix print( ET.tostring(pretty_tree_from_tree(tree_from_cix(buf.cix)))) trg = buf.trg_from_pos(pos, implicit=False) if trg is None: raise Error("unexpected trigger: %r" % trg) print(banner("completions", '-')) ctlr = LogEvalController(log) buf.async_eval_at_trg(trg, ctlr) ctlr.wait(30) #XXX if not ctlr.is_done(): ctlr.abort() raise Error("XXX async eval timed out") pprint(ctlr.cplns) print(banner(None)) finally: mgr.finalize()
if t and t.get("ilk") in reg_ilks: replace_node(origBlobStar, curr_tree, t, i) i += 1 print "After doing yaml-nodes, orig tree has %d nodes" % len(origBlobStar) print "Builtins: %d replacements, %d additions" % (num_replacements, num_additions) i = 0 for t in bin_tree: replace_node(origFile, bin_tree, t, i) i += 1 print "After doing binary modules, orig tree has %d nodes" % len(origBlobStar) print "Builtins: %d replacements, %d additions" % (num_replacements, num_additions) # Finally update the YAML nodes, assuming that if we do a replacement # we can replace the entire subtree. i = 0 for t in yaml_stdlib_tree: replace_node(origFile, yaml_stdlib_tree, t, i) i += 1 print "After doing yaml modules, orig tree has %d nodes" % len(origBlobStar) print "Builtins: %d replacements, %d additions" % (num_replacements, num_additions) newFile = options.origfile + ".new" fd = open(newFile, "w") fd.write(ET.tostring(pretty_tree_from_tree(origTopLevel))) fd.close() print "Done writing to file %s" % newFile
replace_node(origBlobStar, curr_tree, t, i) i += 1 print "After doing yaml-nodes, orig tree has %d nodes" % len(origBlobStar) print "Builtins: %d replacements, %d additions" % (num_replacements, num_additions) i = 0 for t in bin_tree: replace_node(origFile, bin_tree, t, i) i += 1 print "After doing binary modules, orig tree has %d nodes" % len(origBlobStar) print "Builtins: %d replacements, %d additions" % (num_replacements, num_additions) # Finally update the YAML nodes, assuming that if we do a replacement # we can replace the entire subtree. i = 0 for t in yaml_stdlib_tree: replace_node(origFile, yaml_stdlib_tree, t, i) i += 1 print "After doing yaml modules, orig tree has %d nodes" % len(origBlobStar) print "Builtins: %d replacements, %d additions" % (num_replacements, num_additions) newFile = options.origfile + ".new" fd = open(newFile, "w") fd.write(ET.tostring(pretty_tree_from_tree(origTopLevel))) fd.close() print "Done writing to file %s" % newFile
def main(argv): logging.basicConfig() # Parse options. try: opts, args = getopt.getopt(argv[1:], "Vvhf:cL:", ["version", "verbose", "help", "filename=", "md5=", "mtime=", "clock", "language="]) except getopt.GetoptError as ex: log.error(str(ex)) log.error("Try `tclcile --help'.") return 1 numVerboses = 0 stdinFilename = None md5sum = None mtime = None lang = "Tcl" global _gClockIt for opt, optarg in opts: if opt in ("-h", "--help"): sys.stdout.write(__doc__) return elif opt in ("-V", "--version"): ver = '.'.join([str(part) for part in _version_]) print("tclcile %s" % ver) return elif opt in ("-v", "--verbose"): numVerboses += 1 if numVerboses == 1: #log.setLevel(logging.INFO) pass else: #log.setLevel(logging.DEBUG) pass elif opt in ("-f", "--filename"): stdinFilename = optarg elif opt in ("-L", "--language"): lang = optarg elif opt in ("--md5",): md5sum = optarg elif opt in ("--mtime",): mtime = optarg elif opt in ("-c", "--clock"): _gClockIt = 1 global _gClock if sys.platform.startswith("win"): _gClock = time.clock else: _gClock = time.time if len(args) == 0: contentOnStdin = 1 filenames = [stdinFilename or "<stdin>"] else: contentOnStdin = 0 paths = [] for arg in args: paths += glob.glob(arg) filenames = [] for path in paths: if isfile(path): filenames.append(path) elif isdir(path): rbfiles = [join(path, n) for n in os.listdir(path) if splitext(n)[1] == ".rb"] rbfiles = [f for f in rbfiles if isfile(f)] filenames += rbfiles try: for filename in filenames: if contentOnStdin: log.debug("reading content from stdin") content = sys.stdin.read() log.debug("finished reading content from stdin") if mtime is None: mtime = int(time.time()) else: if mtime is None: mtime = int(os.stat(filename)[stat.ST_MTIME]) content = open(filename, 'r').read() if _gClockIt: sys.stdout.write("scanning '%s'..." % filename) global _gStartTime _gStartTime = _gClock() data = tostring(scan_purelang(content, filename)) if _gClockIt: sys.stdout.write(" %.3fs\n" % (_gClock()-_gStartTime)) elif data: sys.stdout.write(data) except KeyboardInterrupt: log.debug("user abort") return 1 if 0: # except Exception, ex: log.error(str(ex)) if log.isEnabledFor(logging.DEBUG): print() import traceback traceback.print_exception(*sys.exc_info()) return 1
def main(argv): logging.basicConfig() # Parse options. try: opts, args = getopt.getopt(argv[1:], "Vvhf:cL:", ["version", "verbose", "help", "filename=", "md5=", "mtime=", "clock", "language="]) except getopt.GetoptError as ex: log.error(str(ex)) log.error("Try `tclcile --help'.") return 1 numVerboses = 0 stdinFilename = None md5sum = None mtime = None lang = "Tcl" global _gClockIt for opt, optarg in opts: if opt in ("-h", "--help"): sys.stdout.write(__doc__) return elif opt in ("-V", "--version"): ver = '.'.join([str(part) for part in _version_]) print("tclcile %s" % ver) return elif opt in ("-v", "--verbose"): numVerboses += 1 if numVerboses == 1: log.setLevel(logging.INFO) else: log.setLevel(logging.DEBUG) elif opt in ("-f", "--filename"): stdinFilename = optarg elif opt in ("-L", "--language"): lang = optarg elif opt in ("--md5",): md5sum = optarg elif opt in ("--mtime",): mtime = optarg elif opt in ("-c", "--clock"): _gClockIt = 1 global _gClock if sys.platform.startswith("win"): _gClock = time.clock else: _gClock = time.time if len(args) == 0: contentOnStdin = 1 filenames = [stdinFilename or "<stdin>"] else: contentOnStdin = 0 paths = [] for arg in args: paths += glob.glob(arg) filenames = [] for path in paths: if isfile(path): filenames.append(path) elif isdir(path): rbfiles = [join(path, n) for n in os.listdir(path) if splitext(n)[1] == ".rb"] rbfiles = [f for f in rbfiles if isfile(f)] filenames += rbfiles try: for filename in filenames: if contentOnStdin: log.debug("reading content from stdin") content = sys.stdin.read() log.debug("finished reading content from stdin") if mtime is None: mtime = int(time.time()) else: if mtime is None: mtime = int(os.stat(filename)[stat.ST_MTIME]) content = open(filename, 'r').read() if _gClockIt: sys.stdout.write("scanning '%s'..." % filename) global _gStartTime _gStartTime = _gClock() data = tostring(scan_purelang(content, filename)) if _gClockIt: sys.stdout.write(" %.3fs\n" % (_gClock()-_gStartTime)) elif data: sys.stdout.write(data) except KeyboardInterrupt: log.debug("user abort") return 1 if 0: #except Exception, ex: log.error(str(ex)) if log.isEnabledFor(logging.DEBUG): print() import traceback traceback.print_exception(*sys.exc_info()) return 1
if contentOnStdin: log.debug("reading content from stdin") content = sys.stdin.read() log.debug("finished reading content from stdin") if mtime is None: mtime = int(time.time()) else: if mtime is None: mtime = int(os.stat(filename)[stat.ST_MTIME]) content = open(filename, 'r').read() if _gClockIt: sys.stdout.write("scanning '%s'..." % filename) global _gStartTime _gStartTime = _gClock() data = tostring(scan_purelang(content, filename)) if _gClockIt: sys.stdout.write(" %.3fs\n" % (_gClock() - _gStartTime)) elif data: sys.stdout.write(data) except KeyboardInterrupt: log.debug("user abort") return 1 if 0: #except Exception, ex: log.error(str(ex)) if log.isEnabledFor(logging.DEBUG): print import traceback traceback.print_exception(*sys.exc_info()) return 1
if contentOnStdin: log.debug("reading content from stdin") content = sys.stdin.read() log.debug("finished reading content from stdin") if mtime is None: mtime = int(time.time()) else: if mtime is None: mtime = int(os.stat(filename)[stat.ST_MTIME]) content = open(filename, 'r').read() if _gClockIt: sys.stdout.write("scanning '%s'..." % filename) global _gStartTime _gStartTime = _gClock() data = tostring(scan_purelang(content, filename)) if _gClockIt: sys.stdout.write(" %.3fs\n" % (_gClock()-_gStartTime)) elif data: sys.stdout.write(data) except KeyboardInterrupt: log.debug("user abort") return 1 if 0: #except Exception, ex: log.error(str(ex)) if log.isEnabledFor(logging.DEBUG): print import traceback traceback.print_exception(*sys.exc_info()) return 1