/[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.10 - (hide annotations)
Mon Sep 13 21:07:38 2004 UTC (20 years, 2 months ago) by xabbu
Branch: MAIN
Changes since 1.9: +23 -3 lines
File MIME type: text/x-python
+ function query added for testing of the nql / rpc interface

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 xabbu 1.10 # RCS-ID: $Id: fraggleEngine.py,v 1.9 2004/09/01 21:43:30 xabbu 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 xabbu 1.10 # Revision 1.9 2004/09/01 21:43:30 xabbu
16     # +Moved funtion getDefaultDir from FraggleCtlPreferences to FraggleEngine for more convenience
17     # +FraggleCtlModules class creation for handling content modules
18     #
19 xabbu 1.9 # Revision 1.8 2004/08/31 16:48:19 joko
20     # + def authenticate
21     #
22 joko 1.8 # Revision 1.7 2004/08/31 09:34:10 joko
23     # + def query_remote: don't do "getTopicById" here anymore
24     #
25 joko 1.7 # Revision 1.6 2004/08/31 02:23:07 joko
26     # U changes to (dummy) topics metadata (FraggleXml)
27     # + def query_remote: wrapper for making remote xmlrpc call
28     #
29 joko 1.6 # Revision 1.5 2004/08/30 13:03:13 joko
30     # - def getDefaultDir now in fraggleCtlPreferences
31     # + def getTopicById
32     #
33 joko 1.5 # Revision 1.4 2004/08/27 03:18:30 joko
34     # new methods: fraggleSync, getTopics
35     #
36 joko 1.4 # Revision 1.3 2004/08/26 15:25:04 joko
37     # added cvs headers
38 joko 1.5 #-----------------------------------------------------------------------------
39 joko 1.3
40 joko 1.1 import os
41 joko 1.2 from fraggleConstants import *
42 joko 1.4 import FraggleXMLRPC
43 joko 1.5 import fraggleCtlPreferences
44 xabbu 1.9 import FraggleCtlModules
45 xabbu 1.10 import fraggleParserXML
46 joko 1.1
47     class FraggleEngine:
48 joko 1.2 """Back-end doing the work."""
49     def __init__(self):
50     self.settings = {}
51 joko 1.4 self.topics = {}
52 xabbu 1.9 self.modules = FraggleCtlModules.create(self)
53 joko 1.5 self.preferences = fraggleCtlPreferences.create(self)
54     self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig())
55 joko 1.2
56     def setSetting(self, settingname, value):
57     """Sets settingname to value in self.settings."""
58     self.settings[settingname] = value
59    
60     def getSetting(self, settingname, default=None):
61     """Returns settingname from self.settings. If not found
62     and default!=None, the default value is return *and*
63     saved to the settings."""
64     if self.settings.has_key(settingname):
65     return self.settings[settingname]
66     else:
67     if default!=None:
68     self.setSetting(settingname, default)
69     return default
70     else:
71     return None
72 joko 1.4
73 joko 1.5 def fraggleSync(self):
74 xabbu 1.10 #self.queryCms()
75     fraggleParser = fraggleParserXML.create(self)
76 joko 1.4 # v1 - demo
77     self.topics = [
78     {
79 joko 1.6 'name': 'iNFO-Page:Test-ViaXMLRPC',
80 joko 1.5 'mode': 'pull',
81 joko 1.6 'result': 'item',
82 joko 1.5 'target': {
83     'url': 'http://netfrag.org/nfo/netfraggle.php',
84     'method': 'nfo.getContent',
85 joko 1.6 'arguments': 'Test',
86 joko 1.5 'type': 'XMLRPC',
87     }
88     },
89     {
90 joko 1.6 'name': 'iNFO-Page:Home-ViaXMLRPC',
91 joko 1.5 'mode': 'pull',
92 joko 1.6 'result': 'item',
93 joko 1.5 'target': {
94     'url': 'http://netfrag.org/nfo/netfraggle.php',
95     'method': 'nfo.getContent',
96 joko 1.6 'arguments': 'Home',
97     'type': 'XMLRPC',
98     }
99     },
100     {
101     'name': 'iNFO-PageIndex',
102     'mode': 'pull',
103     'result': 'list',
104     'target': {
105     'url': 'http://netfrag.org/nfo/netfraggle.php',
106     'method': 'nfo.listTopics',
107     'arguments': ['xmlpage'],
108 joko 1.5 'type': 'XMLRPC',
109     }
110     },
111     {
112     'name': 'TWiki-Test-ViaTWiki',
113 joko 1.4 'mode': 'push',
114     'target': {
115     'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest',
116     'type': 'TWiki',
117     }
118     },
119     {
120 joko 1.5 'name': 'TWiki-Test-ViaXMLRPC',
121 joko 1.4 'mode': 'push',
122     'target': {
123     'method': 'appendToPage',
124     'arguments': ['NetFraggleTest'],
125     'type': 'XMLRPC',
126     }
127     },
128     ]
129 xabbu 1.10 topicfile = os.path.join(self.getDefaultDir(), 'topic.xml')
130     fraggleParser.marshalXML(self.topics,topicfile)
131 joko 1.4 return
132    
133     # v2 - live
134    
135     # 1. load payload from remote side
136 joko 1.5 fragglexml = self.rpc.FraggleSync()
137 joko 1.4
138     # 2. (todo) unmarshal to self.topics (hash)
139     # self.topics = unmarshal(fragglexml)
140    
141     def getTopics(self):
142     return self.topics
143 joko 1.5
144     def getTopicById(self, id):
145     return self.topics[id]
146 xabbu 1.10
147     def listItems(self,topicId):
148     result = self.queryCms("GET creator_id, language_id, description FROM contents")
149     print result
150    
151     def queryCms(self,nqlquery):
152    
153     from xmlrpclib import Server,Error
154     rpc = Server('http://netfrag.org/nfo/netfraggle.php')
155     topicdata = rpc.query(nqlquery)
156     print topicdata
157     return topicdata
158    
159 joko 1.7 def query_remote(self, topicmeta):
160 joko 1.2
161 joko 1.6 if topicmeta['target']['type'] == 'XMLRPC':
162     # TODO: make FraggleXMLRPC do all stuff
163     # (call methods dynamically)
164     from xmlrpclib import Server, Error
165     rpc = Server(topicmeta['target']['url'])
166     #try:
167     if topicmeta['result'] == 'item':
168     topicdata = {}
169     try:
170     #topicdata = rpc.getContent('Home')
171     #topicdata = rpc.getContent(tuple(topicmeta['target']['arguments']))
172     topicdata = rpc.getContent(topicmeta['target']['arguments'])
173     #print topicdata
174     except Error, v:
175     print "ERROR", v
176     elif topicmeta['result'] == 'list':
177     topicdata = []
178     try:
179     arg = {'type': 'xmlpage'}
180     topicdata = rpc.listTopics(arg)
181     #print topicdata
182     #self.styledTextContent.SetText(repr(topicdata))
183     except Error, v:
184     print "ERROR", v
185     return topicdata
186 joko 1.8
187     def authenticate(self, server, username, password):
188     from xmlrpclib import Server, Error
189     rpc = Server(server)
190     try:
191     return rpc.authenticate({'user': username, 'pass': password})
192     except Error, v:
193     print "ERROR", v
194    
195 xabbu 1.9 def getDefaultDir(self):
196     """Gets location of default dir and creates it
197     if necessary. ($HOME/.pears/)"""
198     try:
199     import pearsdebug
200     savedir = pearsdebug.savedir
201     except:
202     dir = '.netfraggle'
203     savedir = os.path.expanduser(os.path.join('~', dir))
204     if len(savedir)<=len("c:\\/" + dir):
205     # problem that might occur on Win2k (no $HOME environment variable)
206     temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir)
207     if temp > len("c:\\/" + dir):
208     savedir = temp
209     # create dir if it doesn't exist
210     if not os.path.exists(savedir):
211     os.makedirs(savedir)
212     return savedir
213    
214 joko 1.2 class urlOpener(object):
215     """Opens urls."""
216     def __init__(self):
217     pass
218     def open(self, url="", command=None):
219     """Opens the url with the method defined in the settings.
220     If command==None, it is retreived from the settings.
221     """
222     if command==None:
223     command = FraggleEngine().getSetting(BROWSERCOMMAND, BROWSERDEFAULT)
224     if command==BROWSERDEFAULT.strip():
225     # use default opening method
226     import os
227     if os.environ.has_key("BROWSER") and \
228     os.environ["BROWSER"]=='kfmclient openProfile webbrowsing':
229     print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"]
230     os.environ["BROWSER"] = 'konqueror' # set it to konqueror
231     import webbrowser # MUST be imported only AFTER os.environ has been modified
232     webbrowser.open(url, 1)
233     #webbrowser.open_new(url)
234     else: #otherwise use user-defined command line
235     # replase %URL with actual url
236     command = command.replace("%URL", url)
237     import os
238     os.system(command)
239    

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