12 |
|
|
13 |
#----------------------------------------------------------------------------- |
#----------------------------------------------------------------------------- |
14 |
# $Log$ |
# $Log$ |
15 |
|
# Revision 1.12 2004/09/17 09:42:30 xabbu |
16 |
|
# U function listItems() places a query to the server now and returns its results |
17 |
|
# |
18 |
|
# Revision 1.11 2004/09/15 22:27:06 xabbu |
19 |
|
# +/- function fraggleSync replaced by function syncTopics which places a query |
20 |
|
# + function query has simple eval of error return code now |
21 |
|
# |
22 |
|
# Revision 1.10 2004/09/13 21:07:38 xabbu |
23 |
|
# + function query added for testing of the nql / rpc interface |
24 |
|
# |
25 |
|
# Revision 1.9 2004/09/01 21:43:30 xabbu |
26 |
|
# +Moved funtion getDefaultDir from FraggleCtlPreferences to FraggleEngine for more convenience |
27 |
|
# +FraggleCtlModules class creation for handling content modules |
28 |
|
# |
29 |
# Revision 1.8 2004/08/31 16:48:19 joko |
# Revision 1.8 2004/08/31 16:48:19 joko |
30 |
# + def authenticate |
# + def authenticate |
31 |
# |
# |
51 |
from fraggleConstants import * |
from fraggleConstants import * |
52 |
import FraggleXMLRPC |
import FraggleXMLRPC |
53 |
import fraggleCtlPreferences |
import fraggleCtlPreferences |
54 |
|
import FraggleCtlModules |
55 |
|
import fraggleParserXML |
56 |
|
|
57 |
class FraggleEngine: |
class FraggleEngine: |
58 |
"""Back-end doing the work.""" |
"""Back-end doing the work.""" |
59 |
def __init__(self): |
def __init__(self): |
60 |
self.settings = {} |
self.settings = {} |
61 |
self.topics = {} |
self.topics = {} |
62 |
|
self.modules = FraggleCtlModules.create(self) |
63 |
self.preferences = fraggleCtlPreferences.create(self) |
self.preferences = fraggleCtlPreferences.create(self) |
64 |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
65 |
|
|
80 |
else: |
else: |
81 |
return None |
return None |
82 |
|
|
83 |
def fraggleSync(self): |
def syncTopics(self): |
84 |
|
query = "GET * FROM contenttypes" |
85 |
# v1 - demo |
topicData = self.queryCms(query) |
86 |
self.topics = [ |
topictypes = topicData['1'] |
87 |
{ |
|
88 |
'name': 'iNFO-Page:Test-ViaXMLRPC', |
for i in topictypes: |
89 |
'mode': 'pull', |
self.topics[i] = topictypes[i]['1'] |
90 |
'result': 'item', |
|
91 |
'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() |
|
92 |
|
|
|
# 2. (todo) unmarshal to self.topics (hash) |
|
|
# self.topics = unmarshal(fragglexml) |
|
|
|
|
93 |
def getTopics(self): |
def getTopics(self): |
94 |
return self.topics |
return self.topics |
95 |
|
|
96 |
def getTopicById(self, id): |
def getTopicById(self, id): |
97 |
return self.topics[id] |
return self.topics[id] |
98 |
|
|
99 |
|
def listItems(self,contentkey): |
100 |
|
result = self.queryCms(str("GET creator_id, language_id, description FROM contents WITH type "+contentkey)) |
101 |
|
return result |
102 |
|
|
103 |
|
def queryCms(self,nqlquery): |
104 |
|
|
105 |
|
from xmlrpclib import Server,Error |
106 |
|
rpc = Server('http://netfrag.org/nfo/netfraggle.php') |
107 |
|
result = rpc.query(nqlquery) |
108 |
|
if result['0']['error'] == '0': |
109 |
|
#print result |
110 |
|
return result |
111 |
|
|
112 |
|
#else: |
113 |
|
#print result['0']['error'] |
114 |
|
#return result |
115 |
|
|
116 |
def query_remote(self, topicmeta): |
def query_remote(self, topicmeta): |
117 |
|
|
118 |
if topicmeta['target']['type'] == 'XMLRPC': |
if topicmeta['target']['type'] == 'XMLRPC': |
149 |
except Error, v: |
except Error, v: |
150 |
print "ERROR", v |
print "ERROR", v |
151 |
|
|
152 |
|
def getDefaultDir(self): |
153 |
|
"""Gets location of default dir and creates it |
154 |
|
if necessary. ($HOME/.pears/)""" |
155 |
|
try: |
156 |
|
import pearsdebug |
157 |
|
savedir = pearsdebug.savedir |
158 |
|
except: |
159 |
|
dir = '.netfraggle' |
160 |
|
savedir = os.path.expanduser(os.path.join('~', dir)) |
161 |
|
if len(savedir)<=len("c:\\/" + dir): |
162 |
|
# problem that might occur on Win2k (no $HOME environment variable) |
163 |
|
temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir) |
164 |
|
if temp > len("c:\\/" + dir): |
165 |
|
savedir = temp |
166 |
|
# create dir if it doesn't exist |
167 |
|
if not os.path.exists(savedir): |
168 |
|
os.makedirs(savedir) |
169 |
|
return savedir |
170 |
|
|
171 |
class urlOpener(object): |
class urlOpener(object): |
172 |
"""Opens urls.""" |
"""Opens urls.""" |
173 |
def __init__(self): |
def __init__(self): |