def __init__(self, options, cmds, log_stream): component.Component.__init__(self, 'ConsoleUI') TermResizeHandler.__init__(self) self.options = options self.log_stream = log_stream # keep track of events for the log view self.events = [] self.torrents = [] self.statusbars = None self.modes = {} self.active_mode = None self.initialized = False try: locale.setlocale(locale.LC_ALL, '') self.encoding = locale.getpreferredencoding() except locale.Error: self.encoding = sys.getdefaultencoding() log.debug('Using encoding: %s', self.encoding) # start up the session proxy self.sessionproxy = SessionProxy() client.set_disconnect_callback(self.on_client_disconnect) # Set the interactive flag to indicate where we should print the output self.interactive = True self._commands = cmds self.coreconfig = CoreConfig()
def __init__(self): super(WebApi, self).__init__('Web', depend=['SessionProxy']) self.hostlist = HostList() self.core_config = CoreConfig() self.event_queue = EventQueue() try: self.sessionproxy = component.get('SessionProxy') except KeyError: self.sessionproxy = SessionProxy()
def __init__(self): super(WebApi, self).__init__("Web", depend=["SessionProxy"]) self.host_list = ConfigManager("hostlist.conf.1.2", DEFAULT_HOSTS) self.core_config = CoreConfig() self.event_queue = EventQueue() try: self.sessionproxy = component.get("SessionProxy") except KeyError: self.sessionproxy = SessionProxy()
def __init__(self, args=None, cmds = None, daemon = None): component.Component.__init__(self, "ConsoleUI", 2) # keep track of events for the log view self.events = [] try: locale.setlocale(locale.LC_ALL, '') self.encoding = locale.getpreferredencoding() except: self.encoding = sys.getdefaultencoding() log.debug("Using encoding: %s", self.encoding) # start up the session proxy self.sessionproxy = SessionProxy() client.set_disconnect_callback(self.on_client_disconnect) # Set the interactive flag to indicate where we should print the output self.interactive = True self._commands = cmds if args: args = args[0] self.interactive = False if not cmds: print "Sorry, couldn't find any commands" return else: from commander import Commander cmdr = Commander(cmds) if daemon: cmdr.exec_args(args,*daemon) else: cmdr.exec_args(args,None,None,None,None) self.coreconfig = CoreConfig() if self.interactive and not deluge.common.windows_check(): # We use the curses.wrapper function to prevent the console from getting # messed up if an uncaught exception is experienced. import curses.wrapper curses.wrapper(self.run) elif self.interactive and deluge.common.windows_check(): print """\nDeluge-console does not run in interactive mode on Windows. \n Please use commands from the command line, eg:\n deluge-console.exe help deluge-console.exe info deluge-console.exe "add --help" deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent" """ else: reactor.run()
def __init__(self, args=None): component.Component.__init__(self, "ConsoleUI", 2) self.batch_write = False try: locale.setlocale(locale.LC_ALL, '') self.encoding = locale.getpreferredencoding() except: self.encoding = sys.getdefaultencoding() log.debug("Using encoding: %s", self.encoding) # Load all the commands self._commands = load_commands(os.path.join(UI_PATH, 'commands')) client.set_disconnect_callback(self.on_client_disconnect) # Set the interactive flag to indicate where we should print the output self.interactive = True if args: # Multiple commands split by ";" commands = [arg.strip() for arg in ' '.join(args).split(';')] self.interactive = False # Try to connect to the daemon (localhost by default) def on_connect(result): def on_started(result): if not self.interactive: def on_started(result): def do_command(result, cmd): return self.do_command(cmd) d = defer.succeed(None) # If we have commands, lets process them, then quit. for command in commands: d.addCallback(do_command, command) if "quit" not in commands and "exit" not in commands: d.addCallback(do_command, "quit") # We need to wait for the rpcs in start() to finish before processing # any of the commands. self.started_deferred.addCallback(on_started) component.start().addCallback(on_started) def on_connect_fail(result): if not self.interactive: self.do_command('quit') connect_cmd = 'connect' if not self.interactive: if commands[0].startswith(connect_cmd): connect_cmd = commands.pop(0) elif 'help' in commands: self.do_command('help') return d = self.do_command(connect_cmd) d.addCallback(on_connect) d.addErrback(on_connect_fail) self.coreconfig = CoreConfig() if self.interactive and not deluge.common.windows_check(): # We use the curses.wrapper function to prevent the console from getting # messed up if an uncaught exception is experienced. import curses.wrapper curses.wrapper(self.run) elif self.interactive and deluge.common.windows_check(): print """\nDeluge-console does not run in interactive mode on Windows. \n Please use commands from the command line, eg:\n deluge-console.exe help deluge-console.exe info deluge-console.exe "add --help" deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent" """ else: reactor.run()