1 |
joko |
1.3 |
import os |
2 |
|
|
|
3 |
xabbu |
1.1 |
import fraggleParserXML |
4 |
joko |
1.3 |
from fraggleEngine import * |
5 |
xabbu |
1.1 |
|
6 |
xabbu |
1.2 |
def create(parent): |
7 |
|
|
return fraggleCtlPreferences(parent) |
8 |
|
|
|
9 |
xabbu |
1.1 |
class fraggleCtlPreferences: |
10 |
|
|
|
11 |
xabbu |
1.2 |
def __init_fraggle_xml__(self): |
12 |
|
|
self.fraggleXML = fraggleParserXML.create(self) |
13 |
xabbu |
1.1 |
|
14 |
|
|
def __init__(self,parent): |
15 |
joko |
1.6 |
self.configList = {} |
16 |
|
|
self.prefsfile = os.path.join(self.getDefaultDir(), 'prefs.xml') |
17 |
xabbu |
1.1 |
self.__init_fraggle_xml__() |
18 |
xabbu |
1.5 |
self.restoreProfiles() |
19 |
xabbu |
1.1 |
|
20 |
|
|
#def savePrefs(): |
21 |
|
|
|
22 |
|
|
|
23 |
xabbu |
1.2 |
def setConfig(self,username,password,url,retrieval): |
24 |
|
|
self.configList = {'username': username,'password': password,'url': url,'retrieval': retrieval} |
25 |
|
|
|
26 |
|
|
def getConfig(self): |
27 |
joko |
1.6 |
if not self.configList: |
28 |
|
|
self.loadConfig(self.prefsfile) |
29 |
xabbu |
1.2 |
return self.configList |
30 |
xabbu |
1.4 |
|
31 |
|
|
def loadConfig(self,inputLocation): |
32 |
|
|
self.configList = self.fraggleXML.unmarshalXML(inputLocation) |
33 |
|
|
|
34 |
xabbu |
1.2 |
def saveConfig(self): |
35 |
joko |
1.6 |
#self.fraggleXML.marshalXML(self.profileDictionary, self.prefsfile) |
36 |
|
|
self.fraggleXML.marshalXML(self.configList, self.prefsfile) |
37 |
xabbu |
1.5 |
|
38 |
|
|
def saveProfiles(self): |
39 |
joko |
1.6 |
profilesTemp = os.path.join(self.getDefaultDir(), 'profiles.xml') |
40 |
xabbu |
1.5 |
self.fraggleXML.marshalXML(self.profileDictionary, profilesTemp) |
41 |
|
|
#print self.profileDictionary |
42 |
|
|
|
43 |
|
|
def restoreProfiles(self): |
44 |
joko |
1.6 |
profiles = os.path.join(self.getDefaultDir(), 'profiles.xml') |
45 |
xabbu |
1.5 |
self.profileDictionary = self.fraggleXML.unmarshalXML(profiles) |
46 |
|
|
#print self.profileDictionary |
47 |
|
|
|
48 |
|
|
def appendProfile(self,profileKey,configList): |
49 |
|
|
#print "Appending: " |
50 |
|
|
#print self.profileDictionary |
51 |
|
|
list = self.getProfileList() |
52 |
|
|
try: |
53 |
|
|
temp = list.index(profileKey) |
54 |
|
|
#print "Index Collision" |
55 |
|
|
return 1 |
56 |
|
|
except ValueError: |
57 |
|
|
try: |
58 |
|
|
self.profileDictionary.append(profileKey) |
59 |
|
|
self.profileDictionary.append(configList) |
60 |
|
|
except AttributeError: |
61 |
|
|
self.profileDictionary = [profileKey,configList] |
62 |
|
|
return 0 |
63 |
|
|
#print self.profileDictionary |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
def loadProfile(self,profileKey): |
67 |
|
|
try: |
68 |
|
|
key = self.profileDictionary.index(profileKey) |
69 |
|
|
self.configList = self.profileDictionary[key+1] |
70 |
|
|
finally: |
71 |
|
|
pass |
72 |
|
|
|
73 |
|
|
def getProfileList(self): |
74 |
|
|
#print self.profileDictionary |
75 |
|
|
try: |
76 |
|
|
profileBuffer = self.profileDictionary |
77 |
|
|
x = len(profileBuffer) -1 |
78 |
|
|
tempList = [] |
79 |
|
|
while x >= 0: |
80 |
|
|
tempList.append(profileBuffer[x-1]) |
81 |
|
|
x = x-2 |
82 |
|
|
return tempList |
83 |
|
|
except TypeError: |
84 |
|
|
return [] |
85 |
|
|
except IndexError: |
86 |
|
|
return [] |
87 |
|
|
|
88 |
|
|
def deleteProfile(self,profileId): |
89 |
|
|
try: |
90 |
|
|
self.profileDictionary.pop(self.profileDictionary.index(profileId)+1) |
91 |
|
|
self.profileDictionary.pop(self.profileDictionary.index(profileId)) |
92 |
|
|
except IndexError: |
93 |
|
|
pass |
94 |
joko |
1.6 |
|
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 |
xabbu |
1.5 |
|