add devMode flag to utils

also remove the extra toolbar call in loadProfile(), as we require a
restart to update the translations anyway
This commit is contained in:
Damien Elmes 2017-08-01 14:28:13 +10:00
parent 83c96770c8
commit 0543a4533b
5 changed files with 14 additions and 13 deletions

View file

@ -14,7 +14,7 @@ import traceback
from anki.lang import _, ngettext from anki.lang import _, ngettext
from anki.utils import ids2str, fieldChecksum, stripHTML, \ from anki.utils import ids2str, fieldChecksum, stripHTML, \
intTime, splitFields, joinFields, maxID, json intTime, splitFields, joinFields, maxID, json, devMode
from anki.hooks import runFilter, runHook from anki.hooks import runFilter, runHook
from anki.sched import Scheduler from anki.sched import Scheduler
from anki.models import ModelManager from anki.models import ModelManager
@ -834,7 +834,7 @@ and queue = 0""", intTime(), self.usn())
buf = "[%s] %s:%s(): %s" % (intTime(), os.path.basename(path), fn, buf = "[%s] %s:%s(): %s" % (intTime(), os.path.basename(path), fn,
", ".join([customRepr(x) for x in args])) ", ".join([customRepr(x) for x in args]))
self._logHnd.write(buf + "\n") self._logHnd.write(buf + "\n")
if os.environ.get("ANKIDEV"): if devMode:
print(buf) print(buf)
def _openLog(self): def _openLog(self):

View file

@ -8,7 +8,7 @@ import random
import requests import requests
from anki.db import DB from anki.db import DB
from anki.utils import ids2str, intTime, json, isWin, isMac, platDesc, checksum from anki.utils import ids2str, intTime, json, platDesc, checksum, devMode
from anki.consts import * from anki.consts import *
from .hooks import runHook from .hooks import runHook
import anki import anki
@ -576,7 +576,7 @@ class RemoteServer(HttpSyncer):
HttpSyncer.__init__(self, hkey) HttpSyncer.__init__(self, hkey)
def syncURL(self): def syncURL(self):
if os.getenv("ANKIDEV"): if devMode:
return "https://l1sync.ankiweb.net/sync/" return "https://l1sync.ankiweb.net/sync/"
return SYNC_BASE + "sync/" return SYNC_BASE + "sync/"
@ -645,7 +645,7 @@ class FullSyncer(HttpSyncer):
self.col = col self.col = col
def syncURL(self): def syncURL(self):
if os.getenv("ANKIDEV"): if devMode:
return "https://l1.ankiweb.net/sync/" return "https://l1.ankiweb.net/sync/"
return SYNC_BASE + "sync/" return SYNC_BASE + "sync/"
@ -829,7 +829,7 @@ class RemoteMediaServer(HttpSyncer):
HttpSyncer.__init__(self, hkey, client) HttpSyncer.__init__(self, hkey, client)
def syncURL(self): def syncURL(self):
if os.getenv("ANKIDEV"): if devMode:
return "https://l1.ankiweb.net/msync/" return "https://l1.ankiweb.net/msync/"
return SYNC_MEDIA_BASE return SYNC_MEDIA_BASE

View file

@ -342,6 +342,7 @@ def call(argv, wait=True, **kwargs):
isMac = sys.platform.startswith("darwin") isMac = sys.platform.startswith("darwin")
isWin = sys.platform.startswith("win32") isWin = sys.platform.startswith("win32")
isLin = not isMac and not isWin isLin = not isMac and not isWin
devMode = os.getenv("ANKIDEV", 0)
invalidFilenameChars = ":*?\"<>|" invalidFilenameChars = ":*?\"<>|"

View file

@ -13,7 +13,8 @@ from threading import Thread
from send2trash import send2trash from send2trash import send2trash
from aqt.qt import * from aqt.qt import *
from anki import Collection from anki import Collection
from anki.utils import isWin, isMac, intTime, splitFields, ids2str from anki.utils import isWin, isMac, intTime, splitFields, ids2str, \
devMode
from anki.hooks import runHook, addHook from anki.hooks import runHook, addHook
import aqt import aqt
import aqt.progress import aqt.progress
@ -207,8 +208,6 @@ Are you sure?""")):
if self.pm.profile['mainWindowState']: if self.pm.profile['mainWindowState']:
restoreGeom(self, "mainWindow") restoreGeom(self, "mainWindow")
restoreState(self, "mainWindow") restoreState(self, "mainWindow")
# toolbar needs to be retranslated
self.toolbar.draw()
# titlebar # titlebar
self.setWindowTitle("Anki - " + self.pm.name) self.setWindowTitle("Anki - " + self.pm.name)
# show and raise window for osx # show and raise window for osx
@ -299,7 +298,7 @@ Debug info:
except: except:
corrupt = True corrupt = True
if not corrupt: if not corrupt:
if os.getenv("ANKIDEV", 0): if devMode:
corrupt = False corrupt = False
else: else:
corrupt = self.col.db.scalar("pragma integrity_check") != "ok" corrupt = self.col.db.scalar("pragma integrity_check") != "ok"
@ -336,7 +335,7 @@ the manual for information on how to restore from an automatic backup."))
def backup(self): def backup(self):
nbacks = self.pm.profile['numBackups'] nbacks = self.pm.profile['numBackups']
if not nbacks or os.getenv("ANKIDEV", 0): if not nbacks or devMode:
return return
dir = self.pm.backupFolder() dir = self.pm.backupFolder()
path = self.pm.collectionPath() path = self.pm.collectionPath()

View file

@ -7,6 +7,7 @@ from http import HTTPStatus
import http.server import http.server
import socketserver import socketserver
import errno import errno
from anki.utils import devMode
# locate web folder in source/binary distribution # locate web folder in source/binary distribution
def _getExportFolder(): def _getExportFolder():
@ -53,7 +54,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
try: try:
self.copyfile(f, self.wfile) self.copyfile(f, self.wfile)
except Exception as e: except Exception as e:
if os.getenv("ANKIDEV"): if devMode:
print("http server caught exception:", e) print("http server caught exception:", e)
else: else:
# swallow it - user likely surfed away from # swallow it - user likely surfed away from
@ -89,7 +90,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
raise raise
def log_message(self, format, *args): def log_message(self, format, *args):
if not os.getenv("ANKIDEV"): if not devMode:
return return
print("%s - - [%s] %s" % print("%s - - [%s] %s" %
(self.address_string(), (self.address_string(),