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()
|
||||
"""
|
||||
|
||||
import sys
|
||||
import sys, simplejson as _simplejson
|
||||
if sys.version_info[0] > 2:
|
||||
raise Exception("Anki should be run with python2.x.")
|
||||
elif sys.version_info[1] < 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.")
|
||||
elif _simplejson.__version__ < "1.7.3":
|
||||
raise Exception("SimpleJSON must be 1.7.3 or later.")
|
||||
|
||||
version = "1.99"
|
||||
from anki.storage import Collection
|
||||
|
|
|
@ -31,16 +31,11 @@ COUNT_REMAINING = 1
|
|||
MEDIA_ADD = 0
|
||||
MEDIA_REM = 1
|
||||
|
||||
# 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
|
||||
# deck schema & syncing vars
|
||||
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
|
||||
##########################################################################
|
||||
|
|
25
anki/sync.py
25
anki/sync.py
|
@ -7,22 +7,20 @@ from cStringIO import StringIO
|
|||
from datetime import date
|
||||
from anki.db import DB
|
||||
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.lang import _
|
||||
from hooks import runHook
|
||||
|
||||
if simplejson.__version__ < "1.7.3":
|
||||
raise Exception("SimpleJSON must be 1.7.3 or later.")
|
||||
# syncing vars
|
||||
HTTP_CERTS = os.path.join(os.path.dirname(__file__), "ankiweb.certs")
|
||||
HTTP_TIMEOUT = 30
|
||||
|
||||
# - make sure /sync/download is compressed
|
||||
# - status() should be using the hooks instead
|
||||
|
||||
# todo:
|
||||
# - ability to cancel
|
||||
# - 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
|
||||
def httpCon():
|
||||
return httplib2.Http(
|
||||
timeout=HTTP_TIMEOUT, ca_certs=HTTP_CERTS,
|
||||
# python2 doesn't support SNI
|
||||
disable_ssl_certificate_validation="beta" in SYNC_URL)
|
||||
|
||||
# Incremental syncing
|
||||
##########################################################################
|
||||
|
@ -410,7 +408,8 @@ class HttpSyncer(object):
|
|||
|
||||
def req(self, method, fobj=None, comp=6,
|
||||
badAuthRaises=True, hkey=True):
|
||||
bdry = "--"+MIME_BOUNDARY
|
||||
BOUNDARY="Anki-sync-boundary"
|
||||
bdry = "--"+BOUNDARY
|
||||
buf = StringIO()
|
||||
# compression flag and session key as post vars
|
||||
vars = {}
|
||||
|
@ -445,7 +444,7 @@ Content-Type: application/octet-stream\r\n\r\n""")
|
|||
size = buf.tell()
|
||||
# connection headers
|
||||
headers = {
|
||||
'Content-Type': 'multipart/form-data; boundary=%s' % MIME_BOUNDARY,
|
||||
'Content-Type': 'multipart/form-data; boundary=%s' % BOUNDARY,
|
||||
'Content-Length': str(size),
|
||||
}
|
||||
body = buf.getvalue()
|
||||
|
|
|
@ -302,13 +302,3 @@ def call(argv, wait=True, **kwargs):
|
|||
|
||||
isMac = sys.platform.startswith("darwin")
|
||||
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 anki.errors import *
|
||||
from anki.utils import intTime, httpCon
|
||||
from anki.utils import intTime
|
||||
from anki.sync import Syncer, FullSyncer, LocalServer, RemoteServer, \
|
||||
MediaSyncer, RemoteMediaServer
|
||||
MediaSyncer, RemoteMediaServer, httpCon
|
||||
from anki.notes import Note
|
||||
from anki.cards import Card
|
||||
from tests.shared import getEmptyDeck
|
||||
|
|
Loading…
Reference in a new issue