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