Skip to content

Lib

src.anvil.lib.lib

A collection of useful functions and classes used throughout the program.

CopyFiles(old_dir, new_dir, target_file, rename=None)

Copies a file from one directory to another.

Parameters:

Name Type Description Default
old_dir str

The path to the source directory.

required
new_dir str

The path to the destination directory.

required
target_file str

The name of the file to be copied.

required
rename str

The new name for the copied file. Defaults to None.

None

CopyFolder(old_dir, new_dir)

Copies a folder and all its contents to a new location.

Parameters:

Name Type Description Default
old_dir str

The path to the source directory.

required
new_dir str

The path to the destination directory.

required

CreateDirectory(path)

Creates a new directory.

Parameters:

Name Type Description Default
path str

The path to the new directory.

required

File(name, content, directory, mode, skip_tag=False, *args)

Create or modify a file with the given content.

Parameters:

Name Type Description Default
name str

The name of the file.

required
content str | dict

The content of the file.

required
directory str

The directory path where the file should be created or modified.

required
mode str

The file mode, either "w" (write) or "a" (append).

required
skip_tag bool

Whether to skip adding the file metadata tag. Defaults to False.

False
*args

Additional StrEnum.

()
Note

The file content is converted to the appropriate format based on the file extension.

FileExists(path)

Checks if a file exists.

Parameters:

Name Type Description Default
path _type_

The path to the file.

required

Returns:

Name Type Description
bool bool

True if the file exists, False otherwise.

RemoveDirectory(path)

Removes a directory and all its contents.

Parameters:

Name Type Description Default
path str

The path to the directory to be removed.

required

RemoveFile(path)

Removes a file.

Parameters:

Name Type Description Default
path str

The path to the file to be removed.

required

clamp(value, _min, _max)

Clamps a value between a minimum and maximum limit.

Parameters:

Name Type Description Default
value float

The value to be clamped.

required
_min float

The lower limit.

required
_max float

The upper limit.

required

Returns:

Name Type Description
float float

The clamped value.

frange(start, stop, num=1)

Generate a list of interpolated float values between start and stop.

Parameters:

Name Type Description Default
start int

The starting value.

required
stop int

The ending value.

required
num float

The number of values to generate. Defaults to 1.

1

Returns:

Name Type Description
list

A list of interpolated values between start and stop.

normalize_180(angle)

Normalizes an angle between -180 and 180.

Parameters:

Name Type Description Default
angle float

The angle to be normalized.

required

Returns:

Name Type Description
float float

The normalized angle.

zipit(zip_name, dir_list)

Create a ZIP archive containing multiple directories and files.

Parameters:

Name Type Description Default
zip_name

The name of the ZIP archive.

required
dir_list dict

A dictionary where the keys are source directories and the values are target directories.

required
Note

The target directories represent the structure inside the ZIP archive.