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.utils import ids2str, fieldChecksum, stripHTML, \
intTime, splitFields, joinFields, maxID, json
intTime, splitFields, joinFields, maxID, json, devMode
from anki.hooks import runFilter, runHook
from anki.sched import Scheduler
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,
", ".join([customRepr(x) for x in args]))
self._logHnd.write(buf + "\n")
if os.environ.get("ANKIDEV"):
if devMode:
print(buf)
def _openLog(self):

View file

@ -8,7 +8,7 @@ import random
import requests
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 .hooks import runHook
import anki
@ -576,7 +576,7 @@ class RemoteServer(HttpSyncer):
HttpSyncer.__init__(self, hkey)
def syncURL(self):
if os.getenv("ANKIDEV"):
if devMode:
return "https://l1sync.ankiweb.net/sync/"
return SYNC_BASE + "sync/"
@ -645,7 +645,7 @@ class FullSyncer(HttpSyncer):
self.col = col
def syncURL(self):
if os.getenv("ANKIDEV"):
if devMode:
return "https://l1.ankiweb.net/sync/"
return SYNC_BASE + "sync/"
@ -829,7 +829,7 @@ class RemoteMediaServer(HttpSyncer):
HttpSyncer.__init__(self, hkey, client)
def syncURL(self):
if os.getenv("ANKIDEV"):
if devMode:
return "https://l1.ankiweb.net/msync/"
return SYNC_MEDIA_BASE

View file

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

View file

@ -13,7 +13,8 @@ from threading import Thread
from send2trash import send2trash
from aqt.qt import *
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
import aqt
import aqt.progress
@ -207,8 +208,6 @@ Are you sure?""")):
if self.pm.profile['mainWindowState']:
restoreGeom(self, "mainWindow")
restoreState(self, "mainWindow")
# toolbar needs to be retranslated
self.toolbar.draw()
# titlebar
self.setWindowTitle("Anki - " + self.pm.name)
# show and raise window for osx
@ -299,7 +298,7 @@ Debug info:
except:
corrupt = True
if not corrupt:
if os.getenv("ANKIDEV", 0):
if devMode:
corrupt = False
else:
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):
nbacks = self.pm.profile['numBackups']
if not nbacks or os.getenv("ANKIDEV", 0):
if not nbacks or devMode:
return
dir = self.pm.backupFolder()
path = self.pm.collectionPath()

View file

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