Helpers to play with files

simple file manipulation

pyensae.filehelper.enumerate_grep (filename, regex, encoding = ‘utf8’, errors = None)

Extracts lines matching a regular expression.

pyensae.filehelper.file_encoding (filename_or_bytes, limit = 1048576)

Returns the encoding of a file. The function relies on chardet.

pyensae.filehelper.file_head (filename, nbline = 10, encoding = ‘utf8’, errors = ‘strict’)

Extracts the first nbline of a file (assuming it is text file).

pyensae.filehelper.file_tail (filename, nbline = 10, encoding = ‘utf8’, threshold = 16384, errors = ‘strict’)

Extracts the first nbline of a file (assuming it is text file).

pyensae.filehelper.format_helper.format_file_mtime (timestamp)

Returns a :epkg:`datetime` for a file.

compression

pyensae.filehelper.decompress_helper.decompress_bz2 (filename, whereTo = ‘.’, fLOG = <function noLOG at 0x7f086a553f70>)

Decompresses a :epkg:`bz2` file.

pyensae.filehelper.decompress_gz (filename, whereTo = ‘.’, fLOG = <function noLOG at 0x7f086a553f70>)

Decompresses a :epkg:`tar.gz` file.

pyensae.filehelper.decompress_targz (filename, whereTo = ‘.’, silent = True, fLOG = <function noLOG at 0x7f086a553f70>)

Decompresses a :epkg:`tar.gz` file.

pyensae.filehelper.decompress_zip (filename, whereTo = ‘.’, fLOG = <function noLOG at 0x7f086a553f70>)

Unzips a :epkg:`zip` file.

Magic command for notebooks

pyensae.filehelper.magic_file.MagicFile (self, shell = None, kwargs)

Defines magic commands to help with files