12 |
|
|
13 |
#----------------------------------------------------------------------------- |
#----------------------------------------------------------------------------- |
14 |
# $Log$ |
# $Log$ |
15 |
|
# Revision 1.10 2004/09/13 21:07:38 xabbu |
16 |
|
# + function query added for testing of the nql / rpc interface |
17 |
|
# |
18 |
|
# Revision 1.9 2004/09/01 21:43:30 xabbu |
19 |
|
# +Moved funtion getDefaultDir from FraggleCtlPreferences to FraggleEngine for more convenience |
20 |
|
# +FraggleCtlModules class creation for handling content modules |
21 |
|
# |
22 |
|
# Revision 1.8 2004/08/31 16:48:19 joko |
23 |
|
# + def authenticate |
24 |
|
# |
25 |
|
# Revision 1.7 2004/08/31 09:34:10 joko |
26 |
|
# + def query_remote: don't do "getTopicById" here anymore |
27 |
|
# |
28 |
|
# Revision 1.6 2004/08/31 02:23:07 joko |
29 |
|
# U changes to (dummy) topics metadata (FraggleXml) |
30 |
|
# + def query_remote: wrapper for making remote xmlrpc call |
31 |
|
# |
32 |
# Revision 1.5 2004/08/30 13:03:13 joko |
# Revision 1.5 2004/08/30 13:03:13 joko |
33 |
# - def getDefaultDir now in fraggleCtlPreferences |
# - def getDefaultDir now in fraggleCtlPreferences |
34 |
# + def getTopicById |
# + def getTopicById |
44 |
from fraggleConstants import * |
from fraggleConstants import * |
45 |
import FraggleXMLRPC |
import FraggleXMLRPC |
46 |
import fraggleCtlPreferences |
import fraggleCtlPreferences |
47 |
|
import FraggleCtlModules |
48 |
|
import fraggleParserXML |
49 |
|
|
50 |
class FraggleEngine: |
class FraggleEngine: |
51 |
"""Back-end doing the work.""" |
"""Back-end doing the work.""" |
52 |
def __init__(self): |
def __init__(self): |
53 |
self.settings = {} |
self.settings = {} |
54 |
self.topics = {} |
self.topics = {} |
55 |
|
self.modules = FraggleCtlModules.create(self) |
56 |
self.preferences = fraggleCtlPreferences.create(self) |
self.preferences = fraggleCtlPreferences.create(self) |
57 |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
58 |
|
|
74 |
return None |
return None |
75 |
|
|
76 |
def fraggleSync(self): |
def fraggleSync(self): |
77 |
|
#self.queryCms() |
78 |
|
fraggleParser = fraggleParserXML.create(self) |
79 |
# v1 - demo |
# v1 - demo |
80 |
self.topics = [ |
self.topics = [ |
81 |
{ |
{ |
82 |
'name': 'iNFO-Test-ViaXMLRPC', |
'name': 'iNFO-Page:Test-ViaXMLRPC', |
83 |
'mode': 'pull', |
'mode': 'pull', |
84 |
|
'result': 'item', |
85 |
'target': { |
'target': { |
86 |
'url': 'http://netfrag.org/nfo/netfraggle.php', |
'url': 'http://netfrag.org/nfo/netfraggle.php', |
87 |
'method': 'nfo.getContent', |
'method': 'nfo.getContent', |
88 |
'arguments': ['Test'], |
'arguments': 'Test', |
89 |
'type': 'XMLRPC', |
'type': 'XMLRPC', |
90 |
} |
} |
91 |
}, |
}, |
92 |
{ |
{ |
93 |
'name': 'iNFO-Home-ViaXMLRPC', |
'name': 'iNFO-Page:Home-ViaXMLRPC', |
94 |
'mode': 'pull', |
'mode': 'pull', |
95 |
|
'result': 'item', |
96 |
'target': { |
'target': { |
97 |
'url': 'http://netfrag.org/nfo/netfraggle.php', |
'url': 'http://netfrag.org/nfo/netfraggle.php', |
98 |
'method': 'nfo.getContent', |
'method': 'nfo.getContent', |
99 |
'arguments': ['Home'], |
'arguments': 'Home', |
100 |
|
'type': 'XMLRPC', |
101 |
|
} |
102 |
|
}, |
103 |
|
{ |
104 |
|
'name': 'iNFO-PageIndex', |
105 |
|
'mode': 'pull', |
106 |
|
'result': 'list', |
107 |
|
'target': { |
108 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
109 |
|
'method': 'nfo.listTopics', |
110 |
|
'arguments': ['xmlpage'], |
111 |
'type': 'XMLRPC', |
'type': 'XMLRPC', |
112 |
} |
} |
113 |
}, |
}, |
129 |
} |
} |
130 |
}, |
}, |
131 |
] |
] |
132 |
|
topicfile = os.path.join(self.getDefaultDir(), 'topic.xml') |
133 |
|
fraggleParser.marshalXML(self.topics,topicfile) |
134 |
return |
return |
135 |
|
|
136 |
# v2 - live |
# v2 - live |
146 |
|
|
147 |
def getTopicById(self, id): |
def getTopicById(self, id): |
148 |
return self.topics[id] |
return self.topics[id] |
149 |
|
|
150 |
|
def listItems(self,topicId): |
151 |
|
result = self.queryCms("GET creator_id, language_id, description FROM contents") |
152 |
|
print result |
153 |
|
|
154 |
|
def queryCms(self,nqlquery): |
155 |
|
|
156 |
|
from xmlrpclib import Server,Error |
157 |
|
rpc = Server('http://netfrag.org/nfo/netfraggle.php') |
158 |
|
topicdata = rpc.query(nqlquery) |
159 |
|
print topicdata |
160 |
|
return topicdata |
161 |
|
|
162 |
|
def query_remote(self, topicmeta): |
163 |
|
|
164 |
|
if topicmeta['target']['type'] == 'XMLRPC': |
165 |
|
# TODO: make FraggleXMLRPC do all stuff |
166 |
|
# (call methods dynamically) |
167 |
|
from xmlrpclib import Server, Error |
168 |
|
rpc = Server(topicmeta['target']['url']) |
169 |
|
#try: |
170 |
|
if topicmeta['result'] == 'item': |
171 |
|
topicdata = {} |
172 |
|
try: |
173 |
|
#topicdata = rpc.getContent('Home') |
174 |
|
#topicdata = rpc.getContent(tuple(topicmeta['target']['arguments'])) |
175 |
|
topicdata = rpc.getContent(topicmeta['target']['arguments']) |
176 |
|
#print topicdata |
177 |
|
except Error, v: |
178 |
|
print "ERROR", v |
179 |
|
elif topicmeta['result'] == 'list': |
180 |
|
topicdata = [] |
181 |
|
try: |
182 |
|
arg = {'type': 'xmlpage'} |
183 |
|
topicdata = rpc.listTopics(arg) |
184 |
|
#print topicdata |
185 |
|
#self.styledTextContent.SetText(repr(topicdata)) |
186 |
|
except Error, v: |
187 |
|
print "ERROR", v |
188 |
|
return topicdata |
189 |
|
|
190 |
|
def authenticate(self, server, username, password): |
191 |
|
from xmlrpclib import Server, Error |
192 |
|
rpc = Server(server) |
193 |
|
try: |
194 |
|
return rpc.authenticate({'user': username, 'pass': password}) |
195 |
|
except Error, v: |
196 |
|
print "ERROR", v |
197 |
|
|
198 |
|
def getDefaultDir(self): |
199 |
|
"""Gets location of default dir and creates it |
200 |
|
if necessary. ($HOME/.pears/)""" |
201 |
|
try: |
202 |
|
import pearsdebug |
203 |
|
savedir = pearsdebug.savedir |
204 |
|
except: |
205 |
|
dir = '.netfraggle' |
206 |
|
savedir = os.path.expanduser(os.path.join('~', dir)) |
207 |
|
if len(savedir)<=len("c:\\/" + dir): |
208 |
|
# problem that might occur on Win2k (no $HOME environment variable) |
209 |
|
temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir) |
210 |
|
if temp > len("c:\\/" + dir): |
211 |
|
savedir = temp |
212 |
|
# create dir if it doesn't exist |
213 |
|
if not os.path.exists(savedir): |
214 |
|
os.makedirs(savedir) |
215 |
|
return savedir |
216 |
|
|
217 |
class urlOpener(object): |
class urlOpener(object): |
218 |
"""Opens urls.""" |
"""Opens urls.""" |
219 |
def __init__(self): |
def __init__(self): |