mozfile — File utilities for use in Mozilla testing

mozfile is a convenience library for taking care of some common file-related tasks in automated testing, such as extracting files or recursively removing directories.

mozfile.extract(src, dest=None, ignore=None)

Takes in a tar or zip file and extracts it to dest

If dest is not specified, extracts to os.path.dirname(src)

Returns the list of top level files that were extracted

mozfile.extract_tarball(src, dest, ignore=None)

extract a .tar file

mozfile.extract_zip(src, dest, ignore=None)

extract a zip file

mozfile.move(src, dst)

Move a file or directory path.

This is a replacement for shutil.move that works better under windows, retrying operations on some known errors due to various things keeping a handle on file paths.

mozfile.remove(path)

Removes the specified file, link, or directory tree.

This is a replacement for shutil.rmtree that works better under windows. It does the following things:

  • check path access for the current user before trying to remove

  • retry operations on some known errors due to various things keeping a handle on file paths - like explorer, virus scanners, etc. The known errors are errno.EACCES and errno.ENOTEMPTY, and it will retry up to 5 five times with a delay of (failed_attempts * 0.5) seconds between each attempt.

Note that no error will be raised if the given path does not exists.

Parameters:

path – path to be removed