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.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 |
|
# Revision 1.5 2004/08/30 13:03:13 joko |
20 |
|
# - def getDefaultDir now in fraggleCtlPreferences |
21 |
|
# + def getTopicById |
22 |
|
# |
23 |
|
# Revision 1.4 2004/08/27 03:18:30 joko |
24 |
|
# new methods: fraggleSync, getTopics |
25 |
|
# |
26 |
|
# Revision 1.3 2004/08/26 15:25:04 joko |
27 |
|
# added cvs headers |
28 |
|
#----------------------------------------------------------------------------- |
29 |
|
|
30 |
import os |
import os |
31 |
from fraggleConstants import * |
from fraggleConstants import * |
32 |
|
import FraggleXMLRPC |
33 |
|
import fraggleCtlPreferences |
34 |
|
|
35 |
class FraggleEngine: |
class FraggleEngine: |
36 |
"""Back-end doing the work.""" |
"""Back-end doing the work.""" |
37 |
def __init__(self): |
def __init__(self): |
38 |
self.settings = {} |
self.settings = {} |
39 |
|
self.topics = {} |
40 |
def getDefaultDir(self): |
self.preferences = fraggleCtlPreferences.create(self) |
41 |
"""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 |
|
42 |
|
|
43 |
def setSetting(self, settingname, value): |
def setSetting(self, settingname, value): |
44 |
"""Sets settingname to value in self.settings.""" |
"""Sets settingname to value in self.settings.""" |
57 |
else: |
else: |
58 |
return None |
return None |
59 |
|
|
60 |
|
def fraggleSync(self): |
61 |
|
|
62 |
|
# v1 - demo |
63 |
|
self.topics = [ |
64 |
|
{ |
65 |
|
'name': 'iNFO-Page:Test-ViaXMLRPC', |
66 |
|
'mode': 'pull', |
67 |
|
'result': 'item', |
68 |
|
'target': { |
69 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
70 |
|
'method': 'nfo.getContent', |
71 |
|
'arguments': 'Test', |
72 |
|
'type': 'XMLRPC', |
73 |
|
} |
74 |
|
}, |
75 |
|
{ |
76 |
|
'name': 'iNFO-Page:Home-ViaXMLRPC', |
77 |
|
'mode': 'pull', |
78 |
|
'result': 'item', |
79 |
|
'target': { |
80 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
81 |
|
'method': 'nfo.getContent', |
82 |
|
'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 |
|
'type': 'XMLRPC', |
95 |
|
} |
96 |
|
}, |
97 |
|
{ |
98 |
|
'name': 'TWiki-Test-ViaTWiki', |
99 |
|
'mode': 'push', |
100 |
|
'target': { |
101 |
|
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
102 |
|
'type': 'TWiki', |
103 |
|
} |
104 |
|
}, |
105 |
|
{ |
106 |
|
'name': 'TWiki-Test-ViaXMLRPC', |
107 |
|
'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 |
|
fragglexml = self.rpc.FraggleSync() |
121 |
|
|
122 |
|
# 2. (todo) unmarshal to self.topics (hash) |
123 |
|
# self.topics = unmarshal(fragglexml) |
124 |
|
|
125 |
|
def getTopics(self): |
126 |
|
return self.topics |
127 |
|
|
128 |
|
def getTopicById(self, id): |
129 |
|
return self.topics[id] |
130 |
|
|
131 |
|
def query_remote(self, topicid): |
132 |
|
topicmeta = self.getTopicById(topicid) |
133 |
|
|
134 |
|
if topicmeta['target']['type'] == 'XMLRPC': |
135 |
|
# TODO: make FraggleXMLRPC do all stuff |
136 |
|
# (call methods dynamically) |
137 |
|
from xmlrpclib import Server, Error |
138 |
|
rpc = Server(topicmeta['target']['url']) |
139 |
|
#try: |
140 |
|
if topicmeta['result'] == 'item': |
141 |
|
topicdata = {} |
142 |
|
try: |
143 |
|
#topicdata = rpc.getContent('Home') |
144 |
|
#topicdata = rpc.getContent(tuple(topicmeta['target']['arguments'])) |
145 |
|
topicdata = rpc.getContent(topicmeta['target']['arguments']) |
146 |
|
#print topicdata |
147 |
|
except Error, v: |
148 |
|
print "ERROR", v |
149 |
|
elif topicmeta['result'] == 'list': |
150 |
|
topicdata = [] |
151 |
|
try: |
152 |
|
arg = {'type': 'xmlpage'} |
153 |
|
topicdata = rpc.listTopics(arg) |
154 |
|
#print topicdata |
155 |
|
#self.styledTextContent.SetText(repr(topicdata)) |
156 |
|
except Error, v: |
157 |
|
print "ERROR", v |
158 |
|
return topicdata |
159 |
|
|
160 |
class urlOpener(object): |
class urlOpener(object): |
161 |
"""Opens urls.""" |
"""Opens urls.""" |
162 |
def __init__(self): |
def __init__(self): |