#File IO class file
#Purpose - read and write encapsulation
#imports
from PythonCard import dialog, model
import pickle
import wx
import os, glob
import shutil
#class specifyer
#takes db class
class IO():
listName = "rxList.dip"
#init func
def __init__(self):
print "init IO Class"
#loads a list -
def LoadList(self,db):
print "Loading List"
try:
db = pickle.load(open(self.listName,'r'))
except:
print "Unable to find db file: Providing and saving blank list"
#ill figure out the dialog thing later
#dialog.alertDialog(self, 'Unable to find db file: Providing saving blank list', 'File Load Error')
self.SaveList(db)
return db
#saves the list
def SaveList(self,db):
print "Saving List"
pickle.dump(db,open(self.listName,'w'))
print "List Saved"
#cycles through a dir giving list of resulting matches to Regular expression - works
def parseDir(self,workDir,dirEntry,rx):
path = workDir + dirEntry[2]
lst = []
for infile in glob.iglob(os.path.join(workDir, '*.*')):
#print "current file is: " + infile
#print "@%s@" % infile
tmp = infile.replace(workDir,"")
lst.append(tmp[1:])
resultList = rx.rxMatch(dirEntry[1],lst)
return resultList
#works
def mkdir(self,target):
try:
os.mkdir(target)
except:
#print "Dir %s already exists" % target
pass
#moves a file to the targe
def moveFile(self,file,target):
try:
self.mkdir(target)
shutil.move(file,target)
except:
print "Something whent wrong with the move. Check to see if the file being moved is not over writeing an existing file"
print "Else your system is glichy"