Input/Output

magna.util.disk.untar(file_path, dir_name)

Extracts the contents of the tar file into the target directory.

Parameters
  • file_path (str) – The path to the tar file.

  • dir_name (str) – The directory to extract the tar file into.

Examples

Extract the contents of the tar file at /tmp/data.tar.gz into the directory /tmp/data.

>>> untar('/tmp/data.tar.gz', '/tmp/data')
magna.util.disk.md5sum(path)

Returns the md5 hash of a file.

Parameters

path (str) – The path to the file.

Return type

str

magna.util.disk.cache_file(srv_path, local_name)

Copies a file to the magna cache (doesn’t auto-remove).

Parameters
  • srv_path (str) – The remote path of the file.

  • local_name (str) – The key to cache this file with.

Return type

str

Returns

The path to the cached file.

Examples

Cache the file at /srv/data.csv as data.csv.

>>> cache_file('/srv/data.csv', 'data.csv')
magna.util.disk.copy_file(src, dest, checksum=False)

Copies a file from the source path to the destination path.

Parameters
  • src (str) – The source path.

  • dest (str) – The destination path.

  • checksum (Optional[bool, None]) – Whether to validate the checksum of the file.

Raises

IOError – If the checksum is invalid.

magna.util.disk.move_file(src, dest, checksum=False)

Moves a file from the source path to the destination path.

Parameters
  • src (str) – The source path.

  • dest (str) – The destination path.

  • checksum (Optional[bool, None]) – Whether to validate the checksum of the file.

Raises

IOError – If the checksum is invalid.

magna.util.disk.get_file_size_fmt(path)

Format a bytes as a human-readable file unit.

Parameters

path (str) – The path to the file.

Return type

str

Returns

The formatted file size.

References

https://web.archive.org/web/20111010015624/http://blogmag.net/blog/read/38/Print_human_readable_file_size