Skip to main content

NOFUS - Simple Single Purpose Classes

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:

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 logger 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!")

# Disable logging
Logger.disable()

# Set 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("Debug!")

# Or Define a custom logger
from logger 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:

TODO

License

NOFUS is covered by the Simplified BSD License.

Project details


Release history Release notifications

Download files

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

Files for nofus, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size nofus-0.1.1-py3-none-any.whl (13.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size nofus-0.1.1.tar.gz (10.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page