Skip to main content

A collection of self dev py library

Project description

A collection of self dev library.

Build

rm -fr dist
python -m build
python -m twine upload dist/*

Script writer

A simple script writer function to write script file with executable permission.

from xh_utils_script_writer import ScriptWriter
script_writer.write_script("test.sh",lambda f: f.write("hello world"), executable=True)
script_writer.write_script_text("test.sh","hello world", executable=True)

xh_utils_file_changes

In case we have log file from apache web server, the log file name is "access.log", the log will be renamed to "access.log-{YYYYmmdd}" daily.
The configuration can be done as below to capture the all the log file content even after renamed to new file name.

import xh_utils_file_changes as fc
import datetime as dt

fileName = "access.log"

# Please see the RenameHandler source code for detail
# The return value for getFunction() is callable for f"{fileName}{separator}{date}"
renameStrategy = fc.RenameHandler(date=dt.date.today(), separator="-")

fpu = fc.FileProgressUtils()  # create the file progress utils
gen = fpu.checkOnceAndDo(
    fileName,
    renameStrategy.getFunction()
)
while True:
    try:
        dr = next(gen)
        if dr.deltaType == fc.DeltaType.RENAMED:
            pass
        else:
            # handler that simply print out the data
            # should implement the own handling logic 
            fc.ChangeHandler.print_changes(dr)
    except StopIteration:
        pass

xh_utils_ip

IPv4 string handling utils

import xh_utils_ip as ipu

# convert string "192.168.8.1/16" to ipu.Ip object
ip = ipu.Ip.from_regular_form("192.168.8.1/16")
print(ip.binary_notation())  # print in binary format

ipResults = [
    print(f"{ipStr}[{pow(2, 32 - ip.ip_seg[4])}] {ip.binary_notation()}")
    for ipStr in
    "10.91.132.0/22\n10.91.136.0/21\n10.91.144.0/20\n10.91.160.0/19\n10.91.196.0/22\n10.91.200.0/21\n10.91.208.0/20\n10.91.224.0/19".split(
        "\n")
    for ip in [ipu.Ip.from_regular_form(ipStr)]
]

Find host by ip if applicable

form xh_utils_ip import defaultIpHostFinder as ipHostFinder
ipHostFinder.find("127.0.0.1")

xh_utils_string

import xh_utils_string as su

su.repeat_str()

xh_utils_apache_log

from xh_utils_apache_log import LogLine

with open("{==== apache log =====}", "r") as f:
    loglinesg = [LogLine.read_log_lines(line) for line in f.readlines()]

progress_printer

Progress Printer responsible to produce less screen print to ensure the program running as expected. Mainly used for dev env.

from xh_utils_progress import ProgressPinger

pinger = ProgressPinger(
    print_every_n_count=100,  # print a progress log every hundred times call ping method
    print_every_n_second=15  # print a progress log every 15 second if not meeting 100 record processing
)

while True:
    pinger.ping()
    pass

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

pyXhUtils-1.0.0.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

pyXhUtils-1.0.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file pyXhUtils-1.0.0.tar.gz.

File metadata

  • Download URL: pyXhUtils-1.0.0.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyXhUtils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 066d1d5aae7c9483ee6e9a6148f40bc662513beb943fb4a4619793d29b059b59
MD5 85041482729bd9edd68aed849dbb55bc
BLAKE2b-256 dddcaca8deb3a726f23a9a521d8999e2ad9112d8db6ae083f0376e701ddfd4b2

See more details on using hashes here.

File details

Details for the file pyXhUtils-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyXhUtils-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyXhUtils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 144937a85768a6543f617bdbd1eb4b01d40b7848459faf859700b0b8026b8272
MD5 bcec0a2c7d254b950a6c5948d278b421
BLAKE2b-256 e36c62b811095d780d2a38af3734bfe3cb090cc1eac019d420d75f628c182fc4

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