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 connect(self, task, config): """Connects to the deluge daemon and runs on_connect_success """ if config['host'] in ['localhost', '127.0.0.1'] and not config.get('user'): # If an user is not specified, we have to do a lookup for the localclient username/password auth = get_localhost_auth() if auth[0]: config['user'], config['pass'] = auth else: raise PluginError('Unable to get local authentication info for Deluge. ' 'You may need to specify an username and password from your Deluge auth file.') client.set_disconnect_callback(self.on_disconnect) d = client.connect( host=config['host'], port=config['port'], username=config['user'], password=config['pass']) d.addCallback(self.on_connect_success, task, config).addErrback(self.on_connect_fail) result = reactor.run() if isinstance(result, Exception): raise result return result
def first_time(self): client.set_disconnect_callback(component.stop) if self.ui_config["classic_mode"]: self._start_classic() else: self._start_thin()
def connect(self, task, config): """Connects to the deluge daemon and runs on_connect_success """ if config['host'] in ['localhost', '127.0.0.1' ] and not config.get('username'): # If an username is not specified, we have to do a lookup for the localclient username/password auth = get_localhost_auth() if auth[0]: config['username'], config['password'] = auth else: raise plugin.PluginError( 'Unable to get local authentication info for Deluge. You may need to ' 'specify an username and password from your Deluge auth file.' ) client.set_disconnect_callback(self.on_disconnect) d = client.connect(host=config['host'], port=config['port'], username=config['username'], password=config['password']) d.addCallback(self.on_connect_success, task, config).addErrback(self.on_connect_fail) result = reactor.run() if isinstance(result, Exception): raise result return result
def disable(self): client.deregister_event_handler('PluginEnabledEvent', self._json.get_remote_methods) client.deregister_event_handler('PluginDisabledEvent', self._json.get_remote_methods) if client.is_standalone(): component.get('Web.PluginManager').stop() else: client.disconnect() client.set_disconnect_callback(None)
def ConnectToDaemon(): global delugeDaemon host="localhost" port=58846 user="" password="" client.set_disconnect_callback(daemon_disconnect_callback) if debugConnections: print "Connecting to deluge daemon..." delugeDaemon = client.connect(host, port, user, password)
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, 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 = ' '.join(args) 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 enable(self): client.register_event_handler('PluginEnabledEvent', self._json.get_remote_methods) client.register_event_handler('PluginDisabledEvent', self._json.get_remote_methods) if client.is_standalone(): component.get('Web.PluginManager').start() else: client.set_disconnect_callback(self._on_client_disconnect) default_host_id = component.get('DelugeWeb').config['default_daemon'] if default_host_id: return self.connect(default_host_id) return defer.succeed(True)
def enable(self): client.register_event_handler('PluginEnabledEvent', self._json.get_remote_methods) client.register_event_handler('PluginDisabledEvent', self._json.get_remote_methods) if client.is_standalone(): component.get('Web.PluginManager').start() else: client.set_disconnect_callback(self._on_client_disconnect) default_host_id = component.get( 'DelugeWeb').config['default_daemon'] if default_host_id: return self.connect(default_host_id) return defer.succeed(True)
def set_on_disconnect_cb(self, cb): client.set_disconnect_callback(cb)
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: args = ' '.join(args) self.interactive = False # Try to connect to the localhost daemon def on_connect(result): def on_started(result): if not self.interactive: def on_started(result): deferreds = [] # If we have args, lets process them and quit # allow multiple commands split by ";" for arg in args.split(";"): deferreds.append(defer.maybeDeferred(self.do_command, arg.strip())) def on_complete(result): self.do_command("quit") dl = defer.DeferredList(deferreds).addCallback(on_complete) # 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): pass d = client.connect() 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()
class GtkUI(object): def __init__(self, args): self.daemon_bps = (0, 0, 0) # Setup signals try: import gnome.ui import gnome #Suppress: Warning: Attempt to add property GnomeProgram::*** after class was initialised original_filters = warnings.filters[:] warnings.simplefilter("ignore") try: self.gnome_prog = gnome.init("Deluge", deluge.common.get_version()) finally: warnings.filters = original_filters self.gnome_client = gnome.ui.master_client() def on_die(*args): reactor.stop() self.gnome_client.connect("die", on_die) log.debug("GNOME session 'die' handler registered!") except Exception, e: log.warning( "Unable to register a 'die' handler with the GNOME session manager: %s", e) if deluge.common.windows_check(): from win32api import SetConsoleCtrlHandler from win32con import CTRL_CLOSE_EVENT from win32con import CTRL_SHUTDOWN_EVENT def win_handler(ctrl_type): log.debug("ctrl_type: %s", ctrl_type) if ctrl_type in (CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT): reactor.stop() return 1 SetConsoleCtrlHandler(win_handler) if deluge.common.osx_check() and Gdk.WINDOWING == "quartz": import gtkosx_application self.osxapp = gtkosx_application.gtkosx_application_get() def on_die(*args): reactor.stop() self.osxapp.connect("NSApplicationWillTerminate", on_die) # Set process name again to fix gtk issue setproctitle(getproctitle()) # Attempt to register a magnet URI handler with gconf, but do not overwrite # if already set by another program. common.associate_magnet_links(False) # Make sure gtkui.conf has at least the defaults set self.config = deluge.configmanager.ConfigManager( "gtkui.conf", DEFAULT_PREFS) # We need to check on exit if it was started in classic mode to ensure we # shutdown the daemon. self.started_in_classic = self.config["classic_mode"] # Start the IPC Interface before anything else.. Just in case we are # already running. self.queuedtorrents = QueuedTorrents() self.ipcinterface = IPCInterface(args) # Initialize gdk threading Gdk.threads_init() GObject.threads_init() # We make sure that the UI components start once we get a core URI client.set_disconnect_callback(self.__on_disconnect) self.trackericons = TrackerIcons() self.sessionproxy = SessionProxy() # Initialize various components of the gtkui self.mainwindow = MainWindow() self.menubar = MenuBar() self.toolbar = ToolBar() self.torrentview = TorrentView() self.torrentdetails = TorrentDetails() self.sidebar = SideBar() self.filtertreeview = FilterTreeView() self.preferences = Preferences() self.systemtray = SystemTray() self.statusbar = StatusBar() self.addtorrentdialog = AddTorrentDialog() if deluge.common.osx_check() and Gdk.WINDOWING == "quartz": def nsapp_open_file(osxapp, filename): # Will be raised at app launch (python opening main script) if filename.endswith('Deluge-bin'): return True from deluge.ui.gtkui.ipcinterface import process_args process_args([filename]) self.osxapp.connect("NSApplicationOpenFile", nsapp_open_file) from menubar_osx import menubar_osx menubar_osx(self, self.osxapp) self.osxapp.ready() # Initalize the plugins self.plugins = PluginManager() # Show the connection manager self.connectionmanager = ConnectionManager() from twisted.internet.task import LoopingCall rpc_stats = LoopingCall(self.print_rpc_stats) rpc_stats.start(10) reactor.callWhenRunning(self._on_reactor_start) # Start the gtk main loop Gdk.threads_enter() reactor.run() self.shutdown() Gdk.threads_leave()
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()
def __init__(self, args): # Setup gtkbuilder/glade translation setup_translations(setup_gettext=False, setup_pygtk=True) # Setup signals def on_die(*args): log.debug('OS signal "die" caught with args: %s', args) reactor.stop() if windows_check(): from win32api import SetConsoleCtrlHandler SetConsoleCtrlHandler(on_die, True) log.debug('Win32 "die" handler registered') elif osx_check() and WINDOWING == 'quartz': import gtkosx_application self.osxapp = gtkosx_application.gtkosx_application_get() self.osxapp.connect('NSApplicationWillTerminate', on_die) log.debug('OSX quartz "die" handler registered') # Set process name again to fix gtk issue setproctitle(getproctitle()) # Attempt to register a magnet URI handler with gconf, but do not overwrite # if already set by another program. associate_magnet_links(False) # Make sure gtkui.conf has at least the defaults set self.config = ConfigManager('gtkui.conf', DEFAULT_PREFS) # Make sure the gtkui state folder has been created if not os.path.exists(os.path.join(get_config_dir(), 'gtkui_state')): os.makedirs(os.path.join(get_config_dir(), 'gtkui_state')) # Set language if self.config['language'] is not None: set_language(self.config['language']) # Start the IPC Interface before anything else.. Just in case we are # already running. self.queuedtorrents = QueuedTorrents() self.ipcinterface = IPCInterface(args.torrents) # Initialize gdk threading threads_init() # We make sure that the UI components start once we get a core URI client.set_disconnect_callback(self.__on_disconnect) self.trackericons = TrackerIcons() self.sessionproxy = SessionProxy() # Initialize various components of the gtkui self.mainwindow = MainWindow() self.menubar = MenuBar() self.toolbar = ToolBar() self.torrentview = TorrentView() self.torrentdetails = TorrentDetails() self.sidebar = SideBar() self.filtertreeview = FilterTreeView() self.preferences = Preferences() self.systemtray = SystemTray() self.statusbar = StatusBar() self.addtorrentdialog = AddTorrentDialog() if osx_check() and WINDOWING == 'quartz': def nsapp_open_file(osxapp, filename): # Ignore command name which is raised at app launch (python opening main script). if filename == sys.argv[0]: return True process_args([filename]) self.osxapp.connect('NSApplicationOpenFile', nsapp_open_file) from deluge.ui.gtkui.menubar_osx import menubar_osx menubar_osx(self, self.osxapp) self.osxapp.ready() # Initalize the plugins self.plugins = PluginManager() # Show the connection manager self.connectionmanager = ConnectionManager() # Setup RPC stats logging # daemon_bps: time, bytes_sent, bytes_recv self.daemon_bps = (0, 0, 0) self.rpc_stats = LoopingCall(self.log_rpc_stats) self.closing = False # Twisted catches signals to terminate, so have it call a pre_shutdown method. reactor.addSystemEventTrigger('before', 'gtkui_close', self.close) def gtkui_sigint_handler(num, frame): log.debug('SIGINT signal caught, firing event: gtkui_close') reactor.callLater(0, reactor.fireSystemEvent, 'gtkui_close') signal.signal(signal.SIGINT, gtkui_sigint_handler)
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()
class GtkUI(object): def __init__(self, args): self.daemon_bps = (0, 0, 0) # Setup signals try: import gnome.ui import gnome self.gnome_prog = gnome.init("Deluge", deluge.common.get_version()) self.gnome_client = gnome.ui.master_client() def on_die(*args): reactor.stop() self.gnome_client.connect("die", on_die) log.debug("GNOME session 'die' handler registered!") except Exception, e: log.warning( "Unable to register a 'die' handler with the GNOME session manager: %s", e) if deluge.common.windows_check(): from win32api import SetConsoleCtrlHandler from win32con import CTRL_CLOSE_EVENT from win32con import CTRL_SHUTDOWN_EVENT def win_handler(ctrl_type): log.debug("ctrl_type: %s", ctrl_type) if ctrl_type in (CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT): reactor.stop() return 1 SetConsoleCtrlHandler(win_handler) # Attempt to register a magnet URI handler with gconf, but do not overwrite # if already set by another program. common.associate_magnet_links(False) # Make sure gtkui.conf has at least the defaults set self.config = deluge.configmanager.ConfigManager( "gtkui.conf", DEFAULT_PREFS) # We need to check on exit if it was started in classic mode to ensure we # shutdown the daemon. self.started_in_classic = self.config["classic_mode"] # Start the IPC Interface before anything else.. Just in case we are # already running. self.queuedtorrents = QueuedTorrents() self.ipcinterface = IPCInterface(args) # Initialize gdk threading gtk.gdk.threads_init() # We make sure that the UI components start once we get a core URI client.set_disconnect_callback(self.__on_disconnect) self.trackericons = TrackerIcons() self.sessionproxy = SessionProxy() # Initialize various components of the gtkui self.mainwindow = MainWindow() self.menubar = MenuBar() self.toolbar = ToolBar() self.torrentview = TorrentView() self.torrentdetails = TorrentDetails() self.sidebar = SideBar() self.filtertreeview = FilterTreeView() self.preferences = Preferences() self.systemtray = SystemTray() self.statusbar = StatusBar() self.addtorrentdialog = AddTorrentDialog() # Initalize the plugins self.plugins = PluginManager() # Late import because of setting up translations from connectionmanager import ConnectionManager # Show the connection manager self.connectionmanager = ConnectionManager() from twisted.internet.task import LoopingCall rpc_stats = LoopingCall(self.print_rpc_stats) rpc_stats.start(10) reactor.callWhenRunning(self._on_reactor_start) # Initialize gdk threading gtk.gdk.threads_enter() reactor.run() self.shutdown() gtk.gdk.threads_leave()