Skip to main content

AccidentallyTheCables Utility Kit

Project description

ATCKit

AccidentallyTheCable's Utility Kit

About

This is a small kit of classes, util functions, etc that I found myself rewriting or reusing frequently, and instead of copying everywhere, they are now here.

How does it work?

Do the needfuls.... do the needful dance

Literally, import whatever you need to use..

Usage

FunctionSubscriber

A Class container for Function callback subscription via += or -=. Functions can be retrieved in order of addition.

subscriber = FunctionSubscriber()

def a():
    print("I am a teapot")

def b():
    print("I am definitely totally not also a teapot, I swear")

subscriber += a
subscriber += b

for cb in subscriber.functions:
    cb()

>> I am a teapot
>> I am definitely totally not also a teapot, I swear

This class uses the typing.Callable type for function storage. You can extend the FunctionSubscriber class to define the callback function parameters, etc.

class MySubscriber(FunctionSubscriber):
    """My Function Subscriber
    Callback: (bool) -> None
    """

    _functions:list[Callable[[bool],None]]

    def __iadd__(self,fn:Callable[[bool],None]) -> Self:
        """Inline Add. Subscribe Function
        @param method \c fn Method to Subscribe
        """
        return super().__iadd__(fn)

    def __isub__(self,fn:Callable[[bool],None]) -> Self:
        """Inline Subtract. Unsubscribe Function
        @param method \c fn Method to Unsubscribe
        """
        return super().__isub__(fn)

UtilFuncs

A Class containing various static methods:

  • dump_sstr: Dump Structured Data (dict) to str of specified format. Accepts JSON, YAML, TOML
  • load_sfile: Load Structured Data File, automatically determining data by file extension. Accepts JSON, YAML, TOML
  • scan_dir: Search a specified Path, and execute a callback function on discovered files.
    • Allows exclusion of Files/Dirs via regex pattern matching
  • deep_sort: Sort a Dictionary recursively, including through lists of dicts
  • check_pid: Check if a process ID exists (via kill 0)
  • register_signals: Register Shutdown / Restart Handlers
    • Check for Shutdown via UtilFuncs.shutdown (bool)
    • Check for Restart via UtilFuncs.restart (bool)

Version

A Class for version manipulation.

A Version can be created from:

  • Semantic String ("1.0.0")
  • List of Strings or Ints of a version (["1","0","0"] or [1,0,0])
  • Tuple of Strings or Ints of a version (("1","0","0") or (1,0,0))

Versions are comparable (>,<,>=,<=,==,!=) Versions are addable and subtractable (a -= b, a += b)

  • During subtraction, if a part goes negative, it will be set to 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atckit-1.4.1.tar.gz (83.2 kB view details)

Uploaded Source

Built Distribution

atckit-1.4.1-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file atckit-1.4.1.tar.gz.

File metadata

  • Download URL: atckit-1.4.1.tar.gz
  • Upload date:
  • Size: 83.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for atckit-1.4.1.tar.gz
Algorithm Hash digest
SHA256 065a367ca74a35527593dff78f27374f4a65cd15c6a88d1751bb1d6bc1a6a532
MD5 223b703969b820e97e60129ecdca1e9d
BLAKE2b-256 1a2d1f90b988391d926b6820a5c395dab3154c8868fd91ead804e37eeb349327

See more details on using hashes here.

File details

Details for the file atckit-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: atckit-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for atckit-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ded5dfa812599570933019a1bce878d7b4902ea28e0a02d9dcef88196f35fd5
MD5 c55c55d38328612df8438859d2e7b13b
BLAKE2b-256 bdac149c803aff66c7035a45a5ee05ac3204078e1c0a59bbee3968a13e0d6168

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page