12 |
self.fraggleXML = fraggleParserXML.create(self) |
self.fraggleXML = fraggleParserXML.create(self) |
13 |
|
|
14 |
def __init__(self,parent): |
def __init__(self,parent): |
15 |
|
self.configList = {} |
16 |
|
self.prefsfile = os.path.join(self.getDefaultDir(), 'prefs.xml') |
17 |
self.__init_fraggle_xml__() |
self.__init_fraggle_xml__() |
18 |
self.restoreProfiles() |
self.restoreProfiles() |
19 |
|
|
24 |
self.configList = {'username': username,'password': password,'url': url,'retrieval': retrieval} |
self.configList = {'username': username,'password': password,'url': url,'retrieval': retrieval} |
25 |
|
|
26 |
def getConfig(self): |
def getConfig(self): |
27 |
|
if not self.configList: |
28 |
|
self.loadConfig(self.prefsfile) |
29 |
return self.configList |
return self.configList |
|
|
|
30 |
|
|
31 |
def loadConfig(self,inputLocation): |
def loadConfig(self,inputLocation): |
32 |
self.configList = self.fraggleXML.unmarshalXML(inputLocation) |
self.configList = self.fraggleXML.unmarshalXML(inputLocation) |
33 |
|
|
|
|
|
34 |
def saveConfig(self): |
def saveConfig(self): |
35 |
engine = FraggleEngine() |
#self.fraggleXML.marshalXML(self.profileDictionary, self.prefsfile) |
36 |
|
self.fraggleXML.marshalXML(self.configList, self.prefsfile) |
|
prefsfile = os.path.join(engine.getDefaultDir(), 'prefs.xml') |
|
|
#self.fraggleXML.marshalXML(self.profileDictionary, prefsfile) |
|
|
self.fraggleXML.marshalXML(self.configList, prefsfile) |
|
37 |
|
|
38 |
def saveProfiles(self): |
def saveProfiles(self): |
39 |
engine = FraggleEngine() |
profilesTemp = os.path.join(self.getDefaultDir(), 'profiles.xml') |
|
profilesTemp = os.path.join(engine.getDefaultDir(), 'profiles.xml') |
|
40 |
self.fraggleXML.marshalXML(self.profileDictionary, profilesTemp) |
self.fraggleXML.marshalXML(self.profileDictionary, profilesTemp) |
41 |
#print self.profileDictionary |
#print self.profileDictionary |
42 |
|
|
43 |
def restoreProfiles(self): |
def restoreProfiles(self): |
44 |
engine = FraggleEngine() |
profiles = os.path.join(self.getDefaultDir(), 'profiles.xml') |
|
profiles = os.path.join(engine.getDefaultDir(), 'profiles.xml') |
|
45 |
self.profileDictionary = self.fraggleXML.unmarshalXML(profiles) |
self.profileDictionary = self.fraggleXML.unmarshalXML(profiles) |
46 |
#print self.profileDictionary |
#print self.profileDictionary |
47 |
|
|
91 |
self.profileDictionary.pop(self.profileDictionary.index(profileId)) |
self.profileDictionary.pop(self.profileDictionary.index(profileId)) |
92 |
except IndexError: |
except IndexError: |
93 |
pass |
pass |
94 |
|
|
95 |
|
# from Pears: http://project5.freezope.org/pears/ |
96 |
|
def getDefaultDir(self): |
97 |
|
"""Gets location of default dir and creates it |
98 |
|
if necessary. ($HOME/.pears/)""" |
99 |
|
try: |
100 |
|
import pearsdebug |
101 |
|
savedir = pearsdebug.savedir |
102 |
|
except: |
103 |
|
dir = '.netfraggle' |
104 |
|
savedir = os.path.expanduser(os.path.join('~', dir)) |
105 |
|
if len(savedir)<=len("c:\\/" + dir): |
106 |
|
# problem that might occur on Win2k (no $HOME environment variable) |
107 |
|
temp = os.path.join(os.path.expandvars('$USERPROFILE'), dir) |
108 |
|
if temp > len("c:\\/" + dir): |
109 |
|
savedir = temp |
110 |
|
# create dir if it doesn't exist |
111 |
|
if not os.path.exists(savedir): |
112 |
|
os.makedirs(savedir) |
113 |
|
return savedir |
114 |
|
|
115 |
|
|