def get_enso_commands_folder(self): """ Returns the location of the Enso scripts folder. """ from enso.providers import getInterface return getInterface("scripts_folder")()
def __init__(self, eventManager, commandManager): self._scriptCmdTracker = ScriptCommandTracker(commandManager, eventManager) self._scriptFilename = os.path.expanduser(SCRIPTS_FILE_NAME) from enso.providers import getInterface self._scriptFolder = getInterface("scripts_folder")() self._lastMods = {} self._registerDependencies() eventManager.registerResponder(self._updateScripts, "startQuasimode")
def __init__(self, eventManager, commandManager): self._scriptCmdTracker = ScriptCommandTracker(commandManager, eventManager) self._scriptFilename = os.path.expanduser(SCRIPTS_FILE_NAME) from enso.providers import getInterface self._scriptFolder = getInterface("scripts_folder")() self._lastMods = {} self._registerDependencies() eventManager.registerResponder(self._updateScripts, "startQuasimode") commandManager.registerCommand(TracebackCommand.NAME, TracebackCommand())
def install_command_from_url(command_url): try: fp = urllib.urlopen(command_url) except: msg = "Couldn't install that command" displayMessage(msg) return text = fp.read() fp.close() lines = text.split("\n") if len(lines) < 3: msg = "There was no command to install!" displayMessage(msg) return while lines[0].strip() == "": lines.pop(0) command_file_name = command_url.split("/")[-1] if not command_file_name.endswith(".py"): msg = "Couldn't install this command %s" % command_file_name displayMessage(msg) return from enso.providers import getInterface cmd_folder = getInterface("scripts_folder")() command_file_path = os.path.join(cmd_folder, command_file_name) shortname = os.path.splitext(command_file_name)[0] if os.path.exists(command_file_path): msg = "You already have a command named %s" % shortname displayMessage(msg) return allGlobals = {} # normalise text for crlf text = text.replace('\r\n', '\n').replace('\r', '\n') code = compile(text, command_file_path, "exec") exec code in allGlobals installed_commands = [ x["cmdName"] for x in cmdretriever.getCommandsFromObjects(allGlobals) ] if len(installed_commands) == 1: install_message = "%s is now a command" % installed_commands[0] else: install_message = "%s are now commands" % ", ".join(installed_commands) # Use binary mode for writing so endlines are not converted to "\r\n" on win32 fp = open(command_file_path, "wb") fp.write(text) fp.close() displayMessage(install_message)
def install_command_from_url(command_url): try: fp = urllib.urlopen(command_url) except: msg = "Couldn't install that command" displayMessage(msg) return text = fp.read() fp.close() lines = text.split("\n") if len(lines) < 3: msg = "There was no command to install!" displayMessage(msg) return while lines[0].strip() == "": lines.pop(0) command_file_name = command_url.split("/")[-1] if not command_file_name.endswith(".py"): msg = "Couldn't install this command %s" % command_file_name displayMessage(msg) return from enso.providers import getInterface cmd_folder = getInterface("scripts_folder")() command_file_path = os.path.join(cmd_folder, command_file_name) shortname = os.path.splitext(command_file_name)[0] if os.path.exists(command_file_path): msg = "You already have a command named %s" % shortname displayMessage(msg) return allGlobals = {} # normalise text for crlf text = text.replace('\r\n','\n').replace('\r','\n') code = compile( text, command_file_path, "exec" ) exec code in allGlobals installed_commands = [x["cmdName"] for x in cmdretriever.getCommandsFromObjects(allGlobals)] if len(installed_commands) == 1: install_message = "%s is now a command" % installed_commands[0] else: install_message = "%s are now commands" % ", ".join(installed_commands) # Use binary mode for writing so endlines are not converted to "\r\n" on win32 fp = open(command_file_path, "wb") fp.write(text) fp.close() displayMessage(install_message)