Mercurial > MadButterfly
annotate inkscape/firefox/helper_mb.py @ 1127:baf4c4d48cff
Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 14 Dec 2010 11:04:56 +0800 |
parents | 29145d2affdb |
children |
rev | line source |
---|---|
288 | 1 #!/usr/bin/python |
2 from twisted.web import server, resource,soap | |
3 from twisted.internet import reactor,defer | |
353
3d03451be435
Import the file specified in the mozplugger helper. This is the first step to handle the same file between inkscape and helper
wycc
parents:
339
diff
changeset
|
4 import os,time,sys |
288 | 5 import traceback |
6 | |
7 | |
8 | |
9 | |
10 class Server(soap.SOAPPublisher): | |
11 """ | |
12 SOAP server for inkscape extension. | |
13 """ | |
14 def soap_PUBLISH(self): | |
15 if self.client == None: | |
16 os.kill(self.pid,12) | |
17 time.sleep(1) | |
18 self.client = Client() | |
19 d = defer.Deferred() | |
20 self.client.PUBLISH().addCallback(self.quit,d) | |
21 return d | |
22 | |
23 def quit(self,result,d): | |
24 d.callback(result) | |
25 self.client = None | |
26 def soap_INSERTKEY(self,layer,n): | |
27 if self.client == None: | |
28 os.kill(self.pid,12) | |
29 time.sleep(1) | |
30 self.client = Client() | |
31 try: | |
32 n = int(n) | |
33 except: | |
34 n = 0 | |
35 d = defer.Deferred() | |
36 self.client.INSERTKEY(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
37 return d | |
38 def soap_EXTENDSCENE(self,layer,n): | |
39 if self.client == None: | |
40 os.kill(self.pid,12) | |
41 time.sleep(1) | |
42 self.client = Client() | |
43 try: | |
44 n = int(n) | |
45 except: | |
46 n = 0 | |
47 d = defer.Deferred() | |
48 self.client.EXTENDSCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
49 return d | |
50 def soap_DELETESCENE(self,layer,n): | |
51 if self.client == None: | |
52 os.kill(self.pid,12) | |
53 time.sleep(1) | |
54 self.client = Client() | |
55 try: | |
56 n = int(n) | |
57 except: | |
58 n = 0 | |
59 d = defer.Deferred() | |
60 self.client.DELETESCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
61 return d | |
62 | |
63 def soap_SCENE(self,n): | |
64 if self.client == None: | |
65 os.kill(self.pid,12) | |
66 time.sleep(1) | |
67 self.client = Client() | |
68 | |
69 d = defer.Deferred() | |
70 self.client.SCENE(n).addCallback(self.generic_return,d) | |
71 return d | |
72 def generic_return(self,result,d): | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
73 print "Get result:" |
288 | 74 print [result] |
75 d.callback(result) | |
76 def generic_error(self,result,d): | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
77 print "Error:" |
288 | 78 print [result] |
79 d.errback(result) | |
80 def soap_START(self): | |
81 if self.client == None: | |
82 os.kill(self.pid,12) | |
83 time.sleep(1) | |
84 self.client = Client() | |
85 return "OK" | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
86 def getdoc_error(self,result,d): |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
87 try: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
88 print "reconnect" |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
89 time.sleep(1) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
90 os.kill(self.pid,12) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
91 op = self.client.GETDOC() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
92 op.addCallback(self.generic_return,d) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
93 op.addErrback(self.getdoc_error,d) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
94 except: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
95 traceback.print_exc() |
288 | 96 def soap_GETDOC(self): |
97 try: | |
98 print "xxxxx" | |
99 if self.client == None: | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
100 while os.kill(self.pid,12)<0: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
101 time.sleep(1) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
102 |
288 | 103 self.client = Client() |
104 d = defer.Deferred() | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
105 op = self.client.GETDOC() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
106 op.addCallback(self.generic_return,d) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
107 op.addErrback(self.getdoc_error,d) |
288 | 108 print "yyy" |
109 return d | |
110 except: | |
111 traceback.print_exc() | |
358 | 112 def soap_GETPRJ(self,prj): |
113 try: | |
114 f = open(prj,"r") | |
115 l = f.read() | |
116 f.close() | |
117 return l | |
118 except: | |
119 traceback.print_exc() | |
120 | |
381 | 121 def soap_CHANGESYMBOL(self,id,name): |
122 if self.client == None: | |
123 os.kill(self.pid,12) | |
124 time.sleep(1) | |
125 self.client = Client() | |
126 d = defer.Deferred() | |
127 print "send changesymbol" | |
128 self.client.CHANGESYMBOL(id,name).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
129 return d | |
130 | |
288 | 131 class Client(object): |
132 def __init__(self): | |
133 self.proxy = soap.Proxy('http://localhost:8080') | |
134 def PUBLISH(self): | |
135 return self.proxy.callRemote('PUBLISH') | |
136 def SCENE(self,n): | |
137 return self.proxy.callRemote('SCENE',n) | |
138 def INSERTKEY(self,layer,n): | |
139 return self.proxy.callRemote('INSERTKEY',layer,n) | |
140 def GETDOC(self): | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
141 doc = self.proxy.callRemote('GETDOC') |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
142 return doc |
288 | 143 def EXTENDSCENE(self,layer,n): |
144 return self.proxy.callRemote('EXTENDSCENE',layer,n) | |
145 def DELETESCENE(self,layer,n): | |
146 return self.proxy.callRemote('DELETESCENE',layer,n) | |
381 | 147 def CHANGESYMBOL(self,id,name): |
148 print "send soap CHANGESYMBOL to to client" | |
149 return self.proxy.callRemote('CHANGESYMBOL',id,name) | |
288 | 150 |
151 os.system("killall -9 inkscape-mb") | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
152 try: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
153 f = open("/tmp/madbuilder.pid","r") |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
154 pid = int(f.read()) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
155 f.close() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
156 os.system("kill -9 %d" % pid) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
157 f = open("/tmp/madbuilder.pid","w") |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
158 f.write("%d\n" % os.getpid()) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
159 f.close() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
160 except: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
161 traceback.print_exc() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
162 |
288 | 163 pid = os.fork() |
164 if pid==0: | |
353
3d03451be435
Import the file specified in the mozplugger helper. This is the first step to handle the same file between inkscape and helper
wycc
parents:
339
diff
changeset
|
165 os.execvp("inkscape-mb",["inkscape-mb",sys.argv[1]]) |
288 | 166 s = Server() |
167 s.client = None | |
168 s.pid = pid | |
169 site = server.Site(s) | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
170 # Sleep for two seconds to wait for the inkscape become ready. It seems that our inkscape modification has |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
171 # semaphore issue so that it will be blocked if we connect to it in early stage. We need to check it and |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
172 # remove the following wait in the future. |
288 | 173 reactor.listenTCP(19192,site) |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
174 time.sleep(5) |
288 | 175 reactor.run() |
176 | |
177 |