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
clean(force=False)[source]
get_archive(archive)[source]
path
class datalad.support.archives.ExtractedArchive(archive, path=None, persistent=False)[source]

Bases: object

Container for the extracted archive

STAMP_SUFFIX = '.stamp'
assure_extracted()[source]

Return path to the extracted archive. Extract archive if necessary

clean(force=False)[source]
get_extracted_file(afile)[source]
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

is_extracted
path

Given an archive – return full path to it within cache (extracted)

stamp_path
datalad.support.archives.compress_files(files, archive, path=None, overwrite=True)[source]

Compress files into an archive file

Parameters:
  • files (list of str) –
  • archive (str) –
  • path (str) – Alternative directory under which compressor will be invoked, to e.g. take into account relative paths of files and/or archive
  • overwrite (bool) – Whether to allow overwriting the target archive file if one already exists
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.
datalad.support.archives.unixify_path(path)[source]

On windows convert paths from drive:d ile to /drive/d/file

This overcomes problems with various cmdline tools we are to use, such as tar etc