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
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
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
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):
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
75 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
76 d.callback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
79 print [result]
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
80 d.errback(result)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
81 def soap_START(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
82 if self.client == None:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
83 os.kill(self.pid,12)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
84 time.sleep(1)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
85 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
97 def soap_GETDOC(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
98 try:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
99 print "xxxxx"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
104 self.client = Client()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
109 print "yyy"
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
110 return d
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
111 except:
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
112 traceback.print_exc()
358
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
113 def soap_GETPRJ(self,prj):
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
114 try:
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
115 f = open(prj,"r")
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
116 l = f.read()
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
117 f.close()
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
118 return l
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
119 except:
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
120 traceback.print_exc()
50d33c3987ba Add loader for project file.
wycc
parents: 353
diff changeset
121
288
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
122 class Client(object):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
123 def __init__(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
124 self.proxy = soap.Proxy('http://localhost:8080')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
125 def PUBLISH(self):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
126 return self.proxy.callRemote('PUBLISH')
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
127 def SCENE(self,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
128 return self.proxy.callRemote('SCENE',n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
129 def INSERTKEY(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
130 return self.proxy.callRemote('INSERTKEY',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
134 def EXTENDSCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
135 return self.proxy.callRemote('EXTENDSCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
136 def DELETESCENE(self,layer,n):
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
137 return self.proxy.callRemote('DELETESCENE',layer,n)
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
138
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
151 pid = os.fork()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
154 s = Server()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
155 s.client = None
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
156 s.pid = pid
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
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
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
163 reactor.run()
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
164
d5327265da1e Revert the firefox integration to 276
wycc
parents:
diff changeset
165