From 00086b6421cbf4e6405703a56980a5461846042b Mon Sep 17 00:00:00 2001 From: Joel Andres Granados Date: Fri, 6 Jun 2008 15:59:14 +0200 Subject: Add an exists function to the backup system. --- pyfirstaidkit/utils/backup.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'pyfirstaidkit/utils/backup.py') diff --git a/pyfirstaidkit/utils/backup.py b/pyfirstaidkit/utils/backup.py index d9bc1b9..6f925f5 100644 --- a/pyfirstaidkit/utils/backup.py +++ b/pyfirstaidkit/utils/backup.py @@ -50,6 +50,9 @@ class BackupStoreInterface(object): def cleanup(self): raise NotImplemented() + def exists(self, name = None, path = None): + raise NotImplemented() + def __init__(self): raise NotImplemented() @@ -134,7 +137,7 @@ class FileBackupStore(BackupStoreInterface): else: os.unlink(path) - stored = os.join(self._path, stored) + stored = os.path.join(self._path, stored) if os.path.isdir(stored): shutil.copytree(stored, path, symlinks = True) @@ -153,7 +156,7 @@ class FileBackupStore(BackupStoreInterface): def delete(self, name): stored, origin = self._data[name] - stored = os.join(self._path, stored) + stored = os.path.join(self._path, stored) if os.path.isdir(stored): shutil.rmtree(stored) @@ -171,6 +174,27 @@ class FileBackupStore(BackupStoreInterface): self.delete(name) os.rmdir(self._path) + def exists(self, name=None, path=None): + if name == None and path == None: + raise BackupException("Cannot call the exists method with both the arguments equal to None") + + if name != None and path != None: + try: + if self._data[name] == path: + return True + else: + return False + except KeyError: + return False + + if name != None and self._data.has_key(name): + return True + + if path != None and self._origin.has_key[path]: + return True + + return False + def __init__(self, path): if self.__class__._singleton: raise BackupException("BackupStore with %s type can have only one instance" % (self.__name__,)) -- cgit