wepub

Check-in [34f89ce2a5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Serialize writing to state files, as I seem to get competing writes every now and then.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:34f89ce2a5cc235eb7f3591e20050a83f1a7ac6da673cb467bf2f3d2677ec8c8
User & Date: vandys 2019-03-09 21:49:01
Context
2019-03-09
21:49
Snap position as we leave a chapter, as otherwise our current reading position can be too far beyond what was last saved. check-in: 05c6b57556 user: vandys tags: master, trunk
21:49
Serialize writing to state files, as I seem to get competing writes every now and then. check-in: 34f89ce2a5 user: vandys tags: master, trunk
21:48
uncharenc() across large buffers (like, whole book in one epub "chapter") was very, very slow. Break up conversions to line-by-line, push out converted text incrementally. check-in: 91a4709d67 user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to put.py.

1
2
3
4
5
6


7
8
9
10
11
12
13
..
34
35
36
37
38
39
40


41
42
43
44
45
46
47
..
55
56
57
58
59
60
61
62
63
64
65
#
# put.py
#       Handle PUT operations to the ePub reader
#
import os, sys, urllib, json
from chore.utils import Exclusion



class PUT_mixin(object):

    def __init__(self):
        self.dispatchers.append( ("PUT", self.put_state) )

    # The actual file operations of a PUT; in its own function
................................................................................
        except:
            sys.stderr.write("Can't save state to %s\n" % (statepath,))


    # Here's some fresh state?
    # /state.json?doc=X
    def put_state(self, buf):


        if not self.path_match("state.json"):
            return False,None
        doc = self.vals.get("doc")
        if doc is None:
            return False,None

        # Get a filesystem safe name, see if we can save the info
................................................................................
        statepath = "var/state/%s/%s.json" % (self.user, doc)
	try:
	    newvals = json.loads(buf)
	except:
	    sys.stderr.write("Bad newvals\n")
	    return True,self.send_error(400)

	with Exclusion():
	    self.put_state2(doc, statepath, newvals)

        return True,self.send_result("", "text/html")





|
>
>







 







>
>







 







|



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
59
60
61
62
63
64
65
66
67
68
69
#
# put.py
#       Handle PUT operations to the ePub reader
#
import os, sys, urllib, json
import chore

StateLock = chore.utils.Exclusion()

class PUT_mixin(object):

    def __init__(self):
        self.dispatchers.append( ("PUT", self.put_state) )

    # The actual file operations of a PUT; in its own function
................................................................................
        except:
            sys.stderr.write("Can't save state to %s\n" % (statepath,))


    # Here's some fresh state?
    # /state.json?doc=X
    def put_state(self, buf):
	global StateLock

        if not self.path_match("state.json"):
            return False,None
        doc = self.vals.get("doc")
        if doc is None:
            return False,None

        # Get a filesystem safe name, see if we can save the info
................................................................................
        statepath = "var/state/%s/%s.json" % (self.user, doc)
	try:
	    newvals = json.loads(buf)
	except:
	    sys.stderr.write("Bad newvals\n")
	    return True,self.send_error(400)

	with StateLock:
	    self.put_state2(doc, statepath, newvals)

        return True,self.send_result("", "text/html")