annotate inkscape/firefox/helper_mb.py @ 336:995eb2c1a1aa

Merge
author wycc
date Sat, 07 Mar 2009 14:25:20 +0800
parents d5327265da1e
children 63aaf96209cd
rev   line source
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
1 #!/usr/bin/python
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
2 from twisted.web import server, resource,soap
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
3 from twisted.internet import reactor,defer
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
4 import os,time
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
5 import traceback
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
6
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
7
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
8
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
9
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
10 class Server(soap.SOAPPublisher):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
11 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
12 SOAP server for inkscape extension.
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
13 """
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
14 def soap_PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
15 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
16 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
17 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
18 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
19 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
20 self.client.PUBLISH().addCallback(self.quit,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
21 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
22
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
23 def quit(self,result,d):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
24 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
25 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
26 self.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
27 def soap_INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
28 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
29 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
30 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
31 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
32 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
33 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
34 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
35 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
36 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
37 self.client.INSERTKEY(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
38 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
39 def soap_EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
40 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
41 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
42 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
43 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
44 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
45 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
46 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
47 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
48 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
49 self.client.EXTENDSCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
50 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
51 def soap_DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
52 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
53 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
54 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
55 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
56 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
57 n = int(n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
58 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
59 n = 0
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
60 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
61 self.client.DELETESCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
62 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
63
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
64 def soap_SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
65 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
66 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
67 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
68 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
69
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
70 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
71 self.client.SCENE(n).addCallback(self.generic_return,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
72 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
73 def generic_return(self,result,d):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
74 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
75 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
76 def generic_error(self,result,d):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
77 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
78 d.errback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
79 def soap_START(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
80 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
81 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
82 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
83 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
84 return "OK"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85 def soap_GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
86 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
87 print "xxxxx"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
88 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
89 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
90 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
91 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
92 d = defer.Deferred()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
93 self.client.GETDOC().addCallback(self.generic_return,d)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
94 print "yyy"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
95 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
96 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 traceback.print_exc()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
100
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
101
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
102 class Client(object):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
103 def __init__(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 self.proxy = soap.Proxy('http://localhost:8080')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
105 def PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
106 return self.proxy.callRemote('PUBLISH')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
107 def SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
108 return self.proxy.callRemote('SCENE',n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 def INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 return self.proxy.callRemote('INSERTKEY',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 def GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
112 return self.proxy.callRemote('GETDOC')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
113 def EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
114 return self.proxy.callRemote('EXTENDSCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
115 def DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
116 return self.proxy.callRemote('DELETESCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
117
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
118 os.system("killall -9 inkscape-mb")
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
119 pid = os.fork()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
120 if pid==0:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
121 os.execvp("inkscape-mb",["inkscape-mb","/tmp/scene.mbsvg"])
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
122 s = Server()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
123 s.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
124 s.pid = pid
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
125 site = server.Site(s)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
126 reactor.listenTCP(19192,site)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
127 reactor.run()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
128
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
129