예제 #1
0
 def _download(self):
     self.downloaded_files.clear()
     if not os.path.exists(self.download_path):
         os.makedirs(self.download_path)
     for filename, version in self.update_files.iteritems():
         response = utils.GetURL(self.download_url % {
             "version": self._appversion,
             "file": filename,
             "platform": self.platform
         },
                                 buffsize=self.download_chunk_size,
                                 useragent=self._useragent)
         if response.code == 200:
             setup_path = os.path.join(self.download_path, filename)
             response.save(setup_path)
             self.downloaded_files[
                 filename] = response.finished and not response.failed
         else:
             self.downloaded_files[filename] = False
     self.downloaded = any(self.downloaded_files.itervalues())
     self.text = self.simple_update_text % {
         "appname": self.appname,
         "version": self.new_version
     }
     self.title = self.simple_update_title % {
         "appname": self.appname,
         "version": self.new_version
     }
예제 #2
0
    def _newcheck(self, current_version):
        # This one make a request to self.version_url with a POST,
        # giving all the information about version, lang and platform
        args = {
            "version": self.version,
            "lang": self.lang,
            "platform": self.platform
        }
        response = utils.GetURL(self.version_url % args,
                                args=args,
                                useragent=self._useragent)
        if response.code == 200:
            self.update_data = json.load(response)
            logging.debug("Server: %r" % (self.update_data, ))
        self.checked = True

        if self.must_download and (  # APP_UPDATE_MODE 2 allows check without download
                "update" in self.update_data
                and "files" in self.update_data["update"]
                and self.update_data["update"]["files"]):
            self.outdated = True
            self.new_version = max(
                i.get("version", 0)
                for i in self.update_data["update"]["files"])
        else:
            self.outdated = False
            self.new_version = None
예제 #3
0
    def _newdownload(self):
        del self.update_commands[:]
        if not os.path.exists(self.download_path):
            os.makedirs(self.download_path)

        if "update" in self.update_data and "files" in self.update_data[
                "update"]:
            for n, fdata in enumerate(self.update_data["update"]["files"]):
                response = utils.GetURL(fdata["url"],
                                        buffsize=self.download_chunk_size,
                                        useragent=self._useragent)
                if response.code == 200:
                    setup_path = os.path.join(self.download_path,
                                              "update_%d.exe" % n)
                    with open(setup_path, "wb") as f:
                        for data in response:
                            f.write(data)
                    self.update_commands.append((setup_path, ) +
                                                tuple(fdata["argv"]))
                else:
                    # TODO(felipe): on error, try again later
                    logging.error("GET %s %s" % (response.code, fdata["url"]))
                    break
            else:
                self.downloaded = bool(self.update_commands)
                self.text = self.update_data["update"].get(
                    "text", self.default_text)
                self.title = self.update_data["update"].get(
                    "title", self.default_title)
        else:
            self.downloaded = False
            self.text = self.default_text
            self.title = self.default_title
예제 #4
0
 def preview(self):
     if "img_data_scaled" in self.data:
         # Nice, we already have a scaled version of the image
         return self.data["img_data_scaled"]
     elif "img_data" in self.data and self.data["img_data"] is not None:
         # Get its size and see if we need to rescale it
         data = self.data["img_data"]
         img = wx.ImageFromStream(StringIO(data), utils.image_type(data))
         w, h = img.GetSize()
         if w > 150 or h > 150:
             f = 150. / min(w, h)  # factor used to rescale
             img.Rescale(int(f * w), int(f * h), wx.IMAGE_QUALITY_HIGH)
             io_data_new = StringIO()  # will contain the raw image rescaled
             img.SaveStream(io_data_new, type=wx.BITMAP_TYPE_PNG)
             self.data["img_data_scaled"] = io_data_new.getvalue()
             img.Destroy()
         else:
             self.data["img_data_scaled"] = data
         return self.data["img_data_scaled"]
     elif self._download.user_data and self._download.user_data.get(
             "img", None):
         self.data["img_data"] = None
         url = self._download.user_data["img"]
         utils. async (utils.GetURL(url).read_all,
                       success=self._preview_finished,
                       error=self._preview_failed)
     return None
예제 #5
0
    def __init__(self, manager, url, extra_name, installer, params):
        '''
        Thread for downloading and installing plugins

        Params:
            manager
            modulepath: extra directory
            url: extra URL
            extra_name: extra name
            installer: True if URL refers to an executable (installer)
        '''
        threading.Thread.__init__(self)

        self.manager = manager
        self.name = extra_name
        self.modulepath = self.manager._modulepath
        self.installer = installer
        self.params = params
        self.url = url
        self.progress_updater = threading.Thread(target=self._progress_updater_loop)

        if installer:
            self.path = my_env.tempfilepath("extra", my_env.appname_to_bin(extra_name))
        else:
            self.path = os.path.join(self.modulepath, extra_name)

        try:
            self.geturl = utils.GetURL(url)
        except:
            self.geturl = None

        self._instances.append(self)
def check_if_torrent_url(url):
    '''torrent files are bencoded dictionaries. That means they starts
    with dN: being N the number of characters of first key.'''
    d = utils.GetURL(url)
    head = d.read(10)
    d.close()
    return head.startswith("d") and head[1:].split(":", 1)[0].isdigit()
예제 #7
0
    def _check(self, current_version):
        response = utils.GetURL(self.version_url, useragent=self._useragent)
        if response.code == 200:
            updates = []
            for i in response.lines:
                try:
                    version, filename = i.strip().split(None, 1)
                    updates.append((filename, version))
                except BaseException as e:
                    logging.debug(e)
            self.update_files.clear()
            self.update_files.update(updates)

        self.checked = True
        self.outdated = any(v > current_version
                            for v in self.update_files.itervalues())
        self.new_version = max(
            v for k, v in
            self.update_files.iteritems()) if self.outdated else None
예제 #8
0
    def retry(self):
        # Cancel current download
        if self._cthread and self._cthread.is_alive():
            self.cancel()
            self._chtread.join()

        # GetURL (re)initialization
        if self._geturl:
            self._geturl.retry()
        else:
            try:
                bsize = my_env.get_blocksize(self.tmpfolder)
            except BaseException as e:
                logging.exception(e)
                bsize = 4096  # 4 KiB
            self._geturl = utils.GetURL(self.url, buffsize=bsize)

        # Thread info initialization
        self._ok = False
        self._dest = None

        self._cthread = threading.Thread(target=self._run)
        self._cthread.start()