--- nfo/projects/netfraggle/bin/fraggleEngine.py 2004/08/30 13:03:13 1.5 +++ nfo/projects/netfraggle/bin/fraggleEngine.py 2004/09/13 21:07:38 1.10 @@ -5,13 +5,30 @@ # Author: joko # # Created: 2004/30/08 -# RCS-ID: $Id: fraggleEngine.py,v 1.5 2004/08/30 13:03:13 joko Exp $ +# RCS-ID: $Id: fraggleEngine.py,v 1.10 2004/09/13 21:07:38 xabbu Exp $ # Copyright: (c) 2004 netfrag.org # Licence: GPL #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # $Log: fraggleEngine.py,v $ +# Revision 1.10 2004/09/13 21:07:38 xabbu +# + function query added for testing of the nql / rpc interface +# +# Revision 1.9 2004/09/01 21:43:30 xabbu +# +Moved funtion getDefaultDir from FraggleCtlPreferences to FraggleEngine for more convenience +# +FraggleCtlModules class creation for handling content modules +# +# Revision 1.8 2004/08/31 16:48:19 joko +# + def authenticate +# +# Revision 1.7 2004/08/31 09:34:10 joko +# + def query_remote: don't do "getTopicById" here anymore +# +# Revision 1.6 2004/08/31 02:23:07 joko +# U changes to (dummy) topics metadata (FraggleXml) +# + def query_remote: wrapper for making remote xmlrpc call +# # Revision 1.5 2004/08/30 13:03:13 joko # - def getDefaultDir now in fraggleCtlPreferences # + def getTopicById @@ -27,12 +44,15 @@ from fraggleConstants import * import FraggleXMLRPC import fraggleCtlPreferences +import FraggleCtlModules +import fraggleParserXML class FraggleEngine: """Back-end doing the work.""" def __init__(self): self.settings = {} self.topics = {} + self.modules = FraggleCtlModules.create(self) self.preferences = fraggleCtlPreferences.create(self) self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) @@ -54,26 +74,40 @@ return None def fraggleSync(self): - + #self.queryCms() + fraggleParser = fraggleParserXML.create(self) # v1 - demo self.topics = [ { - 'name': 'iNFO-Test-ViaXMLRPC', + 'name': 'iNFO-Page:Test-ViaXMLRPC', 'mode': 'pull', + 'result': 'item', 'target': { 'url': 'http://netfrag.org/nfo/netfraggle.php', 'method': 'nfo.getContent', - 'arguments': ['Test'], + 'arguments': 'Test', 'type': 'XMLRPC', } }, { - 'name': 'iNFO-Home-ViaXMLRPC', + 'name': 'iNFO-Page:Home-ViaXMLRPC', 'mode': 'pull', + 'result': 'item', 'target': { 'url': 'http://netfrag.org/nfo/netfraggle.php', 'method': 'nfo.getContent', - 'arguments': ['Home'], + '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', } }, @@ -95,6 +129,8 @@ } }, ] + topicfile = os.path.join(self.getDefaultDir(), 'topic.xml') + fraggleParser.marshalXML(self.topics,topicfile) return # v2 - live @@ -110,8 +146,74 @@ def getTopicById(self, id): return self.topics[id] + + def listItems(self,topicId): + result = self.queryCms("GET creator_id, language_id, description FROM contents") + print result + + def queryCms(self,nqlquery): + + from xmlrpclib import Server,Error + rpc = Server('http://netfrag.org/nfo/netfraggle.php') + topicdata = rpc.query(nqlquery) + print topicdata + return topicdata + + def query_remote(self, topicmeta): - + if topicmeta['target']['type'] == 'XMLRPC': + # TODO: make FraggleXMLRPC do all stuff + # (call methods dynamically) + from xmlrpclib import Server, Error + rpc = Server(topicmeta['target']['url']) + #try: + if topicmeta['result'] == 'item': + topicdata = {} + try: + #topicdata = rpc.getContent('Home') + #topicdata = rpc.getContent(tuple(topicmeta['target']['arguments'])) + topicdata = rpc.getContent(topicmeta['target']['arguments']) + #print topicdata + except Error, v: + print "ERROR", v + elif topicmeta['result'] == 'list': + topicdata = [] + try: + arg = {'type': 'xmlpage'} + topicdata = rpc.listTopics(arg) + #print topicdata + #self.styledTextContent.SetText(repr(topicdata)) + except Error, v: + print "ERROR", v + return topicdata + + def authenticate(self, server, username, password): + from xmlrpclib import Server, Error + rpc = Server(server) + try: + return rpc.authenticate({'user': username, 'pass': password}) + except Error, v: + print "ERROR", v + + def getDefaultDir(self): + """Gets location of default dir and creates it + if necessary. ($HOME/.pears/)""" + try: + import pearsdebug + savedir = pearsdebug.savedir + except: + dir = '.netfraggle' + savedir = os.path.expanduser(os.path.join('~', dir)) + if len(savedir)<=len("c:\\/" + dir): + # problem that might occur on Win2k (no $HOME environment variable) + temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir) + if temp > len("c:\\/" + dir): + savedir = temp + # create dir if it doesn't exist + if not os.path.exists(savedir): + os.makedirs(savedir) + return savedir + class urlOpener(object): """Opens urls.""" def __init__(self):