Exemple #1
0
 def downloadIds(self, ids):
     log = []
     errs = []
     self.mw.progress.start(immediate=True)
     for n in ids:
         ret = download(self.mw, n)
         if ret[0] == "error":
             errs.append(
                 _("Error downloading %(id)s: %(error)s") %
                 dict(id=n, error=ret[1]))
             continue
         data, fname = ret
         fname = fname.replace("_", " ")
         name = os.path.splitext(fname)[0]
         ret = self.install(io.BytesIO(data),
                            manifest={
                                "package": str(n),
                                "name": name,
                                "mod": intTime()
                            })
         if ret[0] is False:
             if ret[1] == "conflicts":
                 continue
             if ret[1] == "zip":
                 showWarning(
                     _("The download was corrupt. Please try again."))
             elif ret[1] == "manifest":
                 showWarning(_("Invalid add-on manifest."))
         log.append(_("Downloaded %(fname)s" % dict(fname=name)))
     self.mw.progress.finish()
     return log, errs
Exemple #2
0
    def accept(self):
        QDialog.accept(self)

        # get codes
        try:
            ids = [int(n) for n in self.form.code.text().split()]
        except ValueError:
            showWarning(_("Invalid code."))
            return

        errors = []

        self.mw.progress.start(immediate=True)
        for n in ids:
            ret = download(self.mw, n)
            if ret[0] == "error":
                errors.append(
                    _("Error downloading %(id)s: %(error)s") %
                    dict(id=n, error=ret[1]))
                continue
            data, fname = ret
            self.mw.addonManager.install(data, fname)
        self.mw.progress.finish()
        if not errors:
            tooltip(_("Download successful. Please restart Anki."),
                    period=3000)
        else:
            showWarning("\n".join(errors))
Exemple #3
0
    def downloadIds(self, ids):
        log = []
        errs = []
        self.mw.progress.start(immediate=True)
        for n in ids:
            ret = download(self.mw, n)
            if ret[0] == "error":
                errs.append(
                    _("Error downloading %(id)s: %(error)s") %
                    dict(id=n, error=ret[1]))
                continue
            data, fname = ret
            fname = fname.replace("_", " ")
            name = os.path.splitext(fname)[0]
            result = self.install(
                io.BytesIO(data),
                manifest={
                    "package": str(n),
                    "name": name,
                    "mod": intTime()
                },
            )
            if not result.success:
                errs.extend(self._installationErrorReport(result, n))
            else:
                log.extend(self._installationSuccessReport(result, n))

        self.mw.progress.finish()
        return log, errs
Exemple #4
0
 def downloadIds(self, ids):
     log = []
     errs = []
     self.mw.progress.start(immediate=True)
     for n in ids:
         ret = download(self.mw, n)
         if ret[0] == "error":
             errs.append(_("Error downloading %(id)s: %(error)s") % dict(id=n, error=ret[1]))
             continue
         data, fname = ret
         fname = fname.replace("_", " ")
         name = os.path.splitext(fname)[0]
         ret = self.install(io.BytesIO(data),
                            manifest={"package": str(n), "name": name,
                                      "mod": intTime()})
         if ret[0] is False:
             if ret[1] == "conflicts":
                 continue
             if ret[1] == "zip":
                 showWarning(_("The download was corrupt. Please try again."))
             elif ret[1] == "manifest":
                 showWarning(_("Invalid add-on manifest."))
         log.append(_("Downloaded %(fname)s" % dict(fname=name)))
     self.mw.progress.finish()
     return log, errs
Exemple #5
0
    def accept(self):
        QDialog.accept(self)

        # get codes
        try:
            ids = [int(n) for n in self.form.code.text().split()]
        except ValueError:
            showWarning(_("Invalid code."))
            return

        errors = []

        self.mw.progress.start(immediate=True)
        for n in ids:
            ret = download(self.mw, n)
            if ret[0] == "error":
                errors.append(_("Error downloading %(id)s: %(error)s") % dict(id=n, error=ret[1]))
                continue
            data, fname = ret
            self.mw.addonManager.install(data, fname)
        self.mw.progress.finish()
        if not errors:
            tooltip(_("Download successful. Please restart Anki."), period=3000)
        else:
            showWarning("\n".join(errors))
    def install(self, path):
        ret = download(aqt.mw, str(self.codeNumber))
        if not ret:
            return # TODO error
        data, fname = ret
        aqt.mw.progress.finish()

        if fname.endswith(".py"):
            # .py files go directly into the addon folder
            path = os.path.join(path, fname)
            try:
                open(path, "w").write(data)
            except:
                print "Error somewhere"
            self.installed = True
            self.installed_path = os.path.dirname(path)
            return

        # .zip file
        z = ZipFile(StringIO(data))
        base = path
        for n in z.namelist():
            if n.endswith("/"):
                # folder; ignore
                continue
            # write
            z.extract(n, base)

        self.installed = True
        self.installed_path = path
Exemple #7
0
 def downloadDictionaries():
     showInfo(_("No Yomichan dictionaries found\nDownloading now"))
     ret = download(aqt.mw, 2027900559)
     if not ret:
         raise Exception("Could not download dictionary files")
     data, fname = ret
     aqt.mw.addonManager.install(data, fname)
     aqt.mw.progress.finish()
Exemple #8
0
 def accept(self):
     QDialog.accept(self)
     # create downloader thread
     ret = download(self.mw, self.form.code.text())
     if not ret:
         return
     data, fname = ret
     self.mw.addonManager.install(data, fname)
     self.mw.progress.finish()
     showInfo(_("Download successful. Please restart Anki."))
Exemple #9
0
 def accept(self):
     QDialog.accept(self)
     # create downloader thread
     ret = download(self.mw, self.form.code.text())
     if not ret:
         return
     data, fname = ret
     self.mw.addonManager.install(data, fname)
     self.mw.progress.finish()
     showInfo(_("Download successful. Please restart Anki."))
Exemple #10
0
    def upgrade_using_anki(self):
        if MetaConfigObj.IsAnki21():
            ret = download(mw, self.addon_code)
            if ret[0] == "error":
                # err = "Error downloading %(id)s: %(error)s" % dict(id=addon_code, error=ret[1])
                return
            else:
                # err = ''
                data, fname = ret
                fname = fname.replace("_", " ")
                mw.addonManager.install(str(self.addon_code), data, fname)
                # name = os.path.splitext(fname)[0]
                mw.progress.finish()

            # mw.addonManager.downloadIds([addon_code, ])
        else:
            ret = download(mw, self.addon_code)
            if not ret:
                return
            data, fname = ret
            mw.addonManager.install(data, fname)
            mw.progress.finish()
Exemple #11
0
def japaneseSupportExists(editor):
    if not mecab:
        if askUser(_('Ruby generator needs "Japanese Support" add-on to work. Install it now?')):
        	from aqt.downloader import download
        	ret = download(editor.mw, japaneseSupportCode)
        	if not ret:
        		return False
        	data, fname = ret
        	editor.mw.addonManager.install(data, fname)
        	editor.mw.progress.finish()
        	showInfo(_("Download successful. Please restart Anki."))
        return False
    else:
    	return True
def do_upgrade():
    #Broken
    mw.progress.start(immediate=True)
    ret = download(mw, ankiweb_code)
    if not ret:
        mw.progress.finish()
        showInfo(_("Download failed. Please try again later."))
        return False
    else:
        data, fname = ret
        mw.addonManager.install(data, fname)
        mw.progress.finish()
        showInfo(_("Download successful. Please restart Anki."))
        return True
def do_upgrade():
    #Broken
    mw.progress.start(immediate=True)
    ret = download(mw, ankiweb_code)
    if not ret:
        mw.progress.finish()
        showInfo(_("Download failed. Please try again later."))
        return False
    else:
        data, fname = ret
        mw.addonManager.install(data, fname)
        mw.progress.finish()
        showInfo(_("Download successful. Please restart Anki."))
        return True
Exemple #14
0
 def downloadIds(self, ids):
     log = []
     errs = []
     self.mw.progress.start(immediate=True)
     for n in ids:
         ret = download(self.mw, n)
         if ret[0] == "error":
             errs.append(_("Error downloading %(id)s: %(error)s") % dict(id=n, error=ret[1]))
             continue
         data, fname = ret
         self.install(str(n), data, fname)
         name = os.path.splitext(fname)[0]
         log.append(_("Downloaded %(fname)s" % dict(fname=name)))
     self.mw.progress.finish()
     return log, errs
Exemple #15
0
def installJapaneseSupport():
    # Install the Japanese Support addon
    if askUser(
            _(u'Japanese Cloze Examples need "Japanese Support" addon to work. Install it now?'
              )):
        from aqt.downloader import download
        ret = download(mw, JAPANESESUPPORTCODE)
        if not ret:
            return False
        data, fname = ret
        mw.addonManager.install(data, fname)
        mw.progress.finish()
        showInfo(_(u"Download successful. Please restart Anki."))
        return True
    else:
        return False
Exemple #16
0
    def downloadIds(self, ids):
        log = []
        errs = []
        self.mw.progress.start(immediate=True)
        for n in ids:
            ret = download(self.mw, n)
            if ret[0] == "error":
                errs.append(
                    _("Error downloading %(id)s: %(error)s") %
                    dict(id=n, error=ret[1]))
                continue
            data, fname = ret
            fname = fname.replace("_", " ")
            name = os.path.splitext(fname)[0]
            ret = self.install(io.BytesIO(data),
                               manifest={
                                   "package": str(n),
                                   "name": name,
                                   "mod": intTime()
                               })
            if ret[0] is False:
                if ret[1] == "zip":
                    msg = _("Corrupt add-on file.")
                elif ret[1] == "manifest":
                    msg = _("Invalid add-on manifest.")
                else:
                    msg = "Unknown error: {}".format(ret[1])
                errs.append(
                    _("Error downloading %(id)s: %(error)s") %
                    dict(id=n, error=msg))
            else:
                log.append(_("Downloaded %(fname)s" % dict(fname=name)))
                if ret[2]:
                    log.append(
                        _("The following conflicting add-ons were disabled:") +
                        " " + " ".join(ret[2]))

        self.mw.progress.finish()
        return log, errs