1 |
import os |
2 |
|
3 |
import fraggleParserXML |
4 |
from fraggleEngine import * |
5 |
|
6 |
def create(parent): |
7 |
return fraggleCtlPreferences(parent) |
8 |
|
9 |
class fraggleCtlPreferences: |
10 |
|
11 |
def __init_fraggle_xml__(self): |
12 |
self.fraggleXML = fraggleParserXML.create(self) |
13 |
|
14 |
def __init__(self,parent): |
15 |
self.engine = parent |
16 |
self.configList = {} |
17 |
self.__init_fraggle_xml__() |
18 |
self.restoreProfiles() |
19 |
self.prefsfile = os.path.join(self.engine.getDefaultDir(), 'prefs.xml') |
20 |
|
21 |
#def savePrefs(): |
22 |
|
23 |
|
24 |
def setConfig(self,username,password,url,retrieval): |
25 |
self.configList = {'username': username,'password': password,'url': url,'retrieval': retrieval} |
26 |
|
27 |
def getConfig(self): |
28 |
if not self.configList: |
29 |
self.loadConfig(self.prefsfile) |
30 |
return self.configList |
31 |
|
32 |
def loadConfig(self,inputLocation): |
33 |
self.configList = self.fraggleXML.unmarshalXML(inputLocation) |
34 |
|
35 |
def saveConfig(self): |
36 |
#self.fraggleXML.marshalXML(self.profileDictionary, self.prefsfile) |
37 |
self.fraggleXML.marshalXML(self.configList, self.prefsfile) |
38 |
|
39 |
def saveProfiles(self): |
40 |
profilesTemp = os.path.join(self.engine.getDefaultDir(), 'profiles.xml') |
41 |
self.fraggleXML.marshalXML(self.profileDictionary, profilesTemp) |
42 |
#print self.profileDictionary |
43 |
|
44 |
def restoreProfiles(self): |
45 |
profiles = os.path.join(self.engine.getDefaultDir(), 'profiles.xml') |
46 |
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 |
|
96 |
|
97 |
|