Mercurial > MadButterfly
annotate inkscape/firefox/helper_mb.py @ 356:3e84458968ec
Move mb_img_data_t out from argument list of rdman_shape_image_new().
- Application should specify content of sh_image_t by fill the shape
with a paint_image_t.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 09 Mar 2009 23:05:57 +0800 |
parents | 3d03451be435 |
children | 50d33c3987ba |
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 print [result] | |
25 d.callback(result) | |
26 self.client = None | |
27 def soap_INSERTKEY(self,layer,n): | |
28 if self.client == None: | |
29 os.kill(self.pid,12) | |
30 time.sleep(1) | |
31 self.client = Client() | |
32 try: | |
33 n = int(n) | |
34 except: | |
35 n = 0 | |
36 d = defer.Deferred() | |
37 self.client.INSERTKEY(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
38 return d | |
39 def soap_EXTENDSCENE(self,layer,n): | |
40 if self.client == None: | |
41 os.kill(self.pid,12) | |
42 time.sleep(1) | |
43 self.client = Client() | |
44 try: | |
45 n = int(n) | |
46 except: | |
47 n = 0 | |
48 d = defer.Deferred() | |
49 self.client.EXTENDSCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
50 return d | |
51 def soap_DELETESCENE(self,layer,n): | |
52 if self.client == None: | |
53 os.kill(self.pid,12) | |
54 time.sleep(1) | |
55 self.client = Client() | |
56 try: | |
57 n = int(n) | |
58 except: | |
59 n = 0 | |
60 d = defer.Deferred() | |
61 self.client.DELETESCENE(layer,n).addCallback(self.generic_return,d).addErrback(self.generic_error,d) | |
62 return d | |
63 | |
64 def soap_SCENE(self,n): | |
65 if self.client == None: | |
66 os.kill(self.pid,12) | |
67 time.sleep(1) | |
68 self.client = Client() | |
69 | |
70 d = defer.Deferred() | |
71 self.client.SCENE(n).addCallback(self.generic_return,d) | |
72 return d | |
73 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
|
74 print "Get result:" |
288 | 75 print [result] |
76 d.callback(result) | |
77 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
|
78 print "Error:" |
288 | 79 print [result] |
80 d.errback(result) | |
81 def soap_START(self): | |
82 if self.client == None: | |
83 os.kill(self.pid,12) | |
84 time.sleep(1) | |
85 self.client = Client() | |
86 return "OK" | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
87 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
|
88 try: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
89 print "reconnect" |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
90 time.sleep(1) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
91 os.kill(self.pid,12) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
92 op = self.client.GETDOC() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
93 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
|
94 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
|
95 except: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
96 traceback.print_exc() |
288 | 97 def soap_GETDOC(self): |
98 try: | |
99 print "xxxxx" | |
100 if self.client == None: | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
101 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
|
102 time.sleep(1) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
103 |
288 | 104 self.client = Client() |
105 d = defer.Deferred() | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
106 op = self.client.GETDOC() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
107 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
|
108 op.addErrback(self.getdoc_error,d) |
288 | 109 print "yyy" |
110 return d | |
111 except: | |
112 traceback.print_exc() | |
113 | |
114 | |
115 | |
116 | |
117 class Client(object): | |
118 def __init__(self): | |
119 self.proxy = soap.Proxy('http://localhost:8080') | |
120 def PUBLISH(self): | |
121 return self.proxy.callRemote('PUBLISH') | |
122 def SCENE(self,n): | |
123 return self.proxy.callRemote('SCENE',n) | |
124 def INSERTKEY(self,layer,n): | |
125 return self.proxy.callRemote('INSERTKEY',layer,n) | |
126 def GETDOC(self): | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
127 doc = self.proxy.callRemote('GETDOC') |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
128 return doc |
288 | 129 def EXTENDSCENE(self,layer,n): |
130 return self.proxy.callRemote('EXTENDSCENE',layer,n) | |
131 def DELETESCENE(self,layer,n): | |
132 return self.proxy.callRemote('DELETESCENE',layer,n) | |
133 | |
134 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
|
135 try: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
136 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
|
137 pid = int(f.read()) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
138 f.close() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 f.close() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
143 except: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
144 traceback.print_exc() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
145 |
288 | 146 pid = os.fork() |
147 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
|
148 os.execvp("inkscape-mb",["inkscape-mb",sys.argv[1]]) |
288 | 149 s = Server() |
150 s.client = None | |
151 s.pid = pid | |
152 site = server.Site(s) | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
153 # 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
|
154 # 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
|
155 # remove the following wait in the future. |
288 | 156 reactor.listenTCP(19192,site) |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
157 time.sleep(5) |
288 | 158 reactor.run() |
159 | |
160 |