multipackage.manifest module¶
A hash based manifest file.
Summary¶
Classes:
ManagedFile |
|
ManifestFile |
A hash based manifest file. |
Data:
INVALID_HASH |
int(x=0) -> integer int(x, base=10) -> integer |
NOT_PRESENT |
int(x=0) -> integer int(x, base=10) -> integer |
PRESENT_UNKNOWN |
int(x=0) -> integer int(x, base=10) -> integer |
VALID |
int(x=0) -> integer int(x, base=10) -> integer |
Reference¶
-
class
multipackage.manifest.
ManagedFile
(relative_path, absolute_path, status, expected_hash, hash_type)¶ Bases:
tuple
-
absolute_path
¶ Alias for field number 1
-
expected_hash
¶ Alias for field number 3
-
hash_type
¶ Alias for field number 4
-
relative_path
¶ Alias for field number 0
-
status
¶ Alias for field number 2
-
-
class
multipackage.manifest.
ManifestFile
(path, base_path, reporter)[source]¶ Bases:
object
A hash based manifest file.
This class will load a json file that contains relative file paths and hash values. It can detect changes in the files using the hashes.
Parameters: - path (str) – The path to the manifest file. If it does not exist it will be initialized as empty.
- base_path (str) – The base path that will be used to store relative paths for keys.
- reporter (object) – An error reporter class that has a
warning
, error` andinfo
method. This is compatible with the signatures of the Repository class so it can be passed directly.
-
verify_all
(report=False)[source]¶ Verify the hashes of all managed files.
Parameters: report (bool) – Report errors for all invalid files.
-
verify_file
(path)[source]¶ Verify the status of a given file.
The argument should be the path to a given file. If the file is not inside the manifest an InternalError is raised. Otherwise this method will return a string indicating the file’s status.
Parameters: path (str) – The path to the file to check. Returns: The status of the file. Possible options are:
- not_present: The file is not present
- changed: The file is present but does not match the recorded hash.
- unchanged: The file is present and its hash is the same as what was recorded.
Return type: str
-
update_file
(path, hash_type='line')[source]¶ Add or update the hash for a given file.
If the file does not exist, an error is logged and the file is added to the manifest as NOT_PRESENT. Otherwise it is added with the correct hash value.
The new manifest data is written out automatically back to the manifest file on disk.
Parameters: - path (str) – The path to the file that we wish to add to the manifest.
- hash_type (str) – Optional specifier of how to calculate the file’s
hash. Supported options are line, json or section.
line
means that the lines are hashed one at a time with line endings ignored.json
means that the file is valid json which is loaded and then the dict is normalized and hashed.section
means that a section of the file is managed while the rest is not. Default: “line”
-
remove_file
(path, force=False)[source]¶ Remove a managed file from the manifest.
This will remove the entry from this manifest for the file. If the entry does not exist and force is False, an exception will be raised. If force is True, then this error will be silently ignored.
This method does not actually touch the file on disk, it just removes the corresponding entry in this manifest file.
Parameters: