def _download_icon_and_show_when_ready(self, url, pkgname, icon_file_name):
        LOG.debug("did not find the icon locally, must download %s" %
                  icon_file_name)

        if url is not None:
            icon_file_path = os.path.join(SOFTWARE_CENTER_ICON_CACHE_DIR,
                                          icon_file_name)
            image_downloader = SimpleFileDownloader()
            image_downloader.connect('file-download-complete',
                                     self._on_image_download_complete, pkgname)
            image_downloader.download_file(url, icon_file_path)
Exemplo n.º 2
0
    def _download_icon_and_show_when_ready(self, url, pkgname, icon_file_name):
        LOG.debug("did not find the icon locally, must download %s" %
            icon_file_name)

        if url is not None:
            icon_file_path = os.path.join(SOFTWARE_CENTER_ICON_CACHE_DIR,
                icon_file_name)
            image_downloader = SimpleFileDownloader()
            image_downloader.connect('file-download-complete',
                                     self._on_image_download_complete, pkgname)
            image_downloader.download_file(url, icon_file_path)
Exemplo n.º 3
0
class TestImageDownloader(unittest.TestCase):

    DOWNLOAD_FILENAME = "test_image_download"

    def setUp(self):
        self.downloader = SimpleFileDownloader()
        self.downloader.connect("file-url-reachable",
                                self._cb_image_url_reachable)
        self.downloader.connect("file-download-complete",
                                self._cb_image_download_complete)
        self.downloader.connect("error",
                                self._cb_image_download_error)
        self._image_is_reachable = None
        self._image_downloaded_filename = None
        self._error = False
        if os.path.exists(self.DOWNLOAD_FILENAME):
            os.unlink(self.DOWNLOAD_FILENAME)

    def _cb_image_url_reachable(self, downloader, is_reachable):
        self._image_is_reachable = is_reachable

    def _cb_image_download_complete(self, downloader, filename):
        self._image_downloaded_filename = filename

    def _cb_image_download_error(self, downloader, gerror, exc):
        self._error = True

    def test_download_unreachable(self):
        self.downloader.download_file("http://www.ubuntu.com/really-not-there",
                                      self.DOWNLOAD_FILENAME)
        main_loop = GObject.main_context_default()
        while self._image_is_reachable is None:
            while main_loop.pending():
                main_loop.iteration()
            time.sleep(0.1)
        self.assertNotEqual(self._image_is_reachable, None)
        self.assertFalse(self._image_is_reachable)
        self.assertTrue(not os.path.exists(self.DOWNLOAD_FILENAME))
 
    def test_download_reachable(self):
        self.downloader.download_file("http://www.ubuntu.com",
                                      self.DOWNLOAD_FILENAME)
        main_loop = GObject.main_context_default()
        while (self._image_downloaded_filename is None and
               not self._error):
            while main_loop.pending():
                main_loop.iteration()
            time.sleep(0.1)
        self.assertNotEqual(self._image_is_reachable, None)
        self.assertTrue(self._image_is_reachable)
        self.assertTrue(os.path.exists(self.DOWNLOAD_FILENAME))
Exemplo n.º 4
0
class TestImageDownloader(unittest.TestCase):

    DOWNLOAD_FILENAME = "test_image_download"

    def setUp(self):
        self.downloader = SimpleFileDownloader()
        self.downloader.connect("file-url-reachable",
                                self._cb_image_url_reachable)
        self.downloader.connect("file-download-complete",
                                self._cb_image_download_complete)
        self.downloader.connect("error", self._cb_image_download_error)
        self._image_is_reachable = None
        self._image_downloaded_filename = None
        self._error = False
        if os.path.exists(self.DOWNLOAD_FILENAME):
            os.unlink(self.DOWNLOAD_FILENAME)

    def _cb_image_url_reachable(self, downloader, is_reachable):
        self._image_is_reachable = is_reachable

    def _cb_image_download_complete(self, downloader, filename):
        self._image_downloaded_filename = filename

    def _cb_image_download_error(self, downloader, gerror, exc):
        self._error = True

    def test_download_unreachable(self):
        self.downloader.download_file("http://www.ubuntu.com/really-not-there",
                                      self.DOWNLOAD_FILENAME)
        main_loop = GObject.main_context_default()
        while self._image_is_reachable is None:
            while main_loop.pending():
                main_loop.iteration()
            time.sleep(0.1)
        self.assertNotEqual(self._image_is_reachable, None)
        self.assertFalse(self._image_is_reachable)
        self.assertTrue(not os.path.exists(self.DOWNLOAD_FILENAME))

    def test_download_reachable(self):
        self.downloader.download_file("http://www.ubuntu.com",
                                      self.DOWNLOAD_FILENAME)
        main_loop = GObject.main_context_default()
        while (self._image_downloaded_filename is None and not self._error):
            while main_loop.pending():
                main_loop.iteration()
            time.sleep(0.1)
        self.assertNotEqual(self._image_is_reachable, None)
        self.assertTrue(self._image_is_reachable)
        self.assertTrue(os.path.exists(self.DOWNLOAD_FILENAME))
Exemplo n.º 5
0
    def _download_icon_and_show_when_ready(self, url, pkgname, icon_file_name):
        LOG.debug("did not find the icon locally, must download %s" % icon_file_name)

        def on_image_download_complete(downloader, image_file_path, pkgname):
            LOG.debug("download for '%s' complete" % image_file_path)
            pb = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_file_path, self.icon_size, self.icon_size)
            # replace the icon in the icon_cache now that we've got the real
            # one
            icon_file = split_icon_ext(os.path.basename(image_file_path))
            self.icon_cache[icon_file] = pb
            self.emit("needs-refresh", pkgname)

        if url is not None:
            icon_file_path = os.path.join(SOFTWARE_CENTER_ICON_CACHE_DIR, icon_file_name)
            image_downloader = SimpleFileDownloader()
            image_downloader.connect("file-download-complete", on_image_download_complete, pkgname)
            image_downloader.download_file(url, icon_file_path)
Exemplo n.º 6
0
    def _download_icon_and_show_when_ready(self, cache, pkgname, icon_file_name):
        LOG.debug("did not find the icon locally, must download %s" % icon_file_name)

        def on_image_download_complete(downloader, image_file_path):
            pb = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_file_path,
                                                      self.icon_size,
                                                      self.icon_size)
            # replace the icon in the icon_cache now that we've got the real one
            icon_file = os.path.splitext(os.path.basename(image_file_path))[0]
            self.icon_cache[icon_file] = pb
        
        url = get_distro().get_downloadable_icon_url(cache, pkgname, icon_file_name)
        if url is not None:
            icon_file_path = os.path.join(SOFTWARE_CENTER_ICON_CACHE_DIR, icon_file_name)
            image_downloader = SimpleFileDownloader()
            image_downloader.connect('file-download-complete', on_image_download_complete)
            image_downloader.download_file(url, icon_file_path)
Exemplo n.º 7
0
    def __init__(self, id_, url, cancellable, gallery):
        Gtk.Button.__init__(self)
        self.id_ = id_

        def download_complete_cb(loader, path):
            width, height = ThumbnailGallery.THUMBNAIL_SIZE_CONTRAINTS
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
                path,
                width,
                height,  # width, height constraints
                True)  # respect image proportionality
            im = Gtk.Image.new_from_pixbuf(pixbuf)
            self.add(im)
            self.show_all()

        loader = SimpleFileDownloader()
        loader.connect("file-download-complete", download_complete_cb)
        loader.download_file(url, use_cache=ScreenshotGallery.USE_CACHING)

        self.connect("draw", self.on_draw)
Exemplo n.º 8
0
    def __init__(self, id_, url, cancellable, gallery):
        Gtk.Button.__init__(self)
        self.id_ = id_

        def download_complete_cb(loader, path):
            width, height = ThumbnailGallery.THUMBNAIL_SIZE_CONTRAINTS
            pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
                        path,
                        width, height,  # width, height constraints
                        True)  # respect image proportionality
            im = Gtk.Image.new_from_pixbuf(pixbuf)
            self.add(im)
            self.show_all()

        loader = SimpleFileDownloader()
        loader.connect("file-download-complete", download_complete_cb)
        loader.download_file(
            url, use_cache=ScreenshotGallery.USE_CACHING)

        self.connect("draw", self.on_draw)
Exemplo n.º 9
0
    def _download_icon_and_show_when_ready(self, url, pkgname, icon_file_name):
        LOG.debug("did not find the icon locally, must download %s" %
            icon_file_name)

        def on_image_download_complete(downloader, image_file_path, pkgname):
            LOG.debug("download for '%s' complete" % image_file_path)
            pb = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_file_path,
                                                        self.icon_size,
                                                        self.icon_size)
            # replace the icon in the icon_cache now that we've got the real
            # one
            icon_file = split_icon_ext(os.path.basename(image_file_path))
            self.icon_cache[icon_file] = pb
            self.emit("needs-refresh", pkgname)

        if url is not None:
            icon_file_path = os.path.join(SOFTWARE_CENTER_ICON_CACHE_DIR,
                icon_file_name)
            image_downloader = SimpleFileDownloader()
            image_downloader.connect('file-download-complete',
                on_image_download_complete, pkgname)
            image_downloader.download_file(url, icon_file_path)
Exemplo n.º 10
0
class _HtmlRenderer(Gtk.OffscreenWindow):

    __gsignals__ = {
        "render-finished": (GObject.SignalFlags.RUN_LAST,
                            None,
                            (),
                           )
        }

    def __init__(self):
        Gtk.OffscreenWindow.__init__(self)
        self.view = WebKit.WebView()
        settings = self.view.get_settings()
        settings.set_property("enable-java-applet", False)
        settings.set_property("enable-plugins", False)
        settings.set_property("enable-scripts", False)
        self.view.set_size_request(-1, ExhibitBanner.MAX_HEIGHT)
        self.add(self.view)
        self.show_all()
        self.loader = SimpleFileDownloader()
        self.loader.connect("file-download-complete",
                            self.on_download_complete)
        self.loader.connect("error",
                            self.on_download_error)
        self.exhibit = None
        self.view.connect("notify::load-status", self._on_load_status)

    def _on_load_status(self, view, prop):
        if view.get_property("load-status") == WebKit.LoadStatus.FINISHED:
            # this needs to run with a timeout because otherwise the
            # status is emited before the offscreen image is finihsed
            GObject.timeout_add(100, lambda: self.emit("render-finished"))

    def on_download_error(self, loader, exception, error):
        LOG.warn("download failed: '%s', '%s'" % (exception, error))

    def on_download_complete(self, loader, path):
        image_name = os.path.basename(path)
        cache_dir = os.path.dirname(path)
        if hasattr(self.exhibit, "html") and self.exhibit.html:
            html = self.exhibit.html
        else:
            html = EXHIBIT_HTML % {
                'banner_url': self.exhibit.banner_url,
                'title': self.exhibit.title_translated,
                'subtitle': "",
            }
        # replace the server side path with the local image name, this
        # assumes that the image always comes from the same server as
        # the html
        scheme, netloc, server_path, para, query, frag = urlparse(
            self.exhibit.banner_url)
        html = html.replace(server_path, image_name)
        self.view.load_string(html, "text/html", "UTF-8",
                              "file:%s/" % cache_dir)

    def set_exhibit(self, exhibit):
        self.exhibit = exhibit
        self.loader.download_file(exhibit.banner_url,
                                  use_cache=True,
                                  simple_quoting_for_webkit=True)
class _HtmlRenderer(Gtk.OffscreenWindow):

    __gsignals__ = {
        "render-finished": (
            GObject.SignalFlags.RUN_LAST,
            None,
            (),
        )
    }

    def __init__(self):
        Gtk.OffscreenWindow.__init__(self)
        self.view = WebKit.WebView()
        settings = self.view.get_settings()
        settings.set_property("enable-java-applet", False)
        settings.set_property("enable-plugins", False)
        settings.set_property("enable-scripts", False)
        self.view.set_size_request(-1, ExhibitBanner.MAX_HEIGHT)
        self.add(self.view)
        self.show_all()
        self.loader = SimpleFileDownloader()
        self.loader.connect("file-download-complete",
                            self.on_download_complete)
        self.loader.connect("error", self.on_download_error)
        self.exhibit = None
        self.view.connect("notify::load-status", self._on_load_status)

    def _on_load_status(self, view, prop):
        if view.get_property("load-status") == WebKit.LoadStatus.FINISHED:
            # this needs to run with a timeout because otherwise the
            # status is emited before the offscreen image is finihsed
            GObject.timeout_add(100, lambda: self.emit("render-finished"))

    def on_download_error(self, loader, exception, error):
        LOG.warn("download failed: '%s', '%s'" % (exception, error))

    def on_download_complete(self, loader, path):
        image_name = os.path.basename(path)
        cache_dir = os.path.dirname(path)
        if hasattr(self.exhibit, "html") and self.exhibit.html:
            html = self.exhibit.html
        else:
            html = EXHIBIT_HTML % {
                'banner_url': self.exhibit.banner_url,
                'title': self.exhibit.title_translated,
                'subtitle': "",
            }
        # replace the server side path with the local image name, this
        # assumes that the image always comes from the same server as
        # the html
        scheme, netloc, server_path, para, query, frag = urlparse(
            self.exhibit.banner_url)
        html = html.replace(server_path, image_name)
        self.view.load_string(html, "text/html", "UTF-8",
                              "file:%s/" % cache_dir)

    def set_exhibit(self, exhibit):
        self.exhibit = exhibit
        self.loader.download_file(exhibit.banner_url,
                                  use_cache=True,
                                  simple_quoting_for_webkit=True)
Exemplo n.º 12
0
class _HtmlRenderer(Gtk.OffscreenWindow):

    __gsignals__ = {
        "render-finished": (GObject.SignalFlags.RUN_LAST,
                            None,
                            (),
                            )
    }

    def __init__(self):
        Gtk.OffscreenWindow.__init__(self)
        self.view = WebKit.WebView()
        settings = self.view.get_settings()
        settings.set_property("enable-java-applet", False)
        settings.set_property("enable-plugins", False)
        settings.set_property("enable-scripts", False)
        self.view.set_size_request(-1, ExhibitBanner.MAX_HEIGHT)
        self.add(self.view)
        self.show_all()
        self.loader = SimpleFileDownloader()
        self.loader.connect("file-download-complete",
                            self._on_one_download_complete)
        self.loader.connect("error",
                            self._on_download_error)
        self.exhibit = None
        self._downloaded_banner_images = []
        self.view.connect(
            "notify::load-status", self._on_internal_renderer_load_status)

    def set_exhibit(self, exhibit):
        LOG.debug("set_exhibit: '%s'" % exhibit)
        self._downloaded_banner_images = []
        self.exhibit = exhibit
        self._download_next_banner_image()

    def _on_download_error(self, loader, exception, error):
        LOG.warn("download failed: '%s', '%s'" % (exception, error))

    def _on_one_download_complete(self, loader, path):
        LOG.debug("downloading of '%s' finished" % path)
        self._downloaded_banner_images.append(path)
        if len(self._downloaded_banner_images) < len(self.exhibit.banner_urls):
            self._download_next_banner_image()
        self._on_all_banner_images_downloaded()

    def _on_all_banner_images_downloaded(self):
        LOG.debug("downloading of all banner images finished")
        html = self.exhibit.html
        cache_dir = os.path.join(
            softwarecenter.paths.SOFTWARE_CENTER_CACHE_DIR,
            "download-cache")
        for url, local_file in zip(self.exhibit.banner_urls,
                              self._downloaded_banner_images):
            # no need to mangle local urls
            if url.startswith("file"):
                continue
            scheme, netloc, server_path, para, query, frag = urlparse(url)
            image_name = os.path.basename(local_file)
            # replace the server side path with the local image name, this
            # assumes that the image always comes from the same server as
            # the html
            html = html.replace(server_path, image_name)
        self.exhibit.html = html
        LOG.debug("mangled html: '%s'" % html)
        self.view.load_string(html, "text/html", "UTF-8",
                              "file:%s/" % cache_dir)

    def _download_next_banner_image(self):
        LOG.debug("_download_next_banner_image")
        self.loader.download_file(
            self.exhibit.banner_urls[len(self._downloaded_banner_images)],
            use_cache=True,
            simple_quoting_for_webkit=True)

    def _on_internal_renderer_load_status(self, view, prop):
        """Called when the rendering of the html banner is done"""
        if view.get_property("load-status") == WebKit.LoadStatus.FINISHED:
            # this needs to run with a timeout because otherwise the
            # status is emitted before the offscreen image is finished
            GLib.timeout_add(100, lambda: self.emit("render-finished"))