Mercurial > MadButterfly
annotate inkscape/firefox/helper_mb.py @ 358:50d33c3987ba
Add loader for project file.
author | wycc |
---|---|
date | Wed, 11 Mar 2009 07:52:30 +0800 |
parents | 3d03451be435 |
children | 29145d2affdb |
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() | |
358 | 113 def soap_GETPRJ(self,prj): |
114 try: | |
115 f = open(prj,"r") | |
116 l = f.read() | |
117 f.close() | |
118 return l | |
119 except: | |
120 traceback.print_exc() | |
121 | |
288 | 122 class Client(object): |
123 def __init__(self): | |
124 self.proxy = soap.Proxy('http://localhost:8080') | |
125 def PUBLISH(self): | |
126 return self.proxy.callRemote('PUBLISH') | |
127 def SCENE(self,n): | |
128 return self.proxy.callRemote('SCENE',n) | |
129 def INSERTKEY(self,layer,n): | |
130 return self.proxy.callRemote('INSERTKEY',layer,n) | |
131 def GETDOC(self): | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
132 doc = self.proxy.callRemote('GETDOC') |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
133 return doc |
288 | 134 def EXTENDSCENE(self,layer,n): |
135 return self.proxy.callRemote('EXTENDSCENE',layer,n) | |
136 def DELETESCENE(self,layer,n): | |
137 return self.proxy.callRemote('DELETESCENE',layer,n) | |
138 | |
139 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
|
140 try: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
141 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
|
142 pid = int(f.read()) |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
143 f.close() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 f.close() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
148 except: |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
149 traceback.print_exc() |
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
150 |
288 | 151 pid = os.fork() |
152 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
|
153 os.execvp("inkscape-mb",["inkscape-mb",sys.argv[1]]) |
288 | 154 s = Server() |
155 s.client = None | |
156 s.pid = pid | |
157 site = server.Site(s) | |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
158 # 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
|
159 # 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
|
160 # remove the following wait in the future. |
288 | 161 reactor.listenTCP(19192,site) |
339
63aaf96209cd
* Move location of files so that we can produce XPI file from them.
wycc
parents:
288
diff
changeset
|
162 time.sleep(5) |
288 | 163 reactor.run() |
164 | |
165 |