datalad.support.archives
Various handlers/functionality for different types of files (e.g. for archives)
- class datalad.support.archives.ArchivesCache(toppath=None, persistent=False)[source]
Bases:
object
Cache to maintain extracted archives
- Parameters:
toppath (str) – Top directory under .git/ of which temp directory would be created. If not provided – random tempdir is used
persistent (bool, optional) – Passed over into generated ExtractedArchives
- property path
- class datalad.support.archives.ExtractedArchive(archive, path=None, persistent=False)[source]
Bases:
object
Container for the extracted archive
- STAMP_SUFFIX = '.stamp'
- get_extracted_filename(afile)[source]
Return full path to the afile within extracted archive
It does not actually extract any archive
- get_extracted_files()[source]
Generator to provide filenames which are available under extracted archive
- get_leading_directory(depth=None, consider=None, exclude=None)[source]
Return leading directory of the content within archive
- Parameters:
depth (int or None, optional) – Maximal depth of leading directories to consider. If None - no upper limit
consider (list of str, optional) – Regular expressions for file/directory names to be considered (before exclude). Applied to the entire relative path to the file as in the archive
exclude (list of str, optional) – Regular expressions for file/directory names to be excluded from consideration. Applied to the entire relative path to the file as in the archive
- Returns:
If there is no single leading directory – None returned
- Return type:
str or None
- property is_extracted
- property path
Given an archive – return full path to it within cache (extracted)
- property stamp_path
- datalad.support.archives.decompress_file(archive, dir_, leading_directories='strip')[source]
Decompress archive into a directory dir_
- Parameters:
archive (str)
dir (str)
leading_directories ({'strip', None}) – If strip, and archive contains a single leading directory under which all content is stored, all the content will be moved one directory up and that leading directory will be removed.