hbp_nrp_commons.ZipUtil module

This module provides helper functions to handle zip

class ZipUtil[source]

Bases: object

This class provides helper functions to handle zip

static create_from_path(path, dest_zip_file)[source]

Create a zip from a path

Parameters
  • path – path to be compressed

  • dest_zip_file – file name and path to the zip archive

Returns

The created zip file

static extractall(zip_target, extract_to, overwrite=False, flatten=False)[source]

Extract a zip in the given location

Parameters
  • zip_target – absolute path of the zip file or BytesIO object

  • extract_to – absolute path to the folder where to unzip

  • overwrite – boolean to indicate whether to overwrite the existing contents

Returns

static get_rootname(zip_abs_path)[source]

Gets the root folder name inside a zip Note: for some zip, namelist doesn’t contain the folders as entries Possibly dependent upon how the zip was bundled, hence the extra check

Returns

root folder name inside a zip