mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
more open() and regex strings
This commit is contained in:
parent
3b71f8e44e
commit
81d4b77ee1
3 changed files with 16 additions and 10 deletions
|
@ -840,7 +840,7 @@ and queue = 0""", intTime(), self.usn())
|
|||
def _openLog(self):
|
||||
if not self._debugLog:
|
||||
return
|
||||
lpath = re.sub("\.anki2$", ".log", self.path)
|
||||
lpath = re.sub(r"\.anki2$", ".log", self.path)
|
||||
if os.path.exists(lpath) and os.path.getsize(lpath) > 10*1024*1024:
|
||||
lpath2 = lpath + ".old"
|
||||
if os.path.exists(lpath2):
|
||||
|
@ -849,6 +849,7 @@ and queue = 0""", intTime(), self.usn())
|
|||
self._logHnd = open(lpath, "a", encoding="utf8")
|
||||
|
||||
def _closeLog(self):
|
||||
self._logHnd.close()
|
||||
self._logHnd = None
|
||||
|
||||
# Card Flags
|
||||
|
|
|
@ -39,7 +39,7 @@ class AddonManager:
|
|||
|
||||
def managedAddons(self):
|
||||
return [d for d in self.allAddons()
|
||||
if re.match("^\d+$", d)]
|
||||
if re.match(r"^\d+$", d)]
|
||||
|
||||
def addonsFolder(self, dir=None):
|
||||
root = self.mw.pm.addonFolder()
|
||||
|
@ -76,13 +76,15 @@ When loading '%(name)s':
|
|||
def addonMeta(self, dir):
|
||||
path = self._addonMetaPath(dir)
|
||||
try:
|
||||
return json.load(open(path, encoding="utf8"))
|
||||
with open(path, encoding="utf8") as f:
|
||||
return json.load(f)
|
||||
except:
|
||||
return dict()
|
||||
|
||||
def writeAddonMeta(self, dir, meta):
|
||||
path = self._addonMetaPath(dir)
|
||||
json.dump(meta, open(path, "w", encoding="utf8"))
|
||||
with open(path, "w", encoding="utf8") as f:
|
||||
json.dump(meta, f)
|
||||
|
||||
def toggleEnabled(self, dir):
|
||||
meta = self.addonMeta(dir)
|
||||
|
@ -203,14 +205,16 @@ When loading '%(name)s':
|
|||
def addonConfigDefaults(self, dir):
|
||||
path = os.path.join(self.addonsFolder(dir), "config.json")
|
||||
try:
|
||||
return json.load(open(path, encoding="utf8"))
|
||||
with open(path, encoding="utf8") as f:
|
||||
return json.load(f)
|
||||
except:
|
||||
return None
|
||||
|
||||
def addonConfigHelp(self, dir):
|
||||
path = os.path.join(self.addonsFolder(dir), "config.md")
|
||||
if os.path.exists(path):
|
||||
return markdown.markdown(open(path).read())
|
||||
with open(path) as f:
|
||||
return markdown.markdown(f.read())
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
@ -325,7 +329,7 @@ class AddonsDialog(QDialog):
|
|||
addon = self.onlyOneSelected()
|
||||
if not addon:
|
||||
return
|
||||
if re.match("^\d+$", addon):
|
||||
if re.match(r"^\d+$", addon):
|
||||
openLink(aqt.appShared + f"info/{addon}")
|
||||
else:
|
||||
showWarning(_("Add-on was not downloaded from AnkiWeb."))
|
||||
|
|
|
@ -405,7 +405,8 @@ from the profile screen."))
|
|||
# do backup
|
||||
fname = time.strftime("backup-%Y-%m-%d-%H.%M.%S.colpkg", time.localtime(time.time()))
|
||||
newpath = os.path.join(dir, fname)
|
||||
data = open(path, "rb").read()
|
||||
with open(path, "rb") as f:
|
||||
data = f.read()
|
||||
b = self.BackupThread(newpath, data)
|
||||
b.start()
|
||||
|
||||
|
@ -413,7 +414,7 @@ from the profile screen."))
|
|||
backups = []
|
||||
for file in os.listdir(dir):
|
||||
# only look for new-style format
|
||||
m = re.match("backup-\d{4}-\d{2}-.+.colpkg", file)
|
||||
m = re.match(r"backup-\d{4}-\d{2}-.+.colpkg", file)
|
||||
if not m:
|
||||
continue
|
||||
backups.append(file)
|
||||
|
@ -1170,7 +1171,7 @@ will be lost. Continue?"""))
|
|||
tgt = tgt or self
|
||||
for action in tgt.findChildren(QAction):
|
||||
txt = str(action.text())
|
||||
m = re.match("^(.+)\(&.+\)(.+)?", txt)
|
||||
m = re.match(r"^(.+)\(&.+\)(.+)?", txt)
|
||||
if m:
|
||||
action.setText(m.group(1) + (m.group(2) or ""))
|
||||
|
||||
|
|
Loading…
Reference in a new issue