Added base file handler functions to Backup object

This commit is contained in:
Felipe Martin 2013-11-18 23:32:06 +01:00
parent a02e694714
commit a050b7b2f2
1 changed files with 35 additions and 7 deletions

View File

@ -1,5 +1,6 @@
from os import listdir
from os.path import join as join_paths, basename, isdir, isfile
from plistlib import readPlist
from .conf import BACKUPS_PATH
@ -41,30 +42,57 @@ class Backup(object):
'Info.plist', 'Manifest.mbdb', 'Manifest.plist', 'Status.plist'
]
_file_handlers = {
'.plist': '_read_plist'
}
_plist = {}
def __init__(self, path):
self.path = path
self.get_info()
self.check()
self.files = []
print(self._plist)
def get_info(self):
self.id = basename(self.path)
self.name = self.id
self.files = [
x for x in listdir(self.path) if isfile(join_paths(self.path, x))
]
# Check all files
for filename in listdir(self.path):
if isfile(join_paths(self.path, filename)):
self.files.append(filename)
# Check handlers
for match in self._file_handlers.keys():
if match in filename:
handler = getattr(self, self._file_handlers[match])
handler(filename)
def check(self):
for required_file in self._required_files:
# Check if required files are there
if required_file not in self.files:
self.valid = False
def exists(self, filename):
return filename in self.files
#
# File handlers
#
def _read_plist(self, filename):
try:
self._plist[filename] = readPlist(join_paths(self.path, filename))
except:
# TODO
pass
### TEST
# manager = BackupManager()
# manager.lookup()
manager = BackupManager()
manager.lookup()
# for k, backup in manager.backups.items():
# print(backup.id, backup.valid, backup.exists('Info.plist'))
for k, backup in manager.backups.items():
print(backup.id, backup.valid, backup.exists('Info.plist'))