pygacity.util.collectors module

class pygacity.util.collectors.ByteCollector(line_length: int = 80, comment_char: str = '#', byte_collector: str = '')[source]

Bases: object

A simple string manager

The main object in a ByteCollector instance is a string of bytes (byte_collector). The string can be appended to by anoter string or the contents of a file. The string can have “comments” written to it.

addline(msg: str, end: str = '\n')[source]

Appends msg to the string as a line

Parameters:
  • msg (str) – the message

  • end (str, optional) – end-of-line byte

banner(msg: str)[source]

Logs msg as a banner using my_logger

Parameters:

msg (str) – the message

byte_collector: str = ''

the collected string

comment(msg: str, end: str = '\n')[source]

Appends msg as a comment to the string

Parameters:
  • msg (str) – the message

  • end (str, optional) – end-of-line byte

comment_char: str = '#'

comment character

has_statement(statement: str, end: str = '\n', exclude: str = '#')[source]

Determines if a particular statement is on at least one non-comment line

Parameters:
  • statement (str) – the statement; e.g., ‘exit’

  • end (str, optional) – end-of-line byte

  • exclude (str, optional) – comment byte

injest_file(filename: str)[source]

Appends contents of file ‘filename’ to the string

Parameters:

filename (str) – the name of the file

lastline(end: str = '\n', exclude: str = '#')[source]

Returns last line in the string

Parameters:
  • end (str, optional) – end-of-line byte

  • exclude (str, optional) – comment byte

line_length: int = 80

line length for comment wrapping

log(msg: str)[source]

Logs msg using my_logger

Parameters:

msg (str) – the message

reset()[source]

Resets the string

write(msg: str)[source]

Appends msg to the string

Parameters:

msg (str) – the message

class pygacity.util.collectors.FileCollector(initial: list[str | Path] = None)[source]

Bases: UserList

A class for handling collections of files to be managed together as Paths

append(item: str | Path)[source]

Appends a file path to the collection

Parameters:

item (str | Path) – the file path to append

archive(basepath: Path, delete: bool = False)[source]

Archives the files in the collection into a single compressed file. If OS is Windows, makes a zipfile; if Linux, makes a tarball of the files in the collection.

Parameters:
  • basepath (Path) – basename of the resulting tarball or zipfile

  • delete (bool, optional) – if True, deletes the original files after archiving (default is False)

flush()[source]

Deletes all files in the collection from disk

get_filenames() list[str][source]

Returns list of filenames in the collection as strings

pygacity.util.collectors.on_rm_error(func, path, exc)[source]