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