Skip to main content

NOFUS - Nate's One-File Utilities Stash

Project description

NOFUS: Nate's One-File Utilities Stash

About NOFUS

A collection of single purpose classes for common tasks, focusing on simple and straightforward use. Each class can be taken and used individually and requires no external dependencies.

Uses

ConfigFile: No Hassle Config File Parser

Example Config:

[email]
admin    = admin@example.com
reply_to = feedback@example.com

[auth.sql]
host = sql.example.com
db   = mydbname
user = sqluser
pw   = "secret_passwd"

[auth.ldap]
uri = "ldap://ldap1.example.com:389"
uri = "ldap://ldap2.example.com:389"
uri = "ldap://ldap3.example.com:389"

Example Use:

from nofus import ConfigFile

conf = ConfigFile("/path/to/my.conf")
if not conf.load():
    print(conf.errors())
else:
    admin_email = conf.get("email.admin")
    reply_email = conf.get("email.reply_to", default="donotreply@example.com")

    sqlauth     = conf.get("auth.sql")
    sql_host    = sqlauth.get("host")
    sql_db      = sqlauth.get("db")
    sql_user    = sqlauth.get("user")
    sql_pw      = sqlauth.get("pw")

    ldap_uris   = conf.get_list("auth.ldap.uri")

Logger: Simplified Alternate Logging Interface

Example Use:

from nofus import Logger

# Fast setup, default to logging LOG_DEBUG and higher
Logger.initialize('/tmp/myfile.log')
Logger.info("Info!")
Logger.notice("Notice!")
Logger.warning("Warning!")
Logger.error("Error!")
Logger.critical("Critical!")

# Easily put an exception stack trace into the log
try:
    1/0
except ZeroDivisionError as exc:
    Logger.info("Caught something.", exc_info=exc)

# Disable logging
Logger.disable()

# Set custom log level
Logger.initialize('/tmp/myfile.log', Logger.LOG_TRACE)
Logger.trace("Trace!")

# Check log level
if Logger.is_enabled(Logger.LOG_DEBUG):
    Logger.debug("Yep, we're debugging.")

# Or Define a custom logger
from nofus import LoggingInterface
class CustomLogger(LoggingInterface):
    def __init__(self, log_file=None, log_level=None):
        if log_level is None:
            log_level = Logger.LOG_LOW
        # Customize your init

    def make_log(self, entry, log_level):
        # Customize your log actions

Logger.register(CustomLogger())

Installation

If all you need is one class, you can just grab a file and throw it in your project.

Or you can install the whole stack using pip:

pip install nofus

License

NOFUS is covered by the Simplified BSD License.

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

nofus-0.1.5.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

nofus-0.1.5-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file nofus-0.1.5.tar.gz.

File metadata

  • Download URL: nofus-0.1.5.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for nofus-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8fdaf06053bf29262abcebf2a39060ee2338472b021760a8e98d268508594bff
MD5 285252abfd3ae9e9006cbc51383f0aac
BLAKE2b-256 93bf14c167699f3e0b1ae4c8f1842fd615b9a93efbf8c1f67c16cfbb659213cf

See more details on using hashes here.

File details

Details for the file nofus-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: nofus-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for nofus-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e4e97c9dbcab9aaec858678c9a1caf4ffba0cd5724c3e70b2ce091b7f2a9ee87
MD5 ee4553c86ac107a882b1ac46b66ea703
BLAKE2b-256 2ddd20315312b49ca1517eaff6282f3cfcb281aff25d2b5ea5934221014c030c

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