send tz offset at start of sync; allow passing in offset at collection creation
This commit is contained in:
parent
92673c99d8
commit
683edeeb07
@ -81,7 +81,11 @@ class _Collection:
|
|||||||
backend: Backend
|
backend: Backend
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, db: DB, backend: Backend, server: bool = False, log: bool = False
|
self,
|
||||||
|
db: DB,
|
||||||
|
backend: Backend,
|
||||||
|
server: Optional["anki.storage.ServerData"] = None,
|
||||||
|
log: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
self._debugLog = log
|
self._debugLog = log
|
||||||
@ -92,7 +96,7 @@ class _Collection:
|
|||||||
self.server = server
|
self.server = server
|
||||||
self._lastSave = time.time()
|
self._lastSave = time.time()
|
||||||
self.clearUndo()
|
self.clearUndo()
|
||||||
self.media = MediaManager(self, server)
|
self.media = MediaManager(self, server is not None)
|
||||||
self.models = ModelManager(self)
|
self.models = ModelManager(self)
|
||||||
self.decks = DeckManager(self)
|
self.decks = DeckManager(self)
|
||||||
self.tags = TagManager(self)
|
self.tags = TagManager(self)
|
||||||
@ -132,6 +136,8 @@ class _Collection:
|
|||||||
self.sched = V2Scheduler(self)
|
self.sched = V2Scheduler(self)
|
||||||
if not self.server:
|
if not self.server:
|
||||||
self.conf["localOffset"] = self.sched.timezoneOffset()
|
self.conf["localOffset"] = self.sched.timezoneOffset()
|
||||||
|
elif self.server.minutes_west is not None:
|
||||||
|
self.conf["localOffset"] = self.server.minutes_west
|
||||||
|
|
||||||
def changeSchedulerVer(self, ver: int) -> None:
|
def changeSchedulerVer(self, ver: int) -> None:
|
||||||
if ver == self.schedVer():
|
if ver == self.schedVer():
|
||||||
|
@ -6,7 +6,7 @@ import copy
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from typing import Any, Dict, Tuple
|
from typing import Any, Dict, Optional, Tuple
|
||||||
|
|
||||||
from anki.backend import Backend
|
from anki.backend import Backend
|
||||||
from anki.collection import _Collection
|
from anki.collection import _Collection
|
||||||
@ -23,8 +23,12 @@ from anki.stdmodels import (
|
|||||||
from anki.utils import intTime, isWin
|
from anki.utils import intTime, isWin
|
||||||
|
|
||||||
|
|
||||||
|
class ServerData:
|
||||||
|
minutes_west: Optional[int]
|
||||||
|
|
||||||
|
|
||||||
def Collection(
|
def Collection(
|
||||||
path: str, lock: bool = True, server: bool = False, log: bool = False
|
path: str, lock: bool = True, server: Optional[ServerData] = None, log: bool = False
|
||||||
) -> _Collection:
|
) -> _Collection:
|
||||||
"Open a new or existing collection. Path must be unicode."
|
"Open a new or existing collection. Path must be unicode."
|
||||||
backend = Backend()
|
backend = Backend()
|
||||||
|
14
anki/sync.py
14
anki/sync.py
@ -36,7 +36,7 @@ class UnexpectedSchemaChange(Exception):
|
|||||||
class Syncer:
|
class Syncer:
|
||||||
cursor: Optional[sqlite3.Cursor]
|
cursor: Optional[sqlite3.Cursor]
|
||||||
|
|
||||||
def __init__(self, col, server=None) -> None:
|
def __init__(self, col: "anki.storage._Collection", server=None) -> None:
|
||||||
self.col = col
|
self.col = col
|
||||||
self.server = server
|
self.server = server
|
||||||
|
|
||||||
@ -95,7 +95,9 @@ class Syncer:
|
|||||||
return "basicCheckFailed"
|
return "basicCheckFailed"
|
||||||
# step 2: startup and deletions
|
# step 2: startup and deletions
|
||||||
runHook("sync", "meta")
|
runHook("sync", "meta")
|
||||||
rrem = self.server.start(minUsn=self.minUsn, lnewer=self.lnewer)
|
rrem = self.server.start(
|
||||||
|
minUsn=self.minUsn, lnewer=self.lnewer, offset=self.col.localOffset()
|
||||||
|
)
|
||||||
|
|
||||||
# apply deletions to server
|
# apply deletions to server
|
||||||
lgraves = self.removed()
|
lgraves = self.removed()
|
||||||
@ -178,7 +180,9 @@ class Syncer:
|
|||||||
|
|
||||||
def changes(self) -> dict:
|
def changes(self) -> dict:
|
||||||
"Bundle up small objects."
|
"Bundle up small objects."
|
||||||
d = dict(models=self.getModels(), decks=self.getDecks(), tags=self.getTags())
|
d: Dict[str, Any] = dict(
|
||||||
|
models=self.getModels(), decks=self.getDecks(), tags=self.getTags()
|
||||||
|
)
|
||||||
if self.lnewer:
|
if self.lnewer:
|
||||||
d["conf"] = self.getConf()
|
d["conf"] = self.getConf()
|
||||||
d["crt"] = self.col.crt
|
d["crt"] = self.col.crt
|
||||||
@ -328,7 +332,7 @@ from notes where %s"""
|
|||||||
|
|
||||||
def remove(self, graves) -> None:
|
def remove(self, graves) -> None:
|
||||||
# pretend to be the server so we don't set usn = -1
|
# pretend to be the server so we don't set usn = -1
|
||||||
self.col.server = True
|
self.col.server = True # type: ignore
|
||||||
|
|
||||||
# notes first, so we don't end up with duplicate graves
|
# notes first, so we don't end up with duplicate graves
|
||||||
self.col._remNotes(graves["notes"])
|
self.col._remNotes(graves["notes"])
|
||||||
@ -338,7 +342,7 @@ from notes where %s"""
|
|||||||
for oid in graves["decks"]:
|
for oid in graves["decks"]:
|
||||||
self.col.decks.rem(oid, childrenToo=False)
|
self.col.decks.rem(oid, childrenToo=False)
|
||||||
|
|
||||||
self.col.server = False
|
self.col.server = False # type: ignore
|
||||||
|
|
||||||
# Models
|
# Models
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
Loading…
Reference in New Issue
Block a user