CedarBackup3.filesystem

Package CedarBackup3 :: Module filesystem |
[hide private]
[frames] | no frames]

# Module filesystem

source code

Provides filesystem-related objects.

Author: Kenneth J. Pronovici <pronovic@ieee.org>

Classes | [hide private]
| FilesystemList Represents a list of filesystem items.
| BackupFileList List of files to be backed up.
| PurgeItemList List of files and directories to be purged.
| SpanItem Item returned by BackupFileList.generateSpan.

Functions | [hide private]
normalizeDir(path) Normalizes a directory name. | source code
compareContents(path1, path2, verbose=False) Compares the contents of two directories to see if they are equivalent. | source code
compareDigestMaps(digest1, digest2, verbose=False) Compares two digest maps and throws an exception if they differ. | source code

Variables | [hide private]
| logger = `logging.getLogger("CedarBackup3.log.filesystem")`
| __package__ = ``'``CedarBackup3``'``

Function Details | [hide private]

### normalizeDir(path) | source code
Normalizes a directory name. For our purposes, a directory name is normalized by removing the trailing path separator, if any. This is important because we want directories to appear within lists in a consistent way, although from the user's perspective passing in `/path/to/dir/` and `/path/to/dir` are equivalent. Parameters: `path` (String representing a path on disk) - Path to be normalized. Returns: Normalized path, which should be equivalent to the original.

### compareContents(path1, path2, verbose=False) | source code
Compares the contents of two directories to see if they are equivalent. The two directories are recursively compared. First, we check whether they contain exactly the same set of files. Then, we check to see every given file has exactly the same contents in both directories. This is all relatively simple to implement through the magic of BackupFileList.generateDigestMap, which knows how to strip a path prefix off the front of each entry in the mapping it generates. This makes our comparison as simple as creating a list for each path, then generating a digest map for each path and comparing the two. If no exception is thrown, the two directories are considered identical. If the `verbose` flag is `True`, then an alternate (but slower) method is used so that any thrown exception can indicate exactly which file caused the comparison to fail. The thrown `ValueError` exception distinguishes between the directories containing different files, and containing the same files with differing content. Parameters: `path1` (String representing a path on disk) - First path to compare. `path2` (String representing a path on disk) - First path to compare. `verbose` (Boolean) - Indicates whether a verbose response should be given. Raises: `ValueError` - If a directory doesn't exist or can't be read. `ValueError` - If the two directories are not equivalent. `IOError` - If there is an unusual problem reading the directories. Note: Symlinks are not followed for the purposes of this comparison.

### compareDigestMaps(digest1, digest2, verbose=False) | source code
Compares two digest maps and throws an exception if they differ. Parameters: `digest1` (Digest as returned from BackupFileList.generateDigestMap()) - First digest to compare. `digest2` (Digest as returned from BackupFileList.generateDigestMap()) - Second digest to compare. `verbose` (Boolean) - Indicates whether a verbose response should be given. Raises: `ValueError` - If the two directories are not equivalent.