/[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.9 - (hide annotations)
Wed Sep 1 21:43:30 2004 UTC (20 years, 2 months ago) by xabbu
Branch: MAIN
Changes since 1.8: +25 -2 lines
File MIME type: text/x-python
+Moved funtion getDefaultDir from FraggleCtlPreferences to FraggleEngine for more convenience
+FraggleCtlModules class creation for handling content modules

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

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