1 |
#----------------------------------------------------------------------------- |
2 |
# Name: fraggleEngine.py |
3 |
# Purpose: Does the main (non-gui) work |
4 |
# |
5 |
# Author: joko |
6 |
# |
7 |
# Created: 2004/30/08 |
8 |
# RCS-ID: $Id: fraggleEngine.py $ |
9 |
# Copyright: (c) 2004 netfrag.org |
10 |
# Licence: GPL |
11 |
#----------------------------------------------------------------------------- |
12 |
|
13 |
#----------------------------------------------------------------------------- |
14 |
# $Log: fraggleEngine.py,v $ |
15 |
# Revision 1.4 2004/08/27 03:18:30 joko |
16 |
# new methods: fraggleSync, getTopics |
17 |
# |
18 |
# Revision 1.3 2004/08/26 15:25:04 joko |
19 |
# added cvs headers |
20 |
#----------------------------------------------------------------------------- |
21 |
|
22 |
import os |
23 |
from fraggleConstants import * |
24 |
import FraggleXMLRPC |
25 |
import fraggleCtlPreferences |
26 |
|
27 |
class FraggleEngine: |
28 |
"""Back-end doing the work.""" |
29 |
def __init__(self): |
30 |
self.settings = {} |
31 |
self.topics = {} |
32 |
self.preferences = fraggleCtlPreferences.create(self) |
33 |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
34 |
|
35 |
def setSetting(self, settingname, value): |
36 |
"""Sets settingname to value in self.settings.""" |
37 |
self.settings[settingname] = value |
38 |
|
39 |
def getSetting(self, settingname, default=None): |
40 |
"""Returns settingname from self.settings. If not found |
41 |
and default!=None, the default value is return *and* |
42 |
saved to the settings.""" |
43 |
if self.settings.has_key(settingname): |
44 |
return self.settings[settingname] |
45 |
else: |
46 |
if default!=None: |
47 |
self.setSetting(settingname, default) |
48 |
return default |
49 |
else: |
50 |
return None |
51 |
|
52 |
def fraggleSync(self): |
53 |
|
54 |
# v1 - demo |
55 |
self.topics = [ |
56 |
{ |
57 |
'name': 'iNFO-Test-ViaXMLRPC', |
58 |
'mode': 'pull', |
59 |
'target': { |
60 |
'url': 'http://netfrag.org/nfo/netfraggle.php', |
61 |
'method': 'nfo.getContent', |
62 |
'arguments': ['Test'], |
63 |
'type': 'XMLRPC', |
64 |
} |
65 |
}, |
66 |
{ |
67 |
'name': 'iNFO-Home-ViaXMLRPC', |
68 |
'mode': 'pull', |
69 |
'target': { |
70 |
'url': 'http://netfrag.org/nfo/netfraggle.php', |
71 |
'method': 'nfo.getContent', |
72 |
'arguments': ['Home'], |
73 |
'type': 'XMLRPC', |
74 |
} |
75 |
}, |
76 |
{ |
77 |
'name': 'TWiki-Test-ViaTWiki', |
78 |
'mode': 'push', |
79 |
'target': { |
80 |
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
81 |
'type': 'TWiki', |
82 |
} |
83 |
}, |
84 |
{ |
85 |
'name': 'TWiki-Test-ViaXMLRPC', |
86 |
'mode': 'push', |
87 |
'target': { |
88 |
'method': 'appendToPage', |
89 |
'arguments': ['NetFraggleTest'], |
90 |
'type': 'XMLRPC', |
91 |
} |
92 |
}, |
93 |
] |
94 |
return |
95 |
|
96 |
# v2 - live |
97 |
|
98 |
# 1. load payload from remote side |
99 |
fragglexml = self.rpc.FraggleSync() |
100 |
|
101 |
# 2. (todo) unmarshal to self.topics (hash) |
102 |
# self.topics = unmarshal(fragglexml) |
103 |
|
104 |
def getTopics(self): |
105 |
return self.topics |
106 |
|
107 |
def getTopicById(self, id): |
108 |
return self.topics[id] |
109 |
|
110 |
|
111 |
class urlOpener(object): |
112 |
"""Opens urls.""" |
113 |
def __init__(self): |
114 |
pass |
115 |
def open(self, url="", command=None): |
116 |
"""Opens the url with the method defined in the settings. |
117 |
If command==None, it is retreived from the settings. |
118 |
""" |
119 |
if command==None: |
120 |
command = FraggleEngine().getSetting(BROWSERCOMMAND, BROWSERDEFAULT) |
121 |
if command==BROWSERDEFAULT.strip(): |
122 |
# use default opening method |
123 |
import os |
124 |
if os.environ.has_key("BROWSER") and \ |
125 |
os.environ["BROWSER"]=='kfmclient openProfile webbrowsing': |
126 |
print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"] |
127 |
os.environ["BROWSER"] = 'konqueror' # set it to konqueror |
128 |
import webbrowser # MUST be imported only AFTER os.environ has been modified |
129 |
webbrowser.open(url, 1) |
130 |
#webbrowser.open_new(url) |
131 |
else: #otherwise use user-defined command line |
132 |
# replase %URL with actual url |
133 |
command = command.replace("%URL", url) |
134 |
import os |
135 |
os.system(command) |
136 |
|