/[cvs]/nfo/projects/netfraggle/bin/fraggleEngine.py
ViewVC logotype

Annotation of /nfo/projects/netfraggle/bin/fraggleEngine.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Tue Aug 31 02:23:07 2004 UTC (20 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.5: +50 -5 lines
File MIME type: text/x-python
U changes to (dummy) topics metadata (FraggleXml)
+ def query_remote: wrapper for making remote xmlrpc call

1 joko 1.5 #-----------------------------------------------------------------------------
2     # Name: fraggleEngine.py
3     # Purpose: Does the main (non-gui) work
4     #
5     # Author: joko
6     #
7     # Created: 2004/30/08
8 joko 1.6 # RCS-ID: $Id: fraggleEngine.py,v 1.5 2004/08/30 13:03:13 joko Exp $
9 joko 1.5 # Copyright: (c) 2004 netfrag.org
10     # Licence: GPL
11     #-----------------------------------------------------------------------------
12 joko 1.2
13 joko 1.5 #-----------------------------------------------------------------------------
14 joko 1.4 # $Log: fraggleEngine.py,v $
15 joko 1.6 # Revision 1.5 2004/08/30 13:03:13 joko
16     # - def getDefaultDir now in fraggleCtlPreferences
17     # + def getTopicById
18     #
19 joko 1.5 # Revision 1.4 2004/08/27 03:18:30 joko
20     # new methods: fraggleSync, getTopics
21     #
22 joko 1.4 # Revision 1.3 2004/08/26 15:25:04 joko
23     # added cvs headers
24 joko 1.5 #-----------------------------------------------------------------------------
25 joko 1.3
26 joko 1.1 import os
27 joko 1.2 from fraggleConstants import *
28 joko 1.4 import FraggleXMLRPC
29 joko 1.5 import fraggleCtlPreferences
30 joko 1.1
31     class FraggleEngine:
32 joko 1.2 """Back-end doing the work."""
33     def __init__(self):
34     self.settings = {}
35 joko 1.4 self.topics = {}
36 joko 1.5 self.preferences = fraggleCtlPreferences.create(self)
37     self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig())
38 joko 1.2
39     def setSetting(self, settingname, value):
40     """Sets settingname to value in self.settings."""
41     self.settings[settingname] = value
42    
43     def getSetting(self, settingname, default=None):
44     """Returns settingname from self.settings. If not found
45     and default!=None, the default value is return *and*
46     saved to the settings."""
47     if self.settings.has_key(settingname):
48     return self.settings[settingname]
49     else:
50     if default!=None:
51     self.setSetting(settingname, default)
52     return default
53     else:
54     return None
55 joko 1.4
56 joko 1.5 def fraggleSync(self):
57 joko 1.4
58     # v1 - demo
59     self.topics = [
60     {
61 joko 1.6 'name': 'iNFO-Page:Test-ViaXMLRPC',
62 joko 1.5 'mode': 'pull',
63 joko 1.6 'result': 'item',
64 joko 1.5 'target': {
65     'url': 'http://netfrag.org/nfo/netfraggle.php',
66     'method': 'nfo.getContent',
67 joko 1.6 'arguments': 'Test',
68 joko 1.5 'type': 'XMLRPC',
69     }
70     },
71     {
72 joko 1.6 'name': 'iNFO-Page:Home-ViaXMLRPC',
73 joko 1.5 'mode': 'pull',
74 joko 1.6 'result': 'item',
75 joko 1.5 'target': {
76     'url': 'http://netfrag.org/nfo/netfraggle.php',
77     'method': 'nfo.getContent',
78 joko 1.6 'arguments': 'Home',
79     'type': 'XMLRPC',
80     }
81     },
82     {
83     'name': 'iNFO-PageIndex',
84     'mode': 'pull',
85     'result': 'list',
86     'target': {
87     'url': 'http://netfrag.org/nfo/netfraggle.php',
88     'method': 'nfo.listTopics',
89     'arguments': ['xmlpage'],
90 joko 1.5 'type': 'XMLRPC',
91     }
92     },
93     {
94     'name': 'TWiki-Test-ViaTWiki',
95 joko 1.4 'mode': 'push',
96     'target': {
97     'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest',
98     'type': 'TWiki',
99     }
100     },
101     {
102 joko 1.5 'name': 'TWiki-Test-ViaXMLRPC',
103 joko 1.4 'mode': 'push',
104     'target': {
105     'method': 'appendToPage',
106     'arguments': ['NetFraggleTest'],
107     'type': 'XMLRPC',
108     }
109     },
110     ]
111     return
112    
113     # v2 - live
114    
115     # 1. load payload from remote side
116 joko 1.5 fragglexml = self.rpc.FraggleSync()
117 joko 1.4
118     # 2. (todo) unmarshal to self.topics (hash)
119     # self.topics = unmarshal(fragglexml)
120    
121     def getTopics(self):
122     return self.topics
123 joko 1.5
124     def getTopicById(self, id):
125     return self.topics[id]
126 joko 1.2
127 joko 1.6 def query_remote(self, topicid):
128     topicmeta = self.getTopicById(topicid)
129 joko 1.2
130 joko 1.6 if topicmeta['target']['type'] == 'XMLRPC':
131     # TODO: make FraggleXMLRPC do all stuff
132     # (call methods dynamically)
133     from xmlrpclib import Server, Error
134     rpc = Server(topicmeta['target']['url'])
135     #try:
136     if topicmeta['result'] == 'item':
137     topicdata = {}
138     try:
139     #topicdata = rpc.getContent('Home')
140     #topicdata = rpc.getContent(tuple(topicmeta['target']['arguments']))
141     topicdata = rpc.getContent(topicmeta['target']['arguments'])
142     #print topicdata
143     except Error, v:
144     print "ERROR", v
145     elif topicmeta['result'] == 'list':
146     topicdata = []
147     try:
148     arg = {'type': 'xmlpage'}
149     topicdata = rpc.listTopics(arg)
150     #print topicdata
151     #self.styledTextContent.SetText(repr(topicdata))
152     except Error, v:
153     print "ERROR", v
154     return topicdata
155    
156 joko 1.2 class urlOpener(object):
157     """Opens urls."""
158     def __init__(self):
159     pass
160     def open(self, url="", command=None):
161     """Opens the url with the method defined in the settings.
162     If command==None, it is retreived from the settings.
163     """
164     if command==None:
165     command = FraggleEngine().getSetting(BROWSERCOMMAND, BROWSERDEFAULT)
166     if command==BROWSERDEFAULT.strip():
167     # use default opening method
168     import os
169     if os.environ.has_key("BROWSER") and \
170     os.environ["BROWSER"]=='kfmclient openProfile webbrowsing':
171     print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"]
172     os.environ["BROWSER"] = 'konqueror' # set it to konqueror
173     import webbrowser # MUST be imported only AFTER os.environ has been modified
174     webbrowser.open(url, 1)
175     #webbrowser.open_new(url)
176     else: #otherwise use user-defined command line
177     # replase %URL with actual url
178     command = command.replace("%URL", url)
179     import os
180     os.system(command)
181    

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed