--- nfo/projects/netfraggle/bin/fraggleEngine.py 2004/08/25 18:19:31 1.1 +++ nfo/projects/netfraggle/bin/fraggleEngine.py 2004/08/27 03:18:30 1.4 @@ -1,6 +1,23 @@ +#!/usr/bin/env python + +# $Id: fraggleEngine.py,v 1.4 2004/08/27 03:18:30 joko Exp $ +# $Log: fraggleEngine.py,v $ +# Revision 1.4 2004/08/27 03:18:30 joko +# new methods: fraggleSync, getTopics +# +# Revision 1.3 2004/08/26 15:25:04 joko +# added cvs headers +# + import os +from fraggleConstants import * +import FraggleXMLRPC class FraggleEngine: + """Back-end doing the work.""" + def __init__(self): + self.settings = {} + self.topics = {} def getDefaultDir(self): """Gets location of default dir and creates it @@ -20,3 +37,84 @@ if not os.path.exists(savedir): os.makedirs(savedir) return savedir + + def setSetting(self, settingname, value): + """Sets settingname to value in self.settings.""" + self.settings[settingname] = value + + def getSetting(self, settingname, default=None): + """Returns settingname from self.settings. If not found + and default!=None, the default value is return *and* + saved to the settings.""" + if self.settings.has_key(settingname): + return self.settings[settingname] + else: + if default!=None: + self.setSetting(settingname, default) + return default + else: + return None + + def fraggleSync(self, config): + + # v1 - demo + self.topics = [ + { + 'name': 'TWiki-NetFraggleTest-ViaTWiki', + 'mode': 'push', + 'target': { + 'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', + 'type': 'TWiki', + } + }, + { + 'name': 'TWiki-NetFraggleTest-ViaXMLRPC', + 'mode': 'push', + 'target': { + 'method': 'appendToPage', + 'arguments': ['NetFraggleTest'], + 'type': 'XMLRPC', + } + }, + ] + return + + # v2 - live + + # 1. load payload from remote side + xml_rpc = FraggleXMLRPC.create(self, config) + fragglexml = xml_rpc.FraggleSync() + + # 2. (todo) unmarshal to self.topics (hash) + # self.topics = unmarshal(fragglexml) + + def getTopics(self): + return self.topics + + +class urlOpener(object): + """Opens urls.""" + def __init__(self): + pass + def open(self, url="", command=None): + """Opens the url with the method defined in the settings. + If command==None, it is retreived from the settings. + """ + if command==None: + command = FraggleEngine().getSetting(BROWSERCOMMAND, BROWSERDEFAULT) + if command==BROWSERDEFAULT.strip(): + # use default opening method + import os + if os.environ.has_key("BROWSER") and \ + os.environ["BROWSER"]=='kfmclient openProfile webbrowsing': + print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"] + os.environ["BROWSER"] = 'konqueror' # set it to konqueror + import webbrowser # MUST be imported only AFTER os.environ has been modified + webbrowser.open(url, 1) + #webbrowser.open_new(url) + else: #otherwise use user-defined command line + # replase %URL with actual url + command = command.replace("%URL", url) + import os + os.system(command) +