Mercurial > code > home > repos > light9
annotate bin/rdfdb @ 1041:a4632a7b2e17
upgrade knockout and jquery, simplify the static/ dirs for all web services
Ignore-this: 8637b7b61cc5d38e8cf15bb1afd7466c
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Wed, 28 May 2014 05:54:23 +0000 |
parents | 54027815c6cc |
children | c1face79c0e1 |
rev | line source |
---|---|
796 | 1 #!bin/python |
2 """ | |
3 other tools POST themselves to here as subscribers to the graph. They | |
811 | 4 are providing a URL we can PUT to with graph updates. |
796 | 5 |
6 we immediately PUT them back all the contents of the graph as a bunch | |
7 of adds. | |
8 | |
811 | 9 later we PUT them back with patches (del/add lists) when there are |
796 | 10 changes. |
11 | |
12 If we fail to reach a registered caller, we forget about it for future | |
811 | 13 calls. We could PUT empty diffs as a heartbeat to notice disappearing |
796 | 14 callers faster. |
15 | |
811 | 16 A caller can submit a patch which we'll persist and broadcast to every |
17 other client. | |
796 | 18 |
815
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
19 Global data undo should probably happen within this service. Some |
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
20 operations should not support undo, such as updating the default |
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
21 position of a window. How will we separate those? A blacklist of |
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
22 subj+pred pairs that don't save undo? Or just save the updates like |
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
23 everything else, but when you press undo, there's a way to tell which |
d7f1f868eb6c
toplevel window pos is saved in the graph. Patch conflicts no longer break as hard, but they don't exactly reset themselves right yet eiher
drewp@bigasterisk.com
parents:
814
diff
changeset
|
24 updates *should* be part of your app's undo system? |
796 | 25 |
26 Maybe some subgraphs are for transient data (e.g. current timecode, | |
27 mouse position in curvecalc) that only some listeners want to hear about. | |
28 | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
29 Deletes are graph-specific, so callers may be surprised to delete a |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
30 stmt from one graph but then find that statement is still true. |
796 | 31 |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
32 Alternate plan: would it help to insist that every patch is within |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
33 only one subgraph? I think it's ok for them to span multiple ones. |
796 | 34 |
35 Inserts can be made on any subgraphs, and each subgraph is saved in | |
36 its own file. The file might not be in a format that can express | |
37 graphs, so I'm just going to not store the subgraph URI in any file. | |
38 | |
39 I don't support wildcard deletes, and there are race conditions where a | |
40 s-p could end up with unexpected multiple objects. Every client needs | |
41 to be ready for this. | |
42 | |
43 We watch the files and push their own changes back to the clients. | |
44 | |
45 Persist our client list, to survive restarts. In another rdf file? A | |
46 random json one? memcache? Also hold the recent changes. We're not | |
47 logging everything forever, though, since the output files and a VCS | |
48 shall be used for that | |
49 | |
50 Bnodes: this rdfdb graph might be able to track bnodes correctly, and | |
51 they make for more compact n3 files. I'm not sure if it's going to be | |
52 hard to keep the client bnodes in sync though. File rereads would be | |
811 | 53 hard, if ever a bnode was used across graphs, so that probably should |
796 | 54 not be allowed. |
55 | |
56 Our API: | |
57 | |
58 GET / ui | |
811 | 59 GET /graph the whole graph, or a query from it (needed? just for ui browsing?) |
796 | 60 PUT /patches clients submit changes |
61 GET /patches (recent) patches from clients | |
62 POST /graphClients clientUpdate={uri} to subscribe | |
63 GET /graphClients current clients | |
64 | |
65 format: | |
66 json {"adds" : [[quads]...], | |
67 "deletes": [[quads]], | |
811 | 68 "senderUpdateUri" : tooluri, |
69 "created":tttt // maybe to help resolve some conflicts | |
796 | 70 } |
71 maybe use some http://json-ld.org/ in there. | |
72 | |
806 | 73 proposed rule feature: |
74 rdfdb should be able to watch a pair of (sourceFile, rulesFile) and | |
75 rerun the rules when either one changes. Should the sourceFile be able | |
76 to specify its own rules file? That would be easier | |
77 configuration. How do edits work? Not allowed? Patch the source only? | |
78 Also see the source graph loaded into a different ctx, and you can | |
79 edit that one and see the results in the output context? | |
80 | |
796 | 81 Our web ui: |
82 | |
811 | 83 sections |
84 | |
85 registered clients | |
796 | 86 |
811 | 87 recent patches, each one says what client it came from. You can reverse |
88 them here. We should be able to take patches that are close in time | |
89 and keep updating the same data (e.g. a stream of changes as the user | |
90 drags a slider) and collapse them into a single edit for clarity. | |
91 | |
92 Ways to display patches, using labels and creator/subj icons | |
93 where possible: | |
796 | 94 |
811 | 95 <creator> set <subj>'s <p> to <o> |
96 <creator> changed <subj>'s <pred> from <o1> to <o2> | |
97 <creator> added <o> to <s> <p> | |
98 | |
99 raw messages for debugging this client | |
806 | 100 |
811 | 101 ctx urls take you to-> |
102 files, who's dirty, have we seen external changes, notice big | |
103 files that are taking a long time to save | |
806 | 104 |
811 | 105 graph contents. plain rdf browser like an outliner or |
106 something. clicking any resource from the other displays takes you | |
107 to this, focused on that resource | |
803 | 108 |
796 | 109 """ |
110 from twisted.internet import reactor | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
111 import twisted.internet.error |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
112 from twisted.python.filepath import FilePath |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
113 from twisted.internet.inotify import humanReadableMask, IN_CREATE |
796 | 114 import sys, optparse, logging, json, os |
115 import cyclone.web, cyclone.httpclient, cyclone.websocket | |
116 sys.path.append(".") | |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
806
diff
changeset
|
117 from light9 import networking, showconfig, prof |
796 | 118 from rdflib import ConjunctiveGraph, URIRef, Graph |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
119 from light9.rdfdb.graphfile import GraphFile |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
120 from light9.rdfdb.patch import Patch, ALLSTMTS |
798
5c158d37f1ce
autoretry websocket. fix rdflib quad patching. only rerun handlers that asked for the affected subj-preds.
drewp@bigasterisk.com
parents:
797
diff
changeset
|
121 from light9.rdfdb.rdflibpatch import patchQuads |
843
77b5dbcf688d
split syncedgraph into several layers
drewp@bigasterisk.com
parents:
833
diff
changeset
|
122 |
77b5dbcf688d
split syncedgraph into several layers
drewp@bigasterisk.com
parents:
833
diff
changeset
|
123 from light9.rdfdb.patchsender import sendPatch |
77b5dbcf688d
split syncedgraph into several layers
drewp@bigasterisk.com
parents:
833
diff
changeset
|
124 from light9.rdfdb.patchreceiver import makePatchEndpointPutMethod |
796 | 125 |
126 from twisted.internet.inotify import INotify | |
833 | 127 from run_local import log |
128 log.setLevel(logging.DEBUG) | |
796 | 129 |
130 try: | |
131 import sys | |
132 sys.path.append("../homeauto/lib") | |
133 from cycloneerr import PrettyErrorHandler | |
134 except ImportError: | |
135 class PrettyErrorHandler(object): | |
136 pass | |
137 | |
138 class Client(object): | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
139 """ |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
140 one of our syncedgraph clients |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
141 """ |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
142 def __init__(self, updateUri, label, db): |
796 | 143 self.db = db |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
144 self.label = label |
796 | 145 self.updateUri = updateUri |
146 self.sendAll() | |
147 | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
148 def __repr__(self): |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
149 return "<%s client at %s>" % (self.label, self.updateUri) |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
150 |
796 | 151 def sendAll(self): |
152 """send the client the whole graph contents""" | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
153 log.info("sending all graphs to %s at %s" % |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
154 (self.label, self.updateUri)) |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
155 self.sendPatch(Patch( |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
156 addQuads=self.db.graph.quads(ALLSTMTS), |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
157 delQuads=[])) |
821 | 158 |
796 | 159 def sendPatch(self, p): |
843
77b5dbcf688d
split syncedgraph into several layers
drewp@bigasterisk.com
parents:
833
diff
changeset
|
160 return sendPatch(self.updateUri, p) |
796 | 161 |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
162 class WatchedFiles(object): |
811 | 163 """ |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
164 find files, notice new files. |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
165 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
166 This object watches directories. Each GraphFile watches its own file. |
811 | 167 """ |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
168 def __init__(self, topDirsToWatch, patch, getSubgraph): |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
169 self.topDirsToWatch = topDirsToWatch |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
170 self.patch, self.getSubgraph = patch, getSubgraph |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
171 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
172 # files from cwd become uris starting with this. *should* be |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
173 # building uris from the show uri in $LIGHT9_SHOW/URI |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
174 # instead. Who wants to keep their data in the same dir tree |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
175 # as the source code?! |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
176 self.topUri = URIRef("http://light9.bigasterisk.com/") |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
177 |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
178 self.graphFiles = {} # context uri : GraphFile |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
179 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
180 self.notifier = INotify() |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
181 self.notifier.startReading() |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
182 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
183 self.findAndLoadFiles() |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
184 |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
185 def findAndLoadFiles(self): |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
186 self.initialLoad = True |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
187 try: |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
188 for topdir in self.topDirsToWatch: |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
189 for dirpath, dirnames, filenames in os.walk(topdir): |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
190 for base in filenames: |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
191 self.watchFile(os.path.join(dirpath, base)) |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
192 self.notifier.watch(FilePath(dirpath), autoAdd=True, |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
193 callbacks=[self.dirChange]) |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
194 finally: |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
195 self.initialLoad = False |
821 | 196 |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
197 def dirChange(self, watch, path, mask): |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
198 if mask & IN_CREATE: |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
199 log.debug("%s created; consider adding a watch", path) |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
200 self.watchFile(path.path) |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
201 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
202 def watchFile(self, inFile): |
857
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
203 """ |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
204 consider adding a GraphFile to self.graphFiles |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
205 |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
206 inFile needs to be a relative path, not an absolute (e.g. in a |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
207 FilePath) because we use its exact relative form in the |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
208 context URI |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
209 """ |
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
210 if not os.path.isfile(inFile): |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
211 return |
921
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
212 if not any(inFile.startswith(prefix) for prefix in self.topDirsToWatch): |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
213 for prefix in self.topDirsToWatch: |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
214 prefixAbs = os.path.abspath(prefix) |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
215 if inFile.startswith(prefixAbs): |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
216 inFile = prefix + inFile[len(prefixAbs):] |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
217 break |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
218 else: |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
219 raise ValueError("can't correct %s to start with one of %s" % |
e673bdbe0be9
rdfdb: when a new n3 file shows up, fix its path to be relative again so the uri ends up right
drewp@bigasterisk.com
parents:
905
diff
changeset
|
220 (inFile, self.topDirsToWatch)) |
857
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
221 if os.path.splitext(inFile)[1] not in ['.n3']: |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
222 return |
830
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
223 |
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
224 # an n3 file with rules makes it all the way past this reading |
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
225 # and the serialization. Then, on the receiving side, a |
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
226 # SyncedGraph calls graphFromNQuad on the incoming data and |
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
227 # has a parse error. I'm not sure where this should be fixed |
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
228 # yet. |
857
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
229 if '-rules' in inFile: |
830
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
230 return |
904
86c6700d1d63
2013 code ignores 'config.n3' so 2012 code can use that instead
Drew Perttula <drewp@bigasterisk.com>
parents:
899
diff
changeset
|
231 |
86c6700d1d63
2013 code ignores 'config.n3' so 2012 code can use that instead
Drew Perttula <drewp@bigasterisk.com>
parents:
899
diff
changeset
|
232 # for legacy versions, compile all the config stuff you want |
86c6700d1d63
2013 code ignores 'config.n3' so 2012 code can use that instead
Drew Perttula <drewp@bigasterisk.com>
parents:
899
diff
changeset
|
233 # read into one file called config.n3. New versions won't read |
86c6700d1d63
2013 code ignores 'config.n3' so 2012 code can use that instead
Drew Perttula <drewp@bigasterisk.com>
parents:
899
diff
changeset
|
234 # it. |
86c6700d1d63
2013 code ignores 'config.n3' so 2012 code can use that instead
Drew Perttula <drewp@bigasterisk.com>
parents:
899
diff
changeset
|
235 if inFile.endswith("config.n3"): |
86c6700d1d63
2013 code ignores 'config.n3' so 2012 code can use that instead
Drew Perttula <drewp@bigasterisk.com>
parents:
899
diff
changeset
|
236 return |
830
9ba1c866bf4c
workaround for n3 file with rules in it
Drew Perttula <drewp@bigasterisk.com>
parents:
829
diff
changeset
|
237 |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
238 ctx = self.uriFromFile(inFile) |
857
1bda494a8c3a
attempted fix for FilePath making paths absolute (when they need to stay relative since they're used in uris)
drewp@bigasterisk.com
parents:
843
diff
changeset
|
239 gf = GraphFile(self.notifier, inFile, ctx, |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
240 self.patch, self.getSubgraph) |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
241 self.graphFiles[ctx] = gf |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
242 log.info("%s do initial read", inFile) |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
243 gf.reread() |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
244 |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
245 def aboutToPatch(self, ctx): |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
246 """ |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
247 warn us that a patch is about to come to this context. it's more |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
248 straightforward to create the new file now |
931 | 249 |
250 this is meant to make the file before we add triples, so we | |
251 wouldn't see the blank file and lose those triples. But it | |
252 didn't work, so there are other measures that make us not lose | |
253 the triples from a new file. Calling this before patching the | |
254 graph is still a reasonable thing to do, though. | |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
255 """ |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
256 g = self.getSubgraph(ctx) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
257 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
258 if ctx not in self.graphFiles: |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
259 outFile = self.fileForUri(ctx) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
260 log.info("starting new file %r", outFile) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
261 self.graphFiles[ctx] = GraphFile(self.notifier, outFile, ctx, |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
262 self.patch, self.getSubgraph) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
263 |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
264 def dirtyFiles(self, ctxs): |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
265 """mark dirty the files that we watch in these contexts. |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
266 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
267 the ctx might not be a file that we already read; it might be |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
268 for a new file we have to create, or it might be for a |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
269 transient context that we're not going to save |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
270 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
271 if it's a ctx with no file, error |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
272 """ |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
273 for ctx in ctxs: |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
274 g = self.getSubgraph(ctx) |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
275 self.graphFiles[ctx].dirty(g) |
796 | 276 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
277 def uriFromFile(self, filename): |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
278 assert filename.endswith('.n3'), filename |
899
21974e0ef0c4
guard against an abspath getting into a uri
Drew Perttula <drewp@bigasterisk.com>
parents:
857
diff
changeset
|
279 if not any(filename.startswith(t) for t in self.topDirsToWatch): |
21974e0ef0c4
guard against an abspath getting into a uri
Drew Perttula <drewp@bigasterisk.com>
parents:
857
diff
changeset
|
280 raise ValueError("filename %s doesn't start with any of %s" % |
21974e0ef0c4
guard against an abspath getting into a uri
Drew Perttula <drewp@bigasterisk.com>
parents:
857
diff
changeset
|
281 (filename, self.topDirsToWatch)) |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
282 return URIRef(self.topUri + filename[:-len('.n3')]) |
821 | 283 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
284 def fileForUri(self, ctx): |
826
05aabe3d7b02
fix some minor issues with graph contexts
Drew Perttula <drewp@bigasterisk.com>
parents:
821
diff
changeset
|
285 assert isinstance(ctx, URIRef), ctx |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
286 if not ctx.startswith(self.topUri): |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
287 raise ValueError("don't know what filename to use for %s" % ctx) |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
288 return ctx[len(self.topUri):] + ".n3" |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
289 |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
290 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
291 class Db(object): |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
292 """ |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
293 the master graph, all the connected clients, all the files we're watching |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
294 """ |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
295 def __init__(self, topDirsToWatch): |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
296 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
297 self.clients = [] |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
298 self.graph = ConjunctiveGraph() |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
299 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
300 self.watchedFiles = WatchedFiles(topDirsToWatch, |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
301 self.patch, self.getSubgraph) |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
302 |
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
303 self.summarizeToLog() |
821 | 304 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
305 def patch(self, p, dueToFileChange=False): |
796 | 306 """ |
307 apply this patch to the master graph then notify everyone about it | |
811 | 308 |
309 dueToFileChange if this is a patch describing an edit we read | |
310 *from* the file (such that we shouldn't write it back to the file) | |
311 | |
312 if p has a senderUpdateUri attribute, we won't send this patch | |
313 back to the sender with that updateUri | |
796 | 314 """ |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
315 ctx = p.getContext() |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
316 log.info("patching graph %s -%d +%d" % ( |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
317 ctx, len(p.delQuads), len(p.addQuads))) |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
318 |
931 | 319 if hasattr(self, 'watchedFiles'): # not available during startup |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
320 self.watchedFiles.aboutToPatch(ctx) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
921
diff
changeset
|
321 |
798
5c158d37f1ce
autoretry websocket. fix rdflib quad patching. only rerun handlers that asked for the affected subj-preds.
drewp@bigasterisk.com
parents:
797
diff
changeset
|
322 patchQuads(self.graph, p.delQuads, p.addQuads, perfect=True) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
806
diff
changeset
|
323 senderUpdateUri = getattr(p, 'senderUpdateUri', None) |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
324 |
796 | 325 for c in self.clients: |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
806
diff
changeset
|
326 if c.updateUri == senderUpdateUri: |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
806
diff
changeset
|
327 # this client has self-applied the patch already |
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
806
diff
changeset
|
328 continue |
798
5c158d37f1ce
autoretry websocket. fix rdflib quad patching. only rerun handlers that asked for the affected subj-preds.
drewp@bigasterisk.com
parents:
797
diff
changeset
|
329 d = c.sendPatch(p) |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
330 d.addErrback(self.clientErrored, c) |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
331 if not dueToFileChange: |
829
e53e78db7b17
refactor file watching. notice new files and dirs.
Drew Perttula <drewp@bigasterisk.com>
parents:
826
diff
changeset
|
332 self.watchedFiles.dirtyFiles([ctx]) |
796 | 333 sendToLiveClients(asJson=p.jsonRepr) |
334 | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
335 def clientErrored(self, err, c): |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
336 err.trap(twisted.internet.error.ConnectError) |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
337 log.info("connection error- dropping client %r" % c) |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
338 self.clients.remove(c) |
821 | 339 self.sendClientsToAllLivePages() |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
340 |
796 | 341 def summarizeToLog(self): |
798
5c158d37f1ce
autoretry websocket. fix rdflib quad patching. only rerun handlers that asked for the affected subj-preds.
drewp@bigasterisk.com
parents:
797
diff
changeset
|
342 log.info("contexts in graph (%s total stmts):" % len(self.graph)) |
796 | 343 for c in self.graph.contexts(): |
344 log.info(" %s: %s statements" % | |
345 (c.identifier, len(self.getSubgraph(c.identifier)))) | |
346 | |
347 def getSubgraph(self, uri): | |
811 | 348 """ |
349 this is meant to return a live view of the given subgraph, but | |
350 if i'm still working around an rdflib bug, it might return a | |
351 copy | |
352 | |
353 and it's returning triples, but I think quads would be better | |
354 """ | |
796 | 355 # this is returning an empty Graph :( |
356 #return self.graph.get_context(uri) | |
357 | |
358 g = Graph() | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
359 for s in self.graph.triples(ALLSTMTS, uri): |
796 | 360 g.add(s) |
361 return g | |
821 | 362 |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
363 def addClient(self, updateUri, label): |
796 | 364 [self.clients.remove(c) |
365 for c in self.clients if c.updateUri == updateUri] | |
366 | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
367 log.info("new client %s at %s" % (label, updateUri)) |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
368 self.clients.append(Client(updateUri, label, self)) |
796 | 369 self.sendClientsToAllLivePages() |
370 | |
371 def sendClientsToAllLivePages(self): | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
372 sendToLiveClients({"clients":[ |
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
373 dict(updateUri=c.updateUri, label=c.label) |
821 | 374 for c in self.clients]}) |
796 | 375 |
376 class GraphResource(PrettyErrorHandler, cyclone.web.RequestHandler): | |
377 def get(self): | |
905
741aa0f9be48
very simple con-neg on rdfdb /graph to support text/plain (ntriples)
Drew Perttula <drewp@bigasterisk.com>
parents:
904
diff
changeset
|
378 accept = self.request.headers.get('accept', '') |
741aa0f9be48
very simple con-neg on rdfdb /graph to support text/plain (ntriples)
Drew Perttula <drewp@bigasterisk.com>
parents:
904
diff
changeset
|
379 format = 'n3' |
741aa0f9be48
very simple con-neg on rdfdb /graph to support text/plain (ntriples)
Drew Perttula <drewp@bigasterisk.com>
parents:
904
diff
changeset
|
380 if accept == 'text/plain': |
741aa0f9be48
very simple con-neg on rdfdb /graph to support text/plain (ntriples)
Drew Perttula <drewp@bigasterisk.com>
parents:
904
diff
changeset
|
381 format = 'nt' |
1032
54027815c6cc
rdfdb can return 'application/n-quads' response
Drew Perttula <drewp@bigasterisk.com>
parents:
1017
diff
changeset
|
382 elif accept == 'application/n-quads': |
54027815c6cc
rdfdb can return 'application/n-quads' response
Drew Perttula <drewp@bigasterisk.com>
parents:
1017
diff
changeset
|
383 format = 'nquads' |
905
741aa0f9be48
very simple con-neg on rdfdb /graph to support text/plain (ntriples)
Drew Perttula <drewp@bigasterisk.com>
parents:
904
diff
changeset
|
384 self.write(self.settings.db.graph.serialize(format=format)) |
821 | 385 |
796 | 386 class Patches(PrettyErrorHandler, cyclone.web.RequestHandler): |
387 def __init__(self, *args, **kw): | |
388 cyclone.web.RequestHandler.__init__(self, *args, **kw) | |
843
77b5dbcf688d
split syncedgraph into several layers
drewp@bigasterisk.com
parents:
833
diff
changeset
|
389 p = makePatchEndpointPutMethod(self.settings.db.patch) |
796 | 390 self.put = lambda: p(self) |
391 | |
392 def get(self): | |
393 pass | |
394 | |
395 class GraphClients(PrettyErrorHandler, cyclone.web.RequestHandler): | |
396 def get(self): | |
397 pass | |
821 | 398 |
796 | 399 def post(self): |
400 upd = self.get_argument("clientUpdate") | |
401 try: | |
797
904913de4599
deletes are now quads. refactor files. named clients. auto client port
drewp@bigasterisk.com
parents:
796
diff
changeset
|
402 self.settings.db.addClient(upd, self.get_argument("label")) |
796 | 403 except: |
404 import traceback | |
405 traceback.print_exc() | |
406 raise | |
407 | |
408 liveClients = set() | |
409 def sendToLiveClients(d=None, asJson=None): | |
410 j = asJson or json.dumps(d) | |
411 for c in liveClients: | |
412 c.sendMessage(j) | |
413 | |
414 class Live(cyclone.websocket.WebSocketHandler): | |
821 | 415 |
796 | 416 def connectionMade(self, *args, **kwargs): |
811 | 417 log.info("websocket opened") |
796 | 418 liveClients.add(self) |
419 self.settings.db.sendClientsToAllLivePages() | |
420 | |
421 def connectionLost(self, reason): | |
811 | 422 log.info("websocket closed") |
796 | 423 liveClients.remove(self) |
424 | |
425 def messageReceived(self, message): | |
426 log.info("got message %s" % message) | |
427 self.sendMessage(message) | |
428 | |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
429 class NoExts(cyclone.web.StaticFileHandler): |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
430 # .xhtml pages can be get() without .xhtml on them |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
431 def get(self, path, *args, **kw): |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
432 if path and '.' not in path: |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
433 path = path + ".xhtml" |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
434 cyclone.web.StaticFileHandler.get(self, path, *args, **kw) |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
435 |
796 | 436 if __name__ == "__main__": |
437 logging.basicConfig() | |
438 log = logging.getLogger() | |
439 | |
440 parser = optparse.OptionParser() | |
441 parser.add_option("-v", "--verbose", action="store_true", | |
442 help="logging.DEBUG") | |
443 (options, args) = parser.parse_args() | |
444 | |
445 log.setLevel(logging.DEBUG if options.verbose else logging.INFO) | |
446 | |
1017
78423a65d4bc
rdfdb to use LIGHT9_SHOW env, not a flag
drewp@bigasterisk.com
parents:
931
diff
changeset
|
447 db = Db(topDirsToWatch=[os.environ['LIGHT9_SHOW']]) |
821 | 448 |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
449 from twisted.python import log as twlog |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
450 twlog.startLogging(sys.stdout) |
821 | 451 |
796 | 452 port = 8051 |
453 reactor.listenTCP(port, cyclone.web.Application(handlers=[ | |
454 (r'/live', Live), | |
455 (r'/graph', GraphResource), | |
456 (r'/patches', Patches), | |
457 (r'/graphClients', GraphClients), | |
458 | |
1041
a4632a7b2e17
upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents:
1032
diff
changeset
|
459 (r'/static/(.*)', cyclone.web.StaticFileHandler, {'path': 'static/'}), |
814
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
460 (r'/(.*)', NoExts, |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
461 {"path" : "light9/rdfdb/web", |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
462 "default_filename" : "index.xhtml"}), |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
463 |
1ae8e6b287e3
improvements to file watching. outline of how resync will work
drewp@bigasterisk.com
parents:
811
diff
changeset
|
464 ], debug=True, db=db)) |
796 | 465 log.info("serving on %s" % port) |
808
a631e075a5bf
KC big rewrites, now multiple KC instances can sync with rdfdb
drewp@bigasterisk.com
parents:
806
diff
changeset
|
466 prof.run(reactor.run, profile=False) |