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 |
# $Id$ |
#----------------------------------------------------------------------------- |
14 |
# $Log$ |
# $Log$ |
15 |
|
# Revision 1.5 2004/08/30 13:03:13 joko |
16 |
|
# - def getDefaultDir now in fraggleCtlPreferences |
17 |
|
# + def getTopicById |
18 |
|
# |
19 |
# Revision 1.4 2004/08/27 03:18:30 joko |
# Revision 1.4 2004/08/27 03:18:30 joko |
20 |
# new methods: fraggleSync, getTopics |
# new methods: fraggleSync, getTopics |
21 |
# |
# |
22 |
# Revision 1.3 2004/08/26 15:25:04 joko |
# Revision 1.3 2004/08/26 15:25:04 joko |
23 |
# added cvs headers |
# added cvs headers |
24 |
# |
#----------------------------------------------------------------------------- |
25 |
|
|
26 |
import os |
import os |
27 |
from fraggleConstants import * |
from fraggleConstants import * |
28 |
import FraggleXMLRPC |
import FraggleXMLRPC |
29 |
|
import fraggleCtlPreferences |
30 |
|
|
31 |
class FraggleEngine: |
class FraggleEngine: |
32 |
"""Back-end doing the work.""" |
"""Back-end doing the work.""" |
33 |
def __init__(self): |
def __init__(self): |
34 |
self.settings = {} |
self.settings = {} |
35 |
self.topics = {} |
self.topics = {} |
36 |
|
self.preferences = fraggleCtlPreferences.create(self) |
37 |
def getDefaultDir(self): |
self.rpc = FraggleXMLRPC.create(self, self.preferences.getConfig()) |
|
"""Gets location of default dir and creates it |
|
|
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 |
|
38 |
|
|
39 |
def setSetting(self, settingname, value): |
def setSetting(self, settingname, value): |
40 |
"""Sets settingname to value in self.settings.""" |
"""Sets settingname to value in self.settings.""" |
53 |
else: |
else: |
54 |
return None |
return None |
55 |
|
|
56 |
def fraggleSync(self, config): |
def fraggleSync(self): |
57 |
|
|
58 |
# v1 - demo |
# v1 - demo |
59 |
self.topics = [ |
self.topics = [ |
60 |
{ |
{ |
61 |
'name': 'TWiki-NetFraggleTest-ViaTWiki', |
'name': 'iNFO-Test-ViaXMLRPC', |
62 |
|
'mode': 'pull', |
63 |
|
'target': { |
64 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
65 |
|
'method': 'nfo.getContent', |
66 |
|
'arguments': ['Test'], |
67 |
|
'type': 'XMLRPC', |
68 |
|
} |
69 |
|
}, |
70 |
|
{ |
71 |
|
'name': 'iNFO-Home-ViaXMLRPC', |
72 |
|
'mode': 'pull', |
73 |
|
'target': { |
74 |
|
'url': 'http://netfrag.org/nfo/netfraggle.php', |
75 |
|
'method': 'nfo.getContent', |
76 |
|
'arguments': ['Home'], |
77 |
|
'type': 'XMLRPC', |
78 |
|
} |
79 |
|
}, |
80 |
|
{ |
81 |
|
'name': 'TWiki-Test-ViaTWiki', |
82 |
'mode': 'push', |
'mode': 'push', |
83 |
'target': { |
'target': { |
84 |
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
'url': 'http://netfrag.org/twiki/bin/view/Main/NetFraggleTest', |
86 |
} |
} |
87 |
}, |
}, |
88 |
{ |
{ |
89 |
'name': 'TWiki-NetFraggleTest-ViaXMLRPC', |
'name': 'TWiki-Test-ViaXMLRPC', |
90 |
'mode': 'push', |
'mode': 'push', |
91 |
'target': { |
'target': { |
92 |
'method': 'appendToPage', |
'method': 'appendToPage', |
100 |
# v2 - live |
# v2 - live |
101 |
|
|
102 |
# 1. load payload from remote side |
# 1. load payload from remote side |
103 |
xml_rpc = FraggleXMLRPC.create(self, config) |
fragglexml = self.rpc.FraggleSync() |
|
fragglexml = xml_rpc.FraggleSync() |
|
104 |
|
|
105 |
# 2. (todo) unmarshal to self.topics (hash) |
# 2. (todo) unmarshal to self.topics (hash) |
106 |
# self.topics = unmarshal(fragglexml) |
# self.topics = unmarshal(fragglexml) |
107 |
|
|
108 |
def getTopics(self): |
def getTopics(self): |
109 |
return self.topics |
return self.topics |
110 |
|
|
111 |
|
def getTopicById(self, id): |
112 |
|
return self.topics[id] |
113 |
|
|
114 |
|
|
115 |
class urlOpener(object): |
class urlOpener(object): |