class TrackerIconsTestCase(BaseTestCase): if windows_check(): skip = 'cannot use os.path.samefile to compair on windows(unix only)' def set_up(self): # Disable resizing with Pillow for consistency. self.patch(deluge.ui.tracker_icons, 'Image', None) self.icons = TrackerIcons() def tear_down(self): return component.shutdown() def test_get_deluge_png(self): # Deluge has a png favicon link icon = TrackerIcon(common.get_test_data_file('deluge.png')) d = self.icons.fetch('deluge-torrent.org') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_google_ico(self): # Google doesn't have any icon links # So instead we'll grab its favicon.ico icon = TrackerIcon(common.get_test_data_file('google.ico')) d = self.icons.fetch('www.google.com') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_google_ico_with_redirect(self): # google.com redirects to www.google.com icon = TrackerIcon(common.get_test_data_file('google.ico')) d = self.icons.fetch('google.com') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_seo_ico_with_sni(self): # seo using certificates with SNI support only raise SkipTest('Site certificate expired') icon = TrackerIcon(common.get_test_data_file('seo.ico')) d = self.icons.fetch('www.seo.com') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_empty_string_tracker(self): d = self.icons.fetch('') d.addCallback(self.assertIdentical, None) return d
class Tracker(resource.Resource): def __init__(self): resource.Resource.__init__(self) try: self.tracker_icons = component.get("TrackerIcons") except KeyError: self.tracker_icons = TrackerIcons() def getChild(self, path, request): request.tracker_name = path return self def on_got_icon(self, icon, request): headers = {} if icon: request.setHeader("cache-control", "public, must-revalidate, max-age=86400") request.setHeader("content-type", icon.get_mimetype()) request.setResponseCode(http.OK) request.write(icon.get_data()) request.finish() else: request.setResponseCode(http.NOT_FOUND) request.finish() def render(self, request): d = self.tracker_icons.get(request.tracker_name) d.addCallback(self.on_got_icon, request) return server.NOT_DONE_YET
class Tracker(resource.Resource): def __init__(self): resource.Resource.__init__(self) try: self.tracker_icons = component.get('TrackerIcons') except KeyError: self.tracker_icons = TrackerIcons() def getChild(self, path, request): # NOQA: N802 request.tracker_name = path return self def on_got_icon(self, icon, request): if icon: request.setHeader(b'cache-control', b'public, must-revalidate, max-age=86400') request.setHeader(b'content-type', icon.get_mimetype().encode('utf8')) request.setResponseCode(http.OK) request.write(icon.get_data()) request.finish() else: request.setResponseCode(http.NOT_FOUND) request.finish() def render(self, request): d = self.tracker_icons.fetch(request.tracker_name) d.addCallback(self.on_got_icon, request) return server.NOT_DONE_YET
class Tracker(resource.Resource): def __init__(self): resource.Resource.__init__(self) try: self.tracker_icons = component.get('TrackerIcons') except KeyError: self.tracker_icons = TrackerIcons() def getChild(self, path, request): # NOQA: N802 request.tracker_name = path return self def on_got_icon(self, icon, request): if icon: request.setHeader( b'cache-control', b'public, must-revalidate, max-age=86400' ) request.setHeader(b'content-type', icon.get_mimetype().encode('utf8')) request.setResponseCode(http.OK) request.write(icon.get_data()) request.finish() else: request.setResponseCode(http.NOT_FOUND) request.finish() def render(self, request): d = self.tracker_icons.fetch(request.tracker_name.decode()) d.addCallback(self.on_got_icon, request) return server.NOT_DONE_YET
class TrackerIconsTestCase(BaseTestCase): def set_up(self): self.icons = TrackerIcons() def tear_down(self): return component.shutdown() def test_get_deluge_png(self): # Deluge has a png favicon link icon = TrackerIcon(common.get_test_data_file('deluge.png')) d = self.icons.fetch('deluge-torrent.org') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_google_ico(self): # Google doesn't have any icon links # So instead we'll grab its favicon.ico icon = TrackerIcon(common.get_test_data_file('google.ico')) d = self.icons.fetch('www.google.com') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_google_ico_with_redirect(self): # google.com redirects to www.google.com icon = TrackerIcon(common.get_test_data_file('google.ico')) d = self.icons.fetch('google.com') d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEqual, icon) return d def test_get_empty_string_tracker(self): d = self.icons.fetch('') d.addCallback(self.assertIdentical, None) return d
def __init__(self): resource.Resource.__init__(self) try: self.tracker_icons = component.get("TrackerIcons") except KeyError: self.tracker_icons = TrackerIcons()
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()
import os from twisted.trial import unittest from deluge.ui.tracker_icons import TrackerIcons, TrackerIcon import common common.set_tmp_config_dir() icons = TrackerIcons() dirname = os.path.dirname(__file__) class TrackerIconsTestCase(unittest.TestCase): def test_get_deluge_png(self): # Deluge has a png favicon link icon = TrackerIcon(os.path.join(dirname, "deluge.png")) d = icons.get("deluge-torrent.org") d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEquals, icon) return d def test_get_google_ico(self): # Google doesn't have any icon links # So instead we'll grab its favicon.ico icon = TrackerIcon(os.path.join(dirname, "google.ico")) d = icons.get("www.google.com") d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEquals, icon) return d
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)
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()
def set_up(self): self.icons = TrackerIcons()
def set_up(self): # Disable resizing with Pillow for consistency. self.patch(deluge.ui.tracker_icons, 'Image', None) self.icons = TrackerIcons()