12 |
|
|
13 |
#----------------------------------------------------------------------------- |
#----------------------------------------------------------------------------- |
14 |
# $Log$ |
# $Log$ |
15 |
|
# Revision 1.13 2004/09/21 18:07:09 xabbu |
16 |
|
# + added functions listItems and getContent |
17 |
|
# |
18 |
|
# Revision 1.12 2004/09/17 09:42:30 xabbu |
19 |
|
# U function listItems() places a query to the server now and returns its results |
20 |
|
# |
21 |
|
# Revision 1.11 2004/09/15 22:27:06 xabbu |
22 |
|
# +/- function fraggleSync replaced by function syncTopics which places a query |
23 |
|
# + function query has simple eval of error return code now |
24 |
|
# |
25 |
|
# Revision 1.10 2004/09/13 21:07:38 xabbu |
26 |
|
# + function query added for testing of the nql / rpc interface |
27 |
|
# |
28 |
|
# Revision 1.9 2004/09/01 21:43:30 xabbu |
29 |
|
# +Moved funtion getDefaultDir from FraggleCtlPreferences to FraggleEngine for more convenience |
30 |
|
# +FraggleCtlModules class creation for handling content modules |
31 |
|
# |
32 |
|
# Revision 1.8 2004/08/31 16:48:19 joko |
33 |
|
# + def authenticate |
34 |
|
# |
35 |
|
# Revision 1.7 2004/08/31 09:34:10 joko |
36 |
|
# + def query_remote: don't do "getTopicById" here anymore |
37 |
|
# |
38 |
# Revision 1.6 2004/08/31 02:23:07 joko |
# Revision 1.6 2004/08/31 02:23:07 joko |
39 |
# U changes to (dummy) topics metadata (FraggleXml) |
# U changes to (dummy) topics metadata (FraggleXml) |
40 |
# + def query_remote: wrapper for making remote xmlrpc call |
# + def query_remote: wrapper for making remote xmlrpc call |
54 |
from fraggleConstants import * |
from fraggleConstants import * |
55 |
import FraggleXMLRPC |
import FraggleXMLRPC |
56 |
import fraggleCtlPreferences |
import fraggleCtlPreferences |
57 |
|
import FraggleCtlModules |
58 |
|
import fraggleParserXML |
59 |
|
|
60 |
class FraggleEngine: |
class FraggleEngine: |
61 |
"""Back-end doing the work.""" |
"""Back-end doing the work.""" |
62 |
def __init__(self): |
def __init__(self): |
63 |
self.settings = {} |
self.settings = {} |
64 |
self.topics = {} |
self.topics = {} |
65 |
|
self.modules = FraggleCtlModules.create(self) |
66 |
self.preferences = fraggleCtlPreferences.create(self) |
self.preferences = fraggleCtlPreferences.create(self) |
67 |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
68 |
|
|
83 |
else: |
else: |
84 |
return None |
return None |
85 |
|
|
86 |
def fraggleSync(self): |
def syncTopics(self): |
87 |
|
query = "GET * FROM contenttypes" |
88 |
# v1 - demo |
topicData = self.queryCms(query) |
89 |
self.topics = [ |
topictypes = topicData['1'] |
90 |
{ |
|
91 |
'name': 'iNFO-Page:Test-ViaXMLRPC', |
for i in topictypes: |
92 |
'mode': 'pull', |
self.topics[i] = topictypes[i]['1'] |
93 |
'result': 'item', |
|
94 |
'target': { |
#print self.topics |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
|
|
'method': 'nfo.getContent', |
|
|
'arguments': 'Test', |
|
|
'type': 'XMLRPC', |
|
|
} |
|
|
}, |
|
|
{ |
|
|
'name': 'iNFO-Page:Home-ViaXMLRPC', |
|
|
'mode': 'pull', |
|
|
'result': 'item', |
|
|
'target': { |
|
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
|
|
'method': 'nfo.getContent', |
|
|
'arguments': 'Home', |
|
|
'type': 'XMLRPC', |
|
|
} |
|
|
}, |
|
|
{ |
|
|
'name': 'iNFO-PageIndex', |
|
|
'mode': 'pull', |
|
|
'result': 'list', |
|
|
'target': { |
|
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
|
|
'method': 'nfo.listTopics', |
|
|
'arguments': ['xmlpage'], |
|
|
'type': 'XMLRPC', |
|
|
} |
|
|
}, |
|
|
{ |
|
|
'name': 'TWiki-Test-ViaTWiki', |
|
|
'mode': 'push', |
|
|
'target': { |
|
|
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
|
|
'type': 'TWiki', |
|
|
} |
|
|
}, |
|
|
{ |
|
|
'name': 'TWiki-Test-ViaXMLRPC', |
|
|
'mode': 'push', |
|
|
'target': { |
|
|
'method': 'appendToPage', |
|
|
'arguments': ['NetFraggleTest'], |
|
|
'type': 'XMLRPC', |
|
|
} |
|
|
}, |
|
|
] |
|
|
return |
|
|
|
|
|
# v2 - live |
|
|
|
|
|
# 1. load payload from remote side |
|
|
fragglexml = self.rpc.FraggleSync() |
|
95 |
|
|
|
# 2. (todo) unmarshal to self.topics (hash) |
|
|
# self.topics = unmarshal(fragglexml) |
|
|
|
|
96 |
def getTopics(self): |
def getTopics(self): |
97 |
return self.topics |
return self.topics |
98 |
|
|
99 |
def getTopicById(self, id): |
def getTopicById(self, id): |
100 |
return self.topics[id] |
return self.topics[id] |
101 |
|
|
102 |
def query_remote(self, topicid): |
def listItems(self,contentkey): |
103 |
topicmeta = self.getTopicById(topicid) |
print contentkey |
104 |
|
result = self.queryCms(str("GET creator_id, language_id, description, id FROM contents WITH type "+contentkey)) |
105 |
|
return result |
106 |
|
|
107 |
|
def getContent(self,contentkey): |
108 |
|
query = str("GET content, creator_id, description, id FROM contents WITH id "+contentkey) |
109 |
|
result = self.queryCms(query) |
110 |
|
print query |
111 |
|
return result |
112 |
|
|
113 |
|
|
114 |
|
def queryCms(self,nqlquery): |
115 |
|
|
116 |
|
from xmlrpclib import Server,Error |
117 |
|
rpc = Server('http://netfrag.org/nfo/netfraggle.php') |
118 |
|
result = rpc.query(nqlquery) |
119 |
|
if result['0']['error'] == '0': |
120 |
|
#print result |
121 |
|
return result |
122 |
|
|
123 |
|
#else: |
124 |
|
#print result['0']['error'] |
125 |
|
#return result |
126 |
|
|
127 |
|
def query_remote(self, topicmeta): |
128 |
|
|
129 |
if topicmeta['target']['type'] == 'XMLRPC': |
if topicmeta['target']['type'] == 'XMLRPC': |
130 |
# TODO: make FraggleXMLRPC do all stuff |
# TODO: make FraggleXMLRPC do all stuff |
151 |
except Error, v: |
except Error, v: |
152 |
print "ERROR", v |
print "ERROR", v |
153 |
return topicdata |
return topicdata |
154 |
|
|
155 |
|
def authenticate(self, server, username, password): |
156 |
|
from xmlrpclib import Server, Error |
157 |
|
rpc = Server(server) |
158 |
|
try: |
159 |
|
return rpc.authenticate({'user': username, 'pass': password}) |
160 |
|
except Error, v: |
161 |
|
print "ERROR", v |
162 |
|
|
163 |
|
def getDefaultDir(self): |
164 |
|
"""Gets location of default dir and creates it |
165 |
|
if necessary. ($HOME/.pears/)""" |
166 |
|
try: |
167 |
|
import pearsdebug |
168 |
|
savedir = pearsdebug.savedir |
169 |
|
except: |
170 |
|
dir = '.netfraggle' |
171 |
|
savedir = os.path.expanduser(os.path.join('~', dir)) |
172 |
|
if len(savedir)<=len("c:\\/" + dir): |
173 |
|
# problem that might occur on Win2k (no $HOME environment variable) |
174 |
|
temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir) |
175 |
|
if temp > len("c:\\/" + dir): |
176 |
|
savedir = temp |
177 |
|
# create dir if it doesn't exist |
178 |
|
if not os.path.exists(savedir): |
179 |
|
os.makedirs(savedir) |
180 |
|
return savedir |
181 |
|
|
182 |
class urlOpener(object): |
class urlOpener(object): |
183 |
"""Opens urls.""" |
"""Opens urls.""" |
184 |
def __init__(self): |
def __init__(self): |