Skip to main content

A collection of self dev py library

Project description

A collection of self dev library.

file_changes_xh

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 file_changes_xh 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

ip_utils_xh

IPv4 string handling utils

import ip_utils_xh 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 ip_utils_xh import defaultIpHostFinder as ipHostFinder
ipHostFinder.find("127.0.0.1")

string_utils_xh

import string_utils_xh as su
su.repeat_str()

apache_log_xh

from apache_log_xh import LogLine


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

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-0.0.9.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

pyXhUtils-0.0.9-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyXhUtils-0.0.9.tar.gz
Algorithm Hash digest
SHA256 ee25de5a0b91e454f7d58f8eb7b100fc91f18b7d05aff6051111b590fd93dc17
MD5 5c4460b2a3dcf987eaf22608b23fd8e5
BLAKE2b-256 431c0c134b61400629daf540a76603f19724f4ec60f1c7076ffd546ce3e0667d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyXhUtils-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f690014d7f5c52b62bffc98959fc90330cf622e8b417ee1e652ef719f81e1f9c
MD5 5c671fba5e6aa4aa62aecfa64896d1df
BLAKE2b-256 95497e912d9d5df68478dda1c8b3d449483a9ca11d5df378fdd7d511fcbc6749

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