Skip to main content

Another collection of utilities

Project description

logging_utils

logging consists of the following classes and functions to help with the burden of logging

RelativePathRotatingFileHandler

Not sure if this is working properly

get_logger()

This function retrieves a logger for your file and function/method. This should be called first. For example:

start_function(logger, **kwargs)

This function tags the log file with the entry of a function/method. You may turn it on or off in your logging configuration note that the msg= argument is reserved for single string messages

end_function(logger, **kwargs)

This function tags the log file with the exit of a function/method. You may turn it on or off in your logging configuration note that the msg= argument is reserved for single string messages

Here is an example of everything

    val1 = 5
    val2 = 6
    logger = get_logger()
    start_function(logger, msg="testing")

    # or you can call it this way:
    start_function(logger, val1=val1, val2=val2)
    val1 = 10
    val2 = {"first": 1, "second": 2}
    end_function(logger, val1=val1, val2=val2)

os_utils

os consists of the following classes and functions

UnhandledOs

This is raised when the library does not recognize the operating system

list_timezones()

This function returns all known timezones

get_timezone()

This function returns the timezone selected by the operating system

kill_process(name)

This function kills the specified process name

is_running(name)

This function returns whether the specified process name is currently running

os_type()

This function returns the operating system type

get_ip_addresses()

This function returns all IP addresses on this hardware

#config This contains the object ConfigUtils It is used to read and write .ini files. You should put all information into the different methods to fully define the configuration file.

The constructor takes the configuration file name, a title to add to the top of the file, and a flag indicating the file is being constructed.

class ConfigManager:
    def __init__(self, file_name, title=None, create=False):

The read_entry function reads a section/entry from the file. It takes a default value in case the value does not exist in the file and also to create a new file. The notes parameter describe the entry in the file

    def read_entry(self, section, entry, default_value, notes=None):

The read_section function reads the entire section from the configuration file and returns a dictionary of the entries. Note that the notes are only applied to the setion (not to the individual entries)

    def read_section(self, section, default_entries, notes=None):

The write function writes a new configuration file. If this is called, the package will check if the file exists. If it does, it will abort with a warning. If the file does not exist, it will write it and abort.

    def write(self, out_file):

Here is an example of ConfigManager and its functions:

    write = False # set this to True to create the configuration file
    cfg_mgr = ConfigManager("test.ini", "This is the title of the ini file\n"
                                        "You can have multiple lines if you use line breaks", write)
    first = cfg_mgr.read_entry("User 1", "first name", "Joe", "This is the first name")
    last = cfg_mgr.read_entry("User 1", "last name", "Brown", "This is the last name")
    age = cfg_mgr.read_entry("User 1", "age", 12)
    is_male = cfg_mgr.read_entry("User 1", "male", True)
    weight = cfg_mgr.read_entry("User 1", "weight", 23.5)
    section = cfg_mgr.read_section("user 2", {"first name": "Sally",
                                              "last name": "Jones",
                                              "age": 15,
                                              "is_male": False,
                                              "weight": 41.3},
                                   "You only get to add notes at the top of the section using this method")

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

thompcoutils-0.0.31.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

thompcoutils-0.0.31-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file thompcoutils-0.0.31.tar.gz.

File metadata

  • Download URL: thompcoutils-0.0.31.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for thompcoutils-0.0.31.tar.gz
Algorithm Hash digest
SHA256 65cffa8fe2d32dee0045968bd96444f9d8f346c8a3ccff5d2ec562594f5463a2
MD5 0e297097138561351a169bc6bffdfe10
BLAKE2b-256 c19efb3644102ff7bc67dd54432e5b3fa9a17f861f2a36b9d3f6e89dcd9fdeda

See more details on using hashes here.

File details

Details for the file thompcoutils-0.0.31-py3-none-any.whl.

File metadata

  • Download URL: thompcoutils-0.0.31-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for thompcoutils-0.0.31-py3-none-any.whl
Algorithm Hash digest
SHA256 769e1219310b72f81c57a0d574cf33e12240e04ec063e610f028d472303c2f39
MD5 d4ce848c98305c2f70df362e5a5b5423
BLAKE2b-256 b4e28c622258dfca4ea0330a89999d6672375c90d68e6f6865e4cb01df3a23a5

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