From b95c3f57c4fdf742c4f2194453768fea3f645e39 Mon Sep 17 00:00:00 2001 From: "St.Huang" Date: Sat, 14 Jul 2018 20:59:29 +0800 Subject: [PATCH] bug fixes --- .gitignore | 3 ++- src/fastwq/libs/AnkiHub/updates.py | 2 +- src/fastwq/libs/ankihub.py | 21 ++++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 2196b10..f951f8b 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,5 @@ addons/ .pylintrc *.pyc release.zip -README.txt \ No newline at end of file +README.txt +.fastwq.ankihub.json \ No newline at end of file diff --git a/src/fastwq/libs/AnkiHub/updates.py b/src/fastwq/libs/AnkiHub/updates.py index ffe4512..71abc72 100644 --- a/src/fastwq/libs/AnkiHub/updates.py +++ b/src/fastwq/libs/AnkiHub/updates.py @@ -59,7 +59,7 @@ class Ui_DialogUpdates(object): QtCore.QMetaObject.connectSlotsByName(DialogUpdates) def retranslateUi(self, DialogUpdates): - DialogUpdates.setWindowTitle(_translate("DialogUpdates", "Update Checker", None)) + DialogUpdates.setWindowTitle(_translate("DialogUpdates", "FastWQ - Update Checker", None)) self.labelUpdates.setText(_translate("DialogUpdates", "

A new version of {0} is available for download!

Do you want to update {1}to version {2}?

Changes from your version are listed below:

", None)) #self.always.setText(_translate("DialogUpdates", "Always update", None)) self.update.setText(_translate("DialogUpdates", "Update", None)) diff --git a/src/fastwq/libs/ankihub.py b/src/fastwq/libs/ankihub.py index 47a9b2a..6b34d6c 100644 --- a/src/fastwq/libs/ankihub.py +++ b/src/fastwq/libs/ankihub.py @@ -13,10 +13,12 @@ import aqt from aqt import mw from anki.hooks import addHook from anki.utils import isMac, isWin +from ..context import APP_ICON + -''' # taken from Anki's aqt/profiles.py def defaultBase(): + ''' print(mw.pm.addonFolder()) if isWin: loc = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.DocumentsLocation) @@ -34,10 +36,13 @@ def defaultBase(): return os.path.expanduser("~/Documents/Anki") else: return os.path.join(loc, "Anki") -''' + ''' + path = mw.pm.addonFolder() + return path[:path.rindex(os.path.sep)] + headers = {"User-Agent": "AnkiHub"} -dataPath = '.ankihub.json' #os.path.join(defaultBase(),'.ankihub.json') +dataPath = os.path.join(defaultBase(),'.fastwq.ankihub.json') class DialogUpdates(QtGui.QDialog, Ui_DialogUpdates): @@ -48,9 +53,9 @@ class DialogUpdates(QtGui.QDialog, Ui_DialogUpdates): self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint ) + self.setWindowIcon(APP_ICON) self.setupUi(self) totalSize = sum(map(lambda x:x['size'],data['assets'])) - def answer(doUpdate,answ): self.update.setEnabled(False) #self.dont.setEnabled(False) @@ -100,7 +105,9 @@ def installZipFile(data, fname): base = mw.pm.addonFolder()#os.path.join(defaultBase(),'addons') if fname.endswith(".py"): path = os.path.join(base, fname) - open(path, "wb").write(data) + with open(path, "wb") as file: + file.write(data) + file.close() return True # .zip file try: @@ -164,6 +171,7 @@ def updateSingle(repositories,path,data): repositories[path]['update'] = answer with open(dataPath,'w') as file: json.dump(repositories,file,indent=2) + file.close() if install: appendHtml('Executing new scripts...
') newFiles = set(aqt.mw.addonManager.files()) - set(filesBefore) @@ -190,6 +198,7 @@ def updateSingle(repositories,path,data): repositories[path]['update'] = answer with open(dataPath,'w') as file: json.dump(repositories,file,indent=2) + file.close() onReady() return callback @@ -200,6 +209,7 @@ def update(add=[],install=False, VERSION='v0.0.0'): try: with open(dataPath,'r') as file: repositories = json.load(file) + file.close() except: repositories = {} # 'dayjaby/AnkiHub': { @@ -288,6 +298,7 @@ def update(add=[],install=False, VERSION='v0.0.0'): with open(dataPath,'w') as file: json.dump(repositories,file,indent=2) + file.close() return ret #update()