Skip to content

Releases: netinvent/ofunctions

Maintenance si here

07 Sep 15:59
Compare
Choose a tag to compare

So basically ofunctions evolves slowly, because it's a collection of small things needed in almost all my projects.
I've been doing this since 2018, and in 2021 I made my repos public.
So there aren't big improvements.
I've tried over the years to keep Python compatibility as low as I could. Except of requestor and threading, everything should still run on Python 2.7, and I strive to make all new releases backwards compatible.

Hope these code collections help someone out there.

v2.8.0

logger_utils

  • Monkeypatch get_worst_logger_level() into logger object returned by logger_get_logger() in order to easily retrieve worst called log level

misc

  • Created a function called replace_in_iterable() that recursively walks a dict structure and replaces data depending on key / value names. Replacement can be the result of a function call.
  • Added fn_name() function which returns current or parent function name depending on the requested level
  • Fixed BytesConverter class to allow interpreting 0

network

  • BREAKING CHANGE: test_http_internet() has been renamed to check_http_internet() to avoid pytest complaints
  • get_public_ip() can now properly enforce timeouts, which didn't work on host resolution because of OS
  • get_public_ip() is now way faster since it tries to concurrently fetch IP addresses

platform

  • Remove get_distro()
  • Added get_os_identifier()

process

  • Refactor kill_childs() to allow grace period before asking nicely to quit, then grace period before being a merciless process killer

requestor

  • Requestor now has ignore_errors getter/setter, which will transform all log levels above info into info

threading

  • @threaded decorator now takes optional __no_thread bool which allows to bypass threading will keeping the decorator syntax (the __no_thread argument is given to the original function and is intercepted by the decorator)
  • New wait_for_thread_completion() function which accepts threads or lists of threads, and returns results or lists of results

Replace something in anything ;)

11 Dec 21:20
Compare
Choose a tag to compare

Maintenance release, with a couple of smaller but nice features, the best being replace_in_iterable

Features

network

  • Added IPv4 / IPv6 preference selector function set_ip_version()
    • Make Nuitka compiler and pylint happy about the way we call into urllib

Misc

  • New replace_in_iterable() function which can iter over a composite dict/list struct and replace values
    • Retains original struct type
    • Can also run a callable to replace values
  • New DotDict() object which is basically a dict that can be accessed with dot notation, ie dict.my.value

Platform

  • Improve os_arch() function to work with various arm platforms

Random

  • Add new password_gen() function which allows to select alpha/numeric/special_chars & non ambiguous chars

Others

  • Removed Python 2.7 from the test matrix since Github doesn't support it anymore
  • Linters are now using Python 3.11

Requests for data

29 Mar 19:31
Compare
Choose a tag to compare

This release mainly adds initial Requestor class for JSON REST API friendly handling.

Features

requestor

  • Initial upload of REST API class

platform

  • os_arch() and python_arch() now also check for arm & arm64 platforms

Same code day different ;)

26 Jan 11:48
Compare
Choose a tag to compare

This is a (very) small release that just tweaks some functions:

Features

  • Added os_arch() function

Misc

logger_utils

  • Make maximum log file rotation size configurable and shift it from 1M to 10M

process

  • Make kill_childs() verbose by default (should always be for sanity purposes)

BytesConverter hotfix

10 Jan 11:21
Compare
Choose a tag to compare

This is a hotfix release for ofunctions

Fixes

misc

  • Fix BytesConverter("0 KB") fails converting to 0
  • Fix BytesConverter("0 b") fails converting to 0

BytesConverter

09 Jan 18:42
Compare
Choose a tag to compare

This new release highly improves BytesConverter class, allowing conversion between bytes / bits / human and IEC notations.

Features

misc

  • highly improves BytesConverter class, allowing conversion between bytes / bits / human and IEC notations
  • Add convert_time_to_seconds() function allowing to convert time strings with more than 24h format into seconds

Misc

  • Remove Python 3.5 and 3.6 from linux test matrix since Github actions don't propose them anymore
  • Update github actions to v3

@no_flood to eliminate identical function calls

07 Nov 17:24
Compare
Choose a tag to compare

This minor release mainly adds @no_flood decorator

Features

threading

  • Added @no_flood decorator to eliminate multiple calls to the same function

logger_utils

  • Replace multiprocess_formatter bool with formatter_insert str so we can insert virtually any logger format we want

Fixes

threading

  • Fixed @threading decorator for Python 3.3+ (use daemon=True)

file_utils

  • Fixed remove_files_on_timestamp_delta() which included directories and obviously failed
  • More Python 2.7 fixes

network love

10 Jul 12:33
Compare
Choose a tag to compare

This release mainly adds a new network class, IOCounters, that will return network interface statistics.
Other minor enhancements include:

Features

checksums

  • Added sha256sum_data() function

srtring handling

  • Added filename_sanitize() function so a string becomes a windows/linux compatible filename

file_utils

  • file_utils.remove_files_on_timestamp_delta() and check_file_timestamp_delta() now accept optional alternative timestamp

misc

  • Added deep_dict_update() function in order to update nested dictionaries with other nested dictionaries
  • Added BytesConverter class which handles conversion between bytes/bits and their binary prefixes

network

  • New IOCounters class that returns periodic network interface statistics
  • probe_mtu and ping functions now allow to specify source
  • added get_public_hostname() function

platform

  • Added get_distro() function which returns distro flavor and version (only works on RHEL so far, help welcome)

string_handling

  • Added sanitize_filename() function to clean filenames in order to work on most filesystems (win/linux/macos)

threading

  • Added a simple threaded decorator for Python 2.7

Fixes

file_utils

  • Fixed remove_files_on_timestamp_delta() did not properly walk directories

Generic

  • Improved Python 2.7 unit tests for logger_utils and string_handling

Stone Age retro compatibility

18 Apr 10:17
Compare
Choose a tag to compare

Well this release mainly adds Python 2.7 retrocompatibility, even if it's totally out of date.
Why ? In order to fit some elder appliances where upgrading Python isn't just an option.

On top of the stone age compatibility, a couple of improvements / fixes made it into this release:

delayed_keyboardinterrupt

  • Added basic unit test

file_utils

  • grep() now has an ignorecase option

mailer

  • Refactored the whole code into a easy to use class (compatibility kept with wrapper)
  • Refactored TLS code to make it non redundant
  • Added missing MIME headers (date, messageID) which improves non-spam score
  • Added missing charset (defaults to utf-8 obviously) for subjet and headers
  • Fixed mail splitting for bulk sending

network

  • Refactored test_http_internet() & get_public_ip() server reach code (is now shared code)
  • Updated get_public_ip() fetch APIs

logger_utils

  • Added a ContextFilter class wihch "automagically" fixes Python 2 non-unicode logging issues
  • Added safe_string_convert() used by the ContextFilter to deal with non-unicode strings in Python 2
  • Added unit tests

string_handling

  • Changed strip_non_alnum_characters() to also exclude '-' (also making the regex Python 2 compatible)

Maintenance release 6

06 Oct 12:01
Compare
Choose a tag to compare

Features

process:

  • kill_childs() has now an option to not kill childs, so we can use it as bare os.kill() replacement which handles PID reusage properly
  • Refactored kill_childs() so we use signals when possible, to avoid race conditions that come with PID reusage
  • Added get_absolute_path() that allows to find an executable path in PATH environment variable, in order to avoid shell=True calls with command_runner / subprocess
  • Added get_processes_by_name() that allows to find processes by name, with default case ignore on Windows

file_utils

  • log_on_perm_fn() now includes a check_permissions() call in order to have more debug material

Misc

  • Added newer python versions to testing matrix
  • Added black linter, moved all linting to Python 3.9 only