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 |
# Revision 1.6 2004/08/31 02:23:07 joko |
29 |
# U changes to (dummy) topics metadata (FraggleXml) |
# U changes to (dummy) topics metadata (FraggleXml) |
30 |
# + def query_remote: wrapper for making remote xmlrpc call |
# + def query_remote: wrapper for making remote xmlrpc call |
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 |
{ |
{ |
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 query_remote(self, topicid): |
def listItems(self,topicId): |
151 |
topicmeta = self.getTopicById(topicid) |
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': |
if topicmeta['target']['type'] == 'XMLRPC': |
165 |
# TODO: make FraggleXMLRPC do all stuff |
# TODO: make FraggleXMLRPC do all stuff |
186 |
except Error, v: |
except Error, v: |
187 |
print "ERROR", v |
print "ERROR", v |
188 |
return topicdata |
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): |