def _getTimelineRecords(): global __timelineRecords if __timelineRecords is not None: return __timelineRecords log.debug("start Komodo Jaguar") argv = [which.which("komodo"), "-j"] # run Jaguar if log.isEnabledFor(logging.DEBUG): argv.append("-v") env = dict(os.environ) # get a copy env["NS_TIMELINE_ENABLE"] = "1" doNotDeleteLog = "NS_TIMELINE_LOG_FILE" in os.environ timelineLog = os.environ.get("NS_TIMELINE_LOG_FILE", tempfile.mktemp()) log.debug("timeline log file: '%s'", timelineLog) env["NS_TIMELINE_LOG_FILE"] = timelineLog env["KOMODO_NONINTERACTIVE"] = "1" #env["KO_TIMELINE_PYXPCOM"] = "1" #env["KO_TIMELINE_SCIMOZ"] = "1" #env["KO_TIMELINE_PYOS"] = "1" try: p = process.Process(argv, env=env) time.sleep(1) # give it time to "announce" that it is starting up # Run macros. if pymacro is not None: log.debug("running Python macro") kc.issue("macro", ["--language", "python", repr(pymacro)]) if jsmacro is not None: log.debug("running JavaScript macro") kc.issue("macro", ["--language", "javascript", repr(jsmacro)]) #XXX How to synchronize??? Wait until 'quit' gets through? # But .wait() doesn't work because it waits for komodo.exe # and not mozilla.exe. kc.issue("quit") p.wait() time.sleep(15) __timelineRecords = ptimeline.parse(timelineLog) return __timelineRecords finally: if (not doNotDeleteLog and os.path.exists(timelineLog) and not log.isEnabledFor(logging.DEBUG)): try: os.remove(timelineLog) except OSError, ex: log.warn("Could not remove timeline log file, '%s': %s", timelineLog, ex)
class KCShell(_ListCmd): """ kc - issue Komodo commandments Usage: kc [<options>...] <command> [<args>...] Options: -h, --help Print this help and exit. -V, --version Print the version info and exit. -v, --verbose More verbose output. -k <version> Specify Komodo <major>.<minor> version to which to connect. Defaults to "3.0". Komodo supports a system by which one can connect to a running Komodo and issue commands. This is called the Komodo Commandment system and each such command is called a "commandment". This script allows one to issue these commandments from the command-line. Getting Started: kc help print this help kc help commandments list all Komodo commandments kc help <commandment> help on a specific commandment """ name = 'kc' def emptyline(self): self.do_help(['help']) def help_commandments(self): sys.stdout.write("""\ General 'kc' commands: open open a file macro run the given code as a macro in Komodo macro_file run the given macro file in Komodo quit quit Komodo """) sys.stdout.flush() def do_open(self, argv): """ open -- open a file in Komodo kc open [<options>...] <file> Options: -s, --selection <selection> Specify a position/selection in the opened file. The given selection numbers are 0-based character indices into the file. (XXX Consider giving alternate interface that 'komodo.exe' provides.) The given file is opened in Komodo. """ # Process options. try: optlist, args = getopt.getopt(argv[1:], "s:", ["selection="]) except getopt.GetoptError, ex: log.error("open: %s", ex) log.error("open: try 'kc help open'") return 1 cargs = [] for opt, optarg in optlist: if opt in ("-s", "--selection"): cargs += ["--selection", optarg] # Process arguments. if len(args) != 1: log.error("open: incorrect number of arguments: %s", args) log.error("open: try 'kc help open'") return 1 file = args[0] if not os.path.isabs(file): file = os.path.abspath(file) cargs.append(file) _ensureKocommandmentsOnPath() import kocommandments try: kocommandments.issue("open", cargs, gKomodoVer) except kocommandments.KoCommandmentsError, ex: raise KCError(ex)
cargs += ["--language", "javascript"] elif opt == "-p": cargs += ["--language", "python"] # Process arguments. if len(args) != 1: log.error("macro: incorrect number of arguments: %s", args) log.error("macro: try 'kc help macro'") return 1 code = repr(args[0]) cargs.append(code) _ensureKocommandmentsOnPath() import kocommandments try: kocommandments.issue("macro", cargs, gKomodoVer) except kocommandments.KoCommandmentsError, ex: raise KCError(ex) def do_macro_file(self, argv): """ macro_file -- run a macro file in Komodo kc macro_file [<options>...] <macro-file> Options: -l, --language <language> Specify the language of the macro_file. Valid values are "python" (the default) and "javascript". -j Shortcut for "--language=javascript" -p Shortcut for "--language=python"