file_utils module

file_utils.directory_from_parameters(params, commonroot='Output')[source]

Construct output directory path with unique IDs from parameters

Parameters
  • params (python dictionary) – Dictionary of parameters read

  • commonroot (string) – String to specify the common folder to store results.

file_utils.get_file(fname, origin, unpack=False, md5_hash=None, cache_subdir='common', datadir=None)[source]

Downloads a file from a URL if it not already in the cache. Passing the MD5 hash will verify the file after download as well as if it is already present in the cache.

Parameters
  • fname (string) – name of the file

  • origin (string) – original URL of the file

  • unpack (boolean) – whether the file should be decompressed

  • md5_hash (string) – MD5 hash of the file for verification

  • cache_subdir (string) – directory being used as the cache

  • datadir (string) – if set, datadir becomes its setting (which could be e.g. an absolute path) and cache_subdir no longer matters

Returns

Path to the downloaded file

file_utils.validate_file(fpath, md5_hash)[source]

Validates a file against a MD5 hash

Parameters
  • fpath (string) – path to the file being validated

  • md5_hash (string) – the MD5 hash being validated against

Returns

boolean – Whether the file is valid