Exemple #1
0
 def start(self):
     """Start downloading a file."""
     self.downloader = Downloader(self.url, self.dest)
     timer_id = GLib.timeout_add(100, self.progress)
     self.cancel_button.set_sensitive(True)
     self.downloader.start()
     return timer_id
Exemple #2
0
def get_runtimes():
    global CURRENT_UPDATES
    global STATUS_UPDATER
    if CURRENT_UPDATES is None:
        CURRENT_UPDATES = 0
    request = http.Request(RUNTIME_URL)
    response = request.get()
    cancellables = []
    runtimes = response.json or []
    for runtime in runtimes:
        name = runtime['name']
        if '64' in name and not system.is_64bit:
            continue
        created_at = runtime['created_at']
        created_at = time.strptime(created_at[:created_at.find('.')],
                                   "%Y-%m-%dT%H:%M:%S")
        if get_created_at(name) < created_at:
            if STATUS_UPDATER:
                STATUS_UPDATER("Updating Runtime")
            logger.debug('Updating runtime %s', name)
            url = runtime['url']
            archive_path = os.path.join(RUNTIME_DIR, os.path.basename(url))
            CURRENT_UPDATES += 1
            downloader = Downloader(url, archive_path, overwrite=True)
            cancellables.append(downloader.cancel)
            downloader.start()
            GLib.timeout_add(100, check_download_progress, downloader)
        else:
            logger.debug("Runtime %s up to date", name)
    return cancellables
Exemple #3
0
 def install_runner(self, row):
     url = row[2]
     logger.debug("Downloading %s", url)
     dest_path = self.get_dest_path(row)
     downloader = Downloader(url, dest_path, overwrite=True)
     GLib.timeout_add(100, self.get_progress, downloader, row)
     self.installing[row[self.COL_VER]] = downloader
     downloader.start()
 def install_runner(self, path):
     row = self.runner_store[path]
     url = row[2]
     dest_path = self.get_dest_path(path)
     downloader = Downloader(url, dest_path)
     self.download_timer = GLib.timeout_add(100, self.get_progress,
                                            downloader, path)
     downloader.start()
Exemple #5
0
 def install_runner(self, row):
     url = row[2]
     logger.debug("Downloading %s", url)
     dest_path = self.get_dest_path(row)
     downloader = Downloader(url, dest_path, overwrite=True)
     GLib.timeout_add(100, self.get_progress, downloader, row)
     self.installing[row[self.COL_VER]] = downloader
     downloader.start()
Exemple #6
0
 def start(self):
     """Start downloading a file."""
     try:
         self.downloader = Downloader(self.url, self.dest)
     except RuntimeError as ex:
         from lutris.gui.dialogs import ErrorDialog
         ErrorDialog(ex.message)
         self.emit('cancelrequested', {})
         return
     timer_id = GLib.timeout_add(100, self.progress)
     self.cancel_button.set_sensitive(True)
     self.downloader.start()
     return timer_id
Exemple #7
0
 def start(self):
     """Start downloading a file."""
     self.downloader = Downloader(self.url, self.dest)
     timer_id = GLib.timeout_add(100, self.progress)
     self.cancel_button.set_sensitive(True)
     self.downloader.start()
     return timer_id
Exemple #8
0
 def download_runtime(self, runtime):
     name = runtime['name']
     created_at = runtime['created_at']
     created_at = time.strptime(created_at[:created_at.find('.')],
                                "%Y-%m-%dT%H:%M:%S")
     if self.get_created_at(name) >= created_at:
         logger.debug("Runtime %s is up to date", name)
         return
     if self.status_updater:
         self.status_updater("Updating Runtime")
     logger.debug('Updating runtime %s', name)
     url = runtime['url']
     archive_path = os.path.join(RUNTIME_DIR, os.path.basename(url))
     self.current_updates += 1
     downloader = Downloader(url, archive_path, overwrite=True)
     self.cancellables.append(downloader.cancel)
     downloader.start()
     GLib.timeout_add(100, self.check_download_progress, downloader)
Exemple #9
0
 def download_runtime(self, runtime):
     name = runtime['name']
     created_at = runtime['created_at']
     created_at = time.strptime(created_at[:created_at.find('.')],
                                "%Y-%m-%dT%H:%M:%S")
     if self.get_created_at(name) >= created_at:
         logger.debug("Runtime %s is up to date", name)
         return
     if self.status_updater:
         self.status_updater("Updating Runtime")
     logger.debug('Updating runtime %s', name)
     url = runtime['url']
     archive_path = os.path.join(RUNTIME_DIR, os.path.basename(url))
     self.current_updates += 1
     downloader = Downloader(url, archive_path, overwrite=True)
     self.cancellables.append(downloader.cancel)
     downloader.start()
     GLib.timeout_add(100, self.check_download_progress, downloader)
Exemple #10
0
    def start(self):
        """Start downloading a file."""
        if not self.downloader:
            try:
                self.downloader = Downloader(self.url,
                                             self.dest,
                                             overwrite=True)
            except RuntimeError as ex:
                from lutris.gui.dialogs import ErrorDialog
                ErrorDialog(ex.args[0])
                self.emit('cancel', {})
                return

        timer_id = GLib.timeout_add(100, self._progress)
        self.cancel_button.set_sensitive(True)
        if not self.downloader.state == self.downloader.DOWNLOADING:
            self.downloader.start()
        return timer_id
Exemple #11
0
 def start(self):
     """Start downloading a file."""
     try:
         self.downloader = Downloader(self.url, self.dest)
     except RuntimeError as ex:
         from lutris.gui.dialogs import ErrorDialog
         ErrorDialog(ex.message)
         self.emit('cancelrequested', {})
         return
     timer_id = GLib.timeout_add(100, self.progress)
     self.cancel_button.set_sensitive(True)
     self.downloader.start()
     return timer_id
Exemple #12
0
    def start(self):
        """Start downloading a file."""
        if not self.downloader:
            try:
                self.downloader = Downloader(self.url, self.dest,
                                             overwrite=True)
            except RuntimeError as ex:
                from lutris.gui.dialogs import ErrorDialog
                ErrorDialog(ex.args[0])
                self.emit('cancel', {})
                return

        timer_id = GLib.timeout_add(100, self._progress)
        self.cancel_button.set_sensitive(True)
        if not self.downloader.state == self.downloader.DOWNLOADING:
            self.downloader.start()
        return timer_id
Exemple #13
0
class DownloadProgressBox(Gtk.HBox):
    """Progress bar used to monitor a file download."""
    __gsignals__ = {
        'complete':
        (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT, )),
        'cancelrequested':
        (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT, ))
    }

    def __init__(self, params, cancelable=True):
        super(DownloadProgressBox, self).__init__()
        self.downloader = None

        self.progress_box = Gtk.VBox()

        self.progressbar = Gtk.ProgressBar()
        self.progress_box.pack_start(self.progressbar, True, True, 10)
        self.progress_label = Gtk.Label()
        self.progress_box.pack_start(self.progress_label, True, True, 10)
        self.pack_start(self.progress_box, True, True, 10)
        self.progress_box.show_all()

        self.cancel_button = Gtk.Button(stock=Gtk.STOCK_CANCEL)
        if cancelable:
            self.cancel_button.show()
            self.cancel_button.set_sensitive(False)
            self.cancel_button.connect('clicked', self.cancel)
            self.pack_end(self.cancel_button, False, False, 10)

        self.url = params['url']
        self.dest = params['dest']

    def start(self):
        """Start downloading a file."""
        self.downloader = Downloader(self.url, self.dest)
        timer_id = GLib.timeout_add(100, self.progress)
        self.cancel_button.set_sensitive(True)
        self.downloader.start()
        return timer_id

    def progress(self):
        """Show download progress."""
        progress = min(self.downloader.progress, 1)
        if self.downloader.cancelled:
            self.progressbar.set_fraction(0)
            self.progress_label.set_text("Download canceled")
            self.emit('cancelrequested', {})
            return False
        self.progressbar.set_fraction(progress)
        megabytes = 1024 * 1024
        progress_text = (
            "%0.2fMb out of %0.2fMb (%0.2fMb/s), %d seconds remaining" %
            (float(self.downloader.downloaded_bytes) / megabytes,
             float(self.downloader.total_bytes) / megabytes,
             float(self.downloader.speed) / megabytes,
             self.downloader.time_remaining))
        self.progress_label.set_text(progress_text)
        self.progressbar.set_fraction(progress)
        if progress >= 1.0:
            self.cancel_button.set_sensitive(False)
            self.emit('complete', {})
            return False
        return True

    def cancel(self, _widget):
        """Cancel the current download."""
        if self.downloader:
            self.downloader.cancel()
            self.cancel_button.set_sensitive(False)
Exemple #14
0
class DownloadProgressBox(Gtk.HBox):
    """Progress bar used to monitor a file download."""
    __gsignals__ = {
        'complete': (GObject.SignalFlags.RUN_LAST, None,
                     (GObject.TYPE_PYOBJECT,)),
        'cancelrequested': (GObject.SignalFlags.RUN_LAST, None,
                            (GObject.TYPE_PYOBJECT,))
    }

    def __init__(self, params, cancelable=True):
        super(DownloadProgressBox, self).__init__()
        self.downloader = None

        self.progress_box = Gtk.VBox()

        self.progressbar = Gtk.ProgressBar()
        self.progress_box.pack_start(self.progressbar, True, True, 10)
        self.progress_label = Gtk.Label()
        self.progress_box.pack_start(self.progress_label, True, True, 10)
        self.pack_start(self.progress_box, True, True, 10)
        self.progress_box.show_all()

        self.cancel_button = Gtk.Button(stock=Gtk.STOCK_CANCEL)
        if cancelable:
            self.cancel_button.show()
            self.cancel_button.set_sensitive(False)
            self.cancel_button.connect('clicked', self.cancel)
            self.pack_end(self.cancel_button, False, False, 10)

        self.url = params['url']
        self.dest = params['dest']

    def start(self):
        """Start downloading a file."""
        self.downloader = Downloader(self.url, self.dest)
        timer_id = GLib.timeout_add(100, self.progress)
        self.cancel_button.set_sensitive(True)
        self.downloader.start()
        return timer_id

    def progress(self):
        """Show download progress."""
        progress = min(self.downloader.progress, 1)
        if self.downloader.cancelled:
            self.progressbar.set_fraction(0)
            self.progress_label.set_text("Download canceled")
            self.emit('cancelrequested', {})
            return False
        self.progressbar.set_fraction(progress)
        megabytes = 1024 * 1024
        progress_text = (
            "%0.2fMb out of %0.2fMb (%0.2fMb/s), %d seconds remaining" % (
                float(self.downloader.downloaded_bytes) / megabytes,
                float(self.downloader.total_bytes) / megabytes,
                float(self.downloader.speed) / megabytes,
                self.downloader.time_remaining
            )
        )
        self.progress_label.set_text(progress_text)
        self.progressbar.set_fraction(progress)
        if progress >= 1.0:
            self.cancel_button.set_sensitive(False)
            self.emit('complete', {})
            return False
        return True

    def cancel(self, _widget):
        """Cancel the current download."""
        if self.downloader:
            self.downloader.cancel()
            self.cancel_button.set_sensitive(False)
Exemple #15
0
class DownloadProgressBox(Gtk.VBox):
    """Progress bar used to monitor a file download."""
    __gsignals__ = {
        'complete': (GObject.SignalFlags.RUN_LAST, None,
                     (GObject.TYPE_PYOBJECT,)),
        'cancelrequested': (GObject.SignalFlags.RUN_LAST, None,
                            (GObject.TYPE_PYOBJECT,))
    }

    def __init__(self, params, cancelable=True):
        super(DownloadProgressBox, self).__init__()

        self.downloader = None
        self.url = params['url']
        self.dest = params['dest']
        title = params.get('title', "Downloading {}".format(self.url))

        self.main_label = Gtk.Label(title)
        self.main_label.set_alignment(0, 0)
        self.main_label.set_property('wrap', True)
        self.main_label.set_margin_bottom(10)
        self.main_label.set_selectable(True)
        self.pack_start(self.main_label, True, True, 0)

        progress_box = Gtk.Box()

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_margin_bottom(10)
        self.progressbar.set_margin_right(10)
        progress_box.pack_start(self.progressbar, True, True, 0)

        self.cancel_button = Gtk.Button.new_with_mnemonic('_Cancel')
        self.cancel_button.connect('clicked', self.cancel)
        if not cancelable:
            self.cancel_button.set_sensitive(False)
        progress_box.pack_end(self.cancel_button, False, False, 0)

        self.pack_start(progress_box, False, False, 0)

        self.progress_label = Gtk.Label()
        self.progress_label.set_alignment(0, 0)
        self.pack_start(self.progress_label, True, True, 0)

        self.show_all()

    def start(self):
        """Start downloading a file."""
        try:
            self.downloader = Downloader(self.url, self.dest, overwrite=True)
        except RuntimeError as ex:
            from lutris.gui.dialogs import ErrorDialog
            ErrorDialog(ex.message)
            self.emit('cancelrequested', {})
            return
        timer_id = GLib.timeout_add(100, self.progress)
        self.cancel_button.set_sensitive(True)
        self.downloader.start()
        return timer_id

    def progress(self):
        """Show download progress."""
        progress = min(self.downloader.check_progress(), 1)
        if self.downloader.cancelled:
            self.progressbar.set_fraction(0)
            self.set_text("Download cancelled")
            self.emit('cancelrequested', {})
            return False
        self.progressbar.set_fraction(progress)
        megabytes = 1024 * 1024
        progress_text = (
            "%0.2f / %0.2fMB (%0.2fMB/s), %s remaining" % (
                float(self.downloader.downloaded_size) / megabytes,
                float(self.downloader.full_size) / megabytes,
                float(self.downloader.average_speed) / megabytes,
                self.downloader.time_left
            )
        )
        self.set_text(progress_text)
        self.progressbar.set_fraction(progress)
        if progress >= 1.0:
            self.cancel_button.set_sensitive(False)
            self.emit('complete', {})
            return False
        return True

    def cancel(self, _widget):
        """Cancel the current download."""
        if self.downloader:
            self.downloader.cancel()
            self.cancel_button.set_sensitive(False)

    def set_text(self, text):
        markup = u"<span size='10000'>{}</span>".format(text)
        self.progress_label.set_markup(markup)
Exemple #16
0
class DownloadProgressBox(Gtk.VBox):
    """Progress bar used to monitor a file download."""
    __gsignals__ = {
        'complete':
        (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT, )),
        'cancel':
        (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT, )),
        'error':
        (GObject.SignalFlags.RUN_LAST, None, (GObject.TYPE_PYOBJECT, )),
    }

    def __init__(self, params, cancelable=True, downloader=None):
        super(DownloadProgressBox, self).__init__()

        self.downloader = downloader
        self.url = params.get('url')
        self.dest = params.get('dest')
        title = params.get('title', "Downloading {}".format(self.url))

        self.main_label = Gtk.Label(title)
        self.main_label.set_alignment(0, 0)
        self.main_label.set_property('wrap', True)
        self.main_label.set_margin_bottom(10)
        self.main_label.set_max_width_chars(70)
        self.main_label.set_selectable(True)
        self.main_label.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
        self.pack_start(self.main_label, True, True, 0)

        progress_box = Gtk.Box()

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_margin_top(5)
        self.progressbar.set_margin_bottom(5)
        self.progressbar.set_margin_right(10)
        progress_box.pack_start(self.progressbar, True, True, 0)

        self.cancel_button = Gtk.Button.new_with_mnemonic('_Cancel')
        self.cancel_button.connect('clicked', self.cancel)
        if not cancelable:
            self.cancel_button.set_sensitive(False)
        progress_box.pack_end(self.cancel_button, False, False, 0)

        self.pack_start(progress_box, False, False, 0)

        self.progress_label = Gtk.Label()
        self.progress_label.set_alignment(0, 0)
        self.pack_start(self.progress_label, True, True, 0)

        self.show_all()

    def start(self):
        """Start downloading a file."""
        if not self.downloader:
            try:
                self.downloader = Downloader(self.url,
                                             self.dest,
                                             overwrite=True)
            except RuntimeError as ex:
                from lutris.gui.dialogs import ErrorDialog
                ErrorDialog(ex.args[0])
                self.emit('cancel', {})
                return

        timer_id = GLib.timeout_add(100, self._progress)
        self.cancel_button.set_sensitive(True)
        if not self.downloader.state == self.downloader.DOWNLOADING:
            self.downloader.start()
        return timer_id

    def cancel(self, _widget=None):
        """Cancel the current download."""
        if self.downloader:
            self.downloader.cancel()
        self.cancel_button.set_sensitive(False)
        self.emit('cancel', {})

    def _progress(self):
        """Show download progress."""
        progress = min(self.downloader.check_progress(), 1)
        if self.downloader.state in [
                self.downloader.CANCELLED, self.downloader.ERROR
        ]:
            self.progressbar.set_fraction(0)
            self._set_text("Download interrupted")
            if self.downloader.state == self.downloader.CANCELLED:
                self.emit('cancel', {})
            return False
        self.progressbar.set_fraction(progress)
        megabytes = 1024 * 1024
        progress_text = ("%0.2f / %0.2fMB (%0.2fMB/s), %s remaining" %
                         (float(self.downloader.downloaded_size) / megabytes,
                          float(self.downloader.full_size) / megabytes,
                          float(self.downloader.average_speed) / megabytes,
                          self.downloader.time_left))
        self._set_text(progress_text)
        if self.downloader.state == self.downloader.COMPLETED:
            self.cancel_button.set_sensitive(False)
            self.emit('complete', {})
            return False
        return True

    def _set_text(self, text):
        markup = u"<span size='10000'>{}</span>".format(text)
        self.progress_label.set_markup(markup)
Exemple #17
0
class DownloadProgressBox(Gtk.VBox):
    """Progress bar used to monitor a file download."""
    __gsignals__ = {
        'complete': (GObject.SignalFlags.RUN_LAST, None,
                     (GObject.TYPE_PYOBJECT,)),
        'cancel': (GObject.SignalFlags.RUN_LAST, None,
                   (GObject.TYPE_PYOBJECT,)),
        'error': (GObject.SignalFlags.RUN_LAST, None,
                  (GObject.TYPE_PYOBJECT,)),
    }

    def __init__(self, params, cancelable=True, downloader=None):
        super(DownloadProgressBox, self).__init__()

        self.downloader = downloader
        self.url = params.get('url')
        self.dest = params.get('dest')
        self.referer = params.get('referer')
        title = params.get('title', "Downloading {}".format(self.url))

        self.main_label = Gtk.Label(title)
        self.main_label.set_alignment(0, 0)
        self.main_label.set_property('wrap', True)
        self.main_label.set_margin_bottom(10)
        self.main_label.set_max_width_chars(70)
        self.main_label.set_selectable(True)
        self.main_label.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
        self.pack_start(self.main_label, True, True, 0)

        progress_box = Gtk.Box()

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_margin_top(5)
        self.progressbar.set_margin_bottom(5)
        self.progressbar.set_margin_right(10)
        progress_box.pack_start(self.progressbar, True, True, 0)

        self.cancel_button = Gtk.Button.new_with_mnemonic('_Cancel')
        self.cancel_button.connect('clicked', self.cancel)
        if not cancelable:
            self.cancel_button.set_sensitive(False)
        progress_box.pack_end(self.cancel_button, False, False, 0)

        self.pack_start(progress_box, False, False, 0)

        self.progress_label = Gtk.Label()
        self.progress_label.set_alignment(0, 0)
        self.pack_start(self.progress_label, True, True, 0)

        self.show_all()

    def start(self):
        """Start downloading a file."""
        if not self.downloader:
            try:
                self.downloader = Downloader(self.url,
                                             self.dest,
                                             referer=self.referer,
                                             overwrite=True)
            except RuntimeError as ex:
                from lutris.gui.dialogs import ErrorDialog
                ErrorDialog(ex.args[0])
                self.emit('cancel', {})
                return

        timer_id = GLib.timeout_add(100, self._progress)
        self.cancel_button.set_sensitive(True)
        if not self.downloader.state == self.downloader.DOWNLOADING:
            self.downloader.start()
        return timer_id

    def cancel(self, _widget=None):
        """Cancel the current download."""
        if self.downloader:
            self.downloader.cancel()
        self.cancel_button.set_sensitive(False)
        self.emit('cancel', {})

    def _progress(self):
        """Show download progress."""
        progress = min(self.downloader.check_progress(), 1)
        if self.downloader.state in [self.downloader.CANCELLED,
                                     self.downloader.ERROR]:
            self.progressbar.set_fraction(0)
            self._set_text("Download interrupted")
            if self.downloader.state == self.downloader.CANCELLED:
                self.emit('cancel', {})
            return False
        self.progressbar.set_fraction(progress)
        megabytes = 1024 * 1024
        progress_text = (
            "%0.2f / %0.2fMB (%0.2fMB/s), %s remaining" % (
                float(self.downloader.downloaded_size) / megabytes,
                float(self.downloader.full_size) / megabytes,
                float(self.downloader.average_speed) / megabytes,
                self.downloader.time_left
            )
        )
        self._set_text(progress_text)
        if self.downloader.state == self.downloader.COMPLETED:
            self.cancel_button.set_sensitive(False)
            self.emit('complete', {})
            return False
        return True

    def _set_text(self, text):
        markup = u"<span size='10000'>{}</span>".format(text)
        self.progress_label.set_markup(markup)