mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
sync tweaks
This commit is contained in:
parent
8ede57b024
commit
0a677fee56
5 changed files with 22 additions and 36 deletions
|
@ -37,13 +37,15 @@ Save & close:
|
||||||
col.close()
|
col.close()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys, simplejson as _simplejson
|
||||||
if sys.version_info[0] > 2:
|
if sys.version_info[0] > 2:
|
||||||
raise Exception("Anki should be run with python2.x.")
|
raise Exception("Anki should be run with python2.x.")
|
||||||
elif sys.version_info[1] < 5:
|
elif sys.version_info[1] < 5:
|
||||||
raise Exception("Anki requires Python 2.5+")
|
raise Exception("Anki requires Python 2.5+")
|
||||||
if sys.getfilesystemencoding().lower() in ("ascii", "ansi_x3.4-1968"):
|
elif sys.getfilesystemencoding().lower() in ("ascii", "ansi_x3.4-1968"):
|
||||||
raise Exception("Anki requires a UTF-8 locale.")
|
raise Exception("Anki requires a UTF-8 locale.")
|
||||||
|
elif _simplejson.__version__ < "1.7.3":
|
||||||
|
raise Exception("SimpleJSON must be 1.7.3 or later.")
|
||||||
|
|
||||||
version = "1.99"
|
version = "1.99"
|
||||||
from anki.storage import Collection
|
from anki.storage import Collection
|
||||||
|
|
|
@ -31,16 +31,11 @@ COUNT_REMAINING = 1
|
||||||
MEDIA_ADD = 0
|
MEDIA_ADD = 0
|
||||||
MEDIA_REM = 1
|
MEDIA_REM = 1
|
||||||
|
|
||||||
# syncing vars
|
# deck schema & syncing vars
|
||||||
SYNC_ZIP_SIZE = int(2.5*1024*1024)
|
|
||||||
MIME_BOUNDARY = "Anki-sync-boundary"
|
|
||||||
SYNC_URL = os.environ.get("SYNC_URL") or "https://ankiweb.net/sync/"
|
|
||||||
SYNC_VER = 0
|
|
||||||
HTTP_CERTS = os.path.join(os.path.dirname(__file__), "ankiweb.certs")
|
|
||||||
HTTP_TIMEOUT = 30
|
|
||||||
|
|
||||||
# deck schema
|
|
||||||
SCHEMA_VERSION = 1
|
SCHEMA_VERSION = 1
|
||||||
|
SYNC_ZIP_SIZE = int(2.5*1024*1024)
|
||||||
|
SYNC_URL = os.environ.get("SYNC_URL") or "https://beta.ankiweb.net/sync/"
|
||||||
|
SYNC_VER = 0
|
||||||
|
|
||||||
# Labels
|
# Labels
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
25
anki/sync.py
25
anki/sync.py
|
@ -7,22 +7,20 @@ from cStringIO import StringIO
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from anki.db import DB
|
from anki.db import DB
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
from anki.utils import ids2str, checksum, intTime, httpCon
|
from anki.utils import ids2str, checksum, intTime
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from hooks import runHook
|
from hooks import runHook
|
||||||
|
|
||||||
if simplejson.__version__ < "1.7.3":
|
# syncing vars
|
||||||
raise Exception("SimpleJSON must be 1.7.3 or later.")
|
HTTP_CERTS = os.path.join(os.path.dirname(__file__), "ankiweb.certs")
|
||||||
|
HTTP_TIMEOUT = 30
|
||||||
|
|
||||||
# - make sure /sync/download is compressed
|
def httpCon():
|
||||||
# - status() should be using the hooks instead
|
return httplib2.Http(
|
||||||
|
timeout=HTTP_TIMEOUT, ca_certs=HTTP_CERTS,
|
||||||
# todo:
|
# python2 doesn't support SNI
|
||||||
# - ability to cancel
|
disable_ssl_certificate_validation="beta" in SYNC_URL)
|
||||||
# - need to make sure syncing doesn't bump the col modified time if nothing was
|
|
||||||
# changed, since by default closing the col bumps the mod time
|
|
||||||
# - ensure the user doesn't add foreign chars to passsword
|
|
||||||
|
|
||||||
# Incremental syncing
|
# Incremental syncing
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -410,7 +408,8 @@ class HttpSyncer(object):
|
||||||
|
|
||||||
def req(self, method, fobj=None, comp=6,
|
def req(self, method, fobj=None, comp=6,
|
||||||
badAuthRaises=True, hkey=True):
|
badAuthRaises=True, hkey=True):
|
||||||
bdry = "--"+MIME_BOUNDARY
|
BOUNDARY="Anki-sync-boundary"
|
||||||
|
bdry = "--"+BOUNDARY
|
||||||
buf = StringIO()
|
buf = StringIO()
|
||||||
# compression flag and session key as post vars
|
# compression flag and session key as post vars
|
||||||
vars = {}
|
vars = {}
|
||||||
|
@ -445,7 +444,7 @@ Content-Type: application/octet-stream\r\n\r\n""")
|
||||||
size = buf.tell()
|
size = buf.tell()
|
||||||
# connection headers
|
# connection headers
|
||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'multipart/form-data; boundary=%s' % MIME_BOUNDARY,
|
'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDARY,
|
||||||
'Content-Length': str(size),
|
'Content-Length': str(size),
|
||||||
}
|
}
|
||||||
body = buf.getvalue()
|
body = buf.getvalue()
|
||||||
|
|
|
@ -302,13 +302,3 @@ 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")
|
||||||
|
|
||||||
# OS helpers
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
def httpCon():
|
|
||||||
disable = os.environ.get("SSL_NOVALIDATE") or False
|
|
||||||
return httplib2.Http(
|
|
||||||
timeout=HTTP_TIMEOUT,
|
|
||||||
disable_ssl_certificate_validation=disable,
|
|
||||||
ca_certs=HTTP_CERTS)
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import nose, os, tempfile, shutil, time
|
||||||
from tests.shared import assertException
|
from tests.shared import assertException
|
||||||
|
|
||||||
from anki.errors import *
|
from anki.errors import *
|
||||||
from anki.utils import intTime, httpCon
|
from anki.utils import intTime
|
||||||
from anki.sync import Syncer, FullSyncer, LocalServer, RemoteServer, \
|
from anki.sync import Syncer, FullSyncer, LocalServer, RemoteServer, \
|
||||||
MediaSyncer, RemoteMediaServer
|
MediaSyncer, RemoteMediaServer, httpCon
|
||||||
from anki.notes import Note
|
from anki.notes import Note
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
from tests.shared import getEmptyDeck
|
from tests.shared import getEmptyDeck
|
||||||
|
|
Loading…
Reference in a new issue