/[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.5 - (hide annotations)
Mon Aug 30 13:03:13 2004 UTC (20 years, 2 months ago) by joko
Branch: MAIN
Changes since 1.4: +46 -27 lines
File MIME type: text/x-python
- def getDefaultDir now in fraggleCtlPreferences
+ def getTopicById

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     # RCS-ID: $Id: fraggleEngine.py $
9     # 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.5 # Revision 1.4 2004/08/27 03:18:30 joko
16     # new methods: fraggleSync, getTopics
17     #
18 joko 1.4 # Revision 1.3 2004/08/26 15:25:04 joko
19     # added cvs headers
20 joko 1.5 #-----------------------------------------------------------------------------
21 joko 1.3
22 joko 1.1 import os
23 joko 1.2 from fraggleConstants import *
24 joko 1.4 import FraggleXMLRPC
25 joko 1.5 import fraggleCtlPreferences
26 joko 1.1
27     class FraggleEngine:
28 joko 1.2 """Back-end doing the work."""
29     def __init__(self):
30     self.settings = {}
31 joko 1.4 self.topics = {}
32 joko 1.5 self.preferences = fraggleCtlPreferences.create(self)
33     self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig())
34 joko 1.2
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 joko 1.4
52 joko 1.5 def fraggleSync(self):
53 joko 1.4
54     # v1 - demo
55     self.topics = [
56     {
57 joko 1.5 '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 joko 1.4 'mode': 'push',
79     'target': {
80     'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest',
81     'type': 'TWiki',
82     }
83     },
84     {
85 joko 1.5 'name': 'TWiki-Test-ViaXMLRPC',
86 joko 1.4 '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 joko 1.5 fragglexml = self.rpc.FraggleSync()
100 joko 1.4
101     # 2. (todo) unmarshal to self.topics (hash)
102     # self.topics = unmarshal(fragglexml)
103    
104     def getTopics(self):
105     return self.topics
106 joko 1.5
107     def getTopicById(self, id):
108     return self.topics[id]
109 joko 1.2
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    

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