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