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