"""
# Compression utilities for the Cirrus Toolkit.

### Functions

## Usage

"""

import os, zipfile


class Compress:
	_error = False


	#== Constructor ===============================================================================


	def __init__(this):
		pass	


	#== Methods ===================================================================================

    
    #
    # ZipFile
    #
	# PURPOSE:
	# Zip a single file.
	#
	def ZipFile(this, source_file, zip_path):
		pass


	#
	# SUMMARY:
	# Zip website folders.
	# This method uses `os.walk` to traverse the source directory and its subdirectories, adding each file to the ZIP archive with a relative path.
    # 
    # PARAMETERS:
	# source_dir - the directory to be zipped.
	# zip_path - the path where the ZIP file will be created.
	#
	# USAGE:
	# app.ZipFolders("./data", "backup.zip")
    #	
	def ZipFolders(this, source_dir, zip_path):
		with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
			for root, _, files in os.walk(source_dir):
				for file in files:
					file_path = os.path.join(root, file)
					arc_name = os.path.relpath(file_path, source_dir)
					zf.write(file_path, arcname=arc_name)