1 |
#!/usr/bin/env python |
#----------------------------------------------------------------------------- |
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$ |
9 |
|
# Copyright: (c) 2004 netfrag.org |
10 |
|
# Licence: GPL |
11 |
|
#----------------------------------------------------------------------------- |
12 |
|
|
13 |
|
#----------------------------------------------------------------------------- |
14 |
|
# $Log$ |
15 |
|
# Revision 1.7 2004/08/31 09:34:10 joko |
16 |
|
# + def query_remote: don't do "getTopicById" here anymore |
17 |
|
# |
18 |
|
# Revision 1.6 2004/08/31 02:23:07 joko |
19 |
|
# U changes to (dummy) topics metadata (FraggleXml) |
20 |
|
# + def query_remote: wrapper for making remote xmlrpc call |
21 |
|
# |
22 |
|
# Revision 1.5 2004/08/30 13:03:13 joko |
23 |
|
# - def getDefaultDir now in fraggleCtlPreferences |
24 |
|
# + def getTopicById |
25 |
|
# |
26 |
|
# Revision 1.4 2004/08/27 03:18:30 joko |
27 |
|
# new methods: fraggleSync, getTopics |
28 |
|
# |
29 |
|
# Revision 1.3 2004/08/26 15:25:04 joko |
30 |
|
# added cvs headers |
31 |
|
#----------------------------------------------------------------------------- |
32 |
|
|
33 |
import os |
import os |
34 |
from fraggleConstants import * |
from fraggleConstants import * |
35 |
|
import FraggleXMLRPC |
36 |
|
import fraggleCtlPreferences |
37 |
|
|
38 |
class FraggleEngine: |
class FraggleEngine: |
39 |
"""Back-end doing the work.""" |
"""Back-end doing the work.""" |
40 |
def __init__(self): |
def __init__(self): |
41 |
self.settings = {} |
self.settings = {} |
42 |
|
self.topics = {} |
43 |
def getDefaultDir(self): |
self.preferences = fraggleCtlPreferences.create(self) |
44 |
"""Gets location of default dir and creates it |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
|
if necessary. ($HOME/.pears/)""" |
|
|
try: |
|
|
import pearsdebug |
|
|
savedir = pearsdebug.savedir |
|
|
except: |
|
|
dir = '.netfraggle' |
|
|
savedir = os.path.expanduser(os.path.join('~', dir)) |
|
|
if len(savedir)<=len("c:\\/" + dir): |
|
|
# problem that might occur on Win2k (no $HOME environment variable) |
|
|
temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir) |
|
|
if temp > len("c:\\/" + dir): |
|
|
savedir = temp |
|
|
# create dir if it doesn't exist |
|
|
if not os.path.exists(savedir): |
|
|
os.makedirs(savedir) |
|
|
return savedir |
|
45 |
|
|
46 |
def setSetting(self, settingname, value): |
def setSetting(self, settingname, value): |
47 |
"""Sets settingname to value in self.settings.""" |
"""Sets settingname to value in self.settings.""" |
60 |
else: |
else: |
61 |
return None |
return None |
62 |
|
|
63 |
|
def fraggleSync(self): |
64 |
|
|
65 |
|
# v1 - demo |
66 |
|
self.topics = [ |
67 |
|
{ |
68 |
|
'name': 'iNFO-Page:Test-ViaXMLRPC', |
69 |
|
'mode': 'pull', |
70 |
|
'result': 'item', |
71 |
|
'target': { |
72 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
73 |
|
'method': 'nfo.getContent', |
74 |
|
'arguments': 'Test', |
75 |
|
'type': 'XMLRPC', |
76 |
|
} |
77 |
|
}, |
78 |
|
{ |
79 |
|
'name': 'iNFO-Page:Home-ViaXMLRPC', |
80 |
|
'mode': 'pull', |
81 |
|
'result': 'item', |
82 |
|
'target': { |
83 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
84 |
|
'method': 'nfo.getContent', |
85 |
|
'arguments': 'Home', |
86 |
|
'type': 'XMLRPC', |
87 |
|
} |
88 |
|
}, |
89 |
|
{ |
90 |
|
'name': 'iNFO-PageIndex', |
91 |
|
'mode': 'pull', |
92 |
|
'result': 'list', |
93 |
|
'target': { |
94 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
95 |
|
'method': 'nfo.listTopics', |
96 |
|
'arguments': ['xmlpage'], |
97 |
|
'type': 'XMLRPC', |
98 |
|
} |
99 |
|
}, |
100 |
|
{ |
101 |
|
'name': 'TWiki-Test-ViaTWiki', |
102 |
|
'mode': 'push', |
103 |
|
'target': { |
104 |
|
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
105 |
|
'type': 'TWiki', |
106 |
|
} |
107 |
|
}, |
108 |
|
{ |
109 |
|
'name': 'TWiki-Test-ViaXMLRPC', |
110 |
|
'mode': 'push', |
111 |
|
'target': { |
112 |
|
'method': 'appendToPage', |
113 |
|
'arguments': ['NetFraggleTest'], |
114 |
|
'type': 'XMLRPC', |
115 |
|
} |
116 |
|
}, |
117 |
|
] |
118 |
|
return |
119 |
|
|
120 |
|
# v2 - live |
121 |
|
|
122 |
|
# 1. load payload from remote side |
123 |
|
fragglexml = self.rpc.FraggleSync() |
124 |
|
|
125 |
|
# 2. (todo) unmarshal to self.topics (hash) |
126 |
|
# self.topics = unmarshal(fragglexml) |
127 |
|
|
128 |
|
def getTopics(self): |
129 |
|
return self.topics |
130 |
|
|
131 |
|
def getTopicById(self, id): |
132 |
|
return self.topics[id] |
133 |
|
|
134 |
|
def query_remote(self, topicmeta): |
135 |
|
|
136 |
|
if topicmeta['target']['type'] == 'XMLRPC': |
137 |
|
# TODO: make FraggleXMLRPC do all stuff |
138 |
|
# (call methods dynamically) |
139 |
|
from xmlrpclib import Server, Error |
140 |
|
rpc = Server(topicmeta['target']['url']) |
141 |
|
#try: |
142 |
|
if topicmeta['result'] == 'item': |
143 |
|
topicdata = {} |
144 |
|
try: |
145 |
|
#topicdata = rpc.getContent('Home') |
146 |
|
#topicdata = rpc.getContent(tuple(topicmeta['target']['arguments'])) |
147 |
|
topicdata = rpc.getContent(topicmeta['target']['arguments']) |
148 |
|
#print topicdata |
149 |
|
except Error, v: |
150 |
|
print "ERROR", v |
151 |
|
elif topicmeta['result'] == 'list': |
152 |
|
topicdata = [] |
153 |
|
try: |
154 |
|
arg = {'type': 'xmlpage'} |
155 |
|
topicdata = rpc.listTopics(arg) |
156 |
|
#print topicdata |
157 |
|
#self.styledTextContent.SetText(repr(topicdata)) |
158 |
|
except Error, v: |
159 |
|
print "ERROR", v |
160 |
|
return topicdata |
161 |
|
|
162 |
class urlOpener(object): |
class urlOpener(object): |
163 |
"""Opens urls.""" |
"""Opens urls.""" |
164 |
def __init__(self): |
def __init__(self): |