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
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
pyXhUtils-0.0.9.tar.gz
(19.4 kB
view hashes)
Built Distribution
pyXhUtils-0.0.9-py3-none-any.whl
(20.1 kB
view hashes)
Close
Hashes for pyXhUtils-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f690014d7f5c52b62bffc98959fc90330cf622e8b417ee1e652ef719f81e1f9c |
|
MD5 | 5c671fba5e6aa4aa62aecfa64896d1df |
|
BLAKE2b-256 | 95497e912d9d5df68478dda1c8b3d449483a9ca11d5df378fdd7d511fcbc6749 |