1 |
|
#!/usr/bin/env python |
2 |
|
|
3 |
|
# $Id$ |
4 |
|
# $Log$ |
5 |
|
# Revision 1.4 2004/08/27 03:18:30 joko |
6 |
|
# new methods: fraggleSync, getTopics |
7 |
|
# |
8 |
|
# Revision 1.3 2004/08/26 15:25:04 joko |
9 |
|
# added cvs headers |
10 |
|
# |
11 |
|
|
12 |
import os |
import os |
13 |
|
from fraggleConstants import * |
14 |
|
import FraggleXMLRPC |
15 |
|
|
16 |
class FraggleEngine: |
class FraggleEngine: |
17 |
|
"""Back-end doing the work.""" |
18 |
|
def __init__(self): |
19 |
|
self.settings = {} |
20 |
|
self.topics = {} |
21 |
|
|
22 |
def getDefaultDir(self): |
def getDefaultDir(self): |
23 |
"""Gets location of default dir and creates it |
"""Gets location of default dir and creates it |
37 |
if not os.path.exists(savedir): |
if not os.path.exists(savedir): |
38 |
os.makedirs(savedir) |
os.makedirs(savedir) |
39 |
return savedir |
return savedir |
40 |
|
|
41 |
|
def setSetting(self, settingname, value): |
42 |
|
"""Sets settingname to value in self.settings.""" |
43 |
|
self.settings[settingname] = value |
44 |
|
|
45 |
|
def getSetting(self, settingname, default=None): |
46 |
|
"""Returns settingname from self.settings. If not found |
47 |
|
and default!=None, the default value is return *and* |
48 |
|
saved to the settings.""" |
49 |
|
if self.settings.has_key(settingname): |
50 |
|
return self.settings[settingname] |
51 |
|
else: |
52 |
|
if default!=None: |
53 |
|
self.setSetting(settingname, default) |
54 |
|
return default |
55 |
|
else: |
56 |
|
return None |
57 |
|
|
58 |
|
def fraggleSync(self, config): |
59 |
|
|
60 |
|
# v1 - demo |
61 |
|
self.topics = [ |
62 |
|
{ |
63 |
|
'name': 'TWiki-NetFraggleTest-ViaTWiki', |
64 |
|
'mode': 'push', |
65 |
|
'target': { |
66 |
|
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
67 |
|
'type': 'TWiki', |
68 |
|
} |
69 |
|
}, |
70 |
|
{ |
71 |
|
'name': 'TWiki-NetFraggleTest-ViaXMLRPC', |
72 |
|
'mode': 'push', |
73 |
|
'target': { |
74 |
|
'method': 'appendToPage', |
75 |
|
'arguments': ['NetFraggleTest'], |
76 |
|
'type': 'XMLRPC', |
77 |
|
} |
78 |
|
}, |
79 |
|
] |
80 |
|
return |
81 |
|
|
82 |
|
# v2 - live |
83 |
|
|
84 |
|
# 1. load payload from remote side |
85 |
|
xml_rpc = FraggleXMLRPC.create(self, config) |
86 |
|
fragglexml = xml_rpc.FraggleSync() |
87 |
|
|
88 |
|
# 2. (todo) unmarshal to self.topics (hash) |
89 |
|
# self.topics = unmarshal(fragglexml) |
90 |
|
|
91 |
|
def getTopics(self): |
92 |
|
return self.topics |
93 |
|
|
94 |
|
|
95 |
|
class urlOpener(object): |
96 |
|
"""Opens urls.""" |
97 |
|
def __init__(self): |
98 |
|
pass |
99 |
|
def open(self, url="", command=None): |
100 |
|
"""Opens the url with the method defined in the settings. |
101 |
|
If command==None, it is retreived from the settings. |
102 |
|
""" |
103 |
|
if command==None: |
104 |
|
command = FraggleEngine().getSetting(BROWSERCOMMAND, BROWSERDEFAULT) |
105 |
|
if command==BROWSERDEFAULT.strip(): |
106 |
|
# use default opening method |
107 |
|
import os |
108 |
|
if os.environ.has_key("BROWSER") and \ |
109 |
|
os.environ["BROWSER"]=='kfmclient openProfile webbrowsing': |
110 |
|
print "Invalid browser detected : %s\nResetting to konqueror." % os.environ["BROWSER"] |
111 |
|
os.environ["BROWSER"] = 'konqueror' # set it to konqueror |
112 |
|
import webbrowser # MUST be imported only AFTER os.environ has been modified |
113 |
|
webbrowser.open(url, 1) |
114 |
|
#webbrowser.open_new(url) |
115 |
|
else: #otherwise use user-defined command line |
116 |
|
# replase %URL with actual url |
117 |
|
command = command.replace("%URL", url) |
118 |
|
import os |
119 |
|
os.system(command) |
120 |
|
|