Skip to main content

Custom library.

Project description

customlib

A few tools for day to day work.


Available tools:

CfgParser

from customlib.config import cfg
from customlib.constants import CONFIG, DEFAULTS, BACKUP
# or
# from customlib.config import CfgParser
# cfg = CfgParser()


# feeding config parameters
cfg.set_defaults(**DEFAULTS)
cfg.open(file_path=CONFIG, encoding="UTF-8", fallback=BACKUP)

# we're parsing cmd-line arguments
cfg.parse()

# we can also do this...
# cfg.parse(["--logger-debug", "True", "--logger-handler", "file"])

Constants can be overridden or even better you can bring your own:

  • CONFIG - Is the configuration file set by default to your project's path.
  • DEFAULTS - Holds ConfigParser's default section parameters.
  • BACKUP - Is the configuration default dictionary to which we fallback if the config file does not exist.
# module: constants.py

from os.path import dirname, join
from sys import modules

DIRECTORY: str = dirname(modules["__main__"].__file__)

# default config file
CONFIG: str = join(DIRECTORY, "config", "config.ini")

# config default section
DEFAULTS: dict = {
    "directory": DIRECTORY,
}

# backup configuration
BACKUP: dict = {
    "FOLDERS": {
        "logger": r"${DEFAULT:directory}\logs"
    },
    "LOGGER": {
        "name": "customlib.log",
        "handler": "console",  # or "file"
        "debug": False,
    },
}

To pass cmd-line arguments:

X:\path\to\project> python -O script-name.py --section-option value --section-option value

cmd-line args have priority over config file and will override the cfg params.

Because it inherits from ConfigParser and with the help of our converters we now have four extra methods to use in our advantage.

some_list = cfg.getlist("SECTION", "option")
some_tuple = cfg.gettuple("SECTION", "option")
some_set = cfg.getset("SECTION", "option")
some_dict = cfg.getdict("SECTION", "option")

The configuration files are read & written using FileHandle (see customlib.handles), a custom context-manager with thread & file locking abilities.

Logger

from customlib.logging import log
# or
# from customlib.logging import Logger
# log = Logger()


log.debug("Testing debug messages...")
log.info("Testing info messages...")
log.warning("Testing warning messages...")
log.error("Testing error messages...")

By default debugging is set to False and must be enabled to work. See CfgParser section for this.


NOTE:

Documentation is not complete...

More tools to be added soon...

Work in progress...


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

customlib-4.4.3.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

customlib-4.4.3-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file customlib-4.4.3.tar.gz.

File metadata

  • Download URL: customlib-4.4.3.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for customlib-4.4.3.tar.gz
Algorithm Hash digest
SHA256 fdeed7fb5eaab5fd0cb24a980746a352d7674903d5ef2fcbabbf80d43c401749
MD5 60eedc915a924b0ee16bd3b093079255
BLAKE2b-256 40e39e18da933487399276d5f4669c0a9d414764f909df4ab34e68324ef950de

See more details on using hashes here.

File details

Details for the file customlib-4.4.3-py3-none-any.whl.

File metadata

  • Download URL: customlib-4.4.3-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.9

File hashes

Hashes for customlib-4.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f535b21853277b2fbb66276c09515a8b8134b5298a89228494dfc477fb840531
MD5 3c20fcee593112ebf8b250805b116f3c
BLAKE2b-256 83b4dfb12404f05a16a06b0a57e46d3bd1c245f9e478a168f8f177c6193de316

See more details on using hashes here.

Supported by

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