diff options
author | Joel Andres Granados <jgranado@redhat.com> | 2008-06-06 15:59:14 +0200 |
---|---|---|
committer | Joel Andres Granados <jgranado@redhat.com> | 2008-06-06 15:59:14 +0200 |
commit | 00086b6421cbf4e6405703a56980a5461846042b (patch) | |
tree | 9ce69a8063c3775cdcd8bb9b434fe65bf817f8ef /pyfirstaidkit/utils/backup.py | |
parent | 69130766005e8ed991601b1ceabde563b4eafa0e (diff) | |
download | firstaidkit-00086b6421cbf4e6405703a56980a5461846042b.tar.gz firstaidkit-00086b6421cbf4e6405703a56980a5461846042b.tar.xz firstaidkit-00086b6421cbf4e6405703a56980a5461846042b.zip |
Add an exists function to the backup system.
Diffstat (limited to 'pyfirstaidkit/utils/backup.py')
-rw-r--r-- | pyfirstaidkit/utils/backup.py | 28 |
1 files changed, 26 insertions, 2 deletions
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__,)) |