previous string_handling located datetime and timestamp files have been moved to the datetime handling folder Update readme file with more information about currently covered areas
95 lines
2.9 KiB
Python
Executable File
95 lines
2.9 KiB
Python
Executable File
#!/usr/bin/env -S uv run --script
|
|
|
|
"""
|
|
Test for progress class
|
|
"""
|
|
|
|
import time
|
|
from random import randint
|
|
import sys
|
|
import io
|
|
from pathlib import Path
|
|
from corelibs.file_handling.progress import Progress
|
|
from corelibs.datetime_handling.datetime_helpers import create_time
|
|
from corelibs.datetime_handling.timestamp_convert import convert_timestamp
|
|
|
|
|
|
def main():
|
|
"""
|
|
test run
|
|
"""
|
|
# flag for file test or normal run
|
|
use_file = 1
|
|
|
|
# variables for object init
|
|
verbose = 1
|
|
precision = -2
|
|
microtime = 0
|
|
wide_time = False
|
|
# object init
|
|
prg = Progress(
|
|
verbose=verbose,
|
|
precision=precision,
|
|
microtime=microtime,
|
|
wide_time=wide_time
|
|
)
|
|
# prg.SetPrecision(-2)
|
|
# prg.SetStartTime(time.time())
|
|
prg.set_start_time()
|
|
print(
|
|
f"PRECISION: {prg.precision} | TEN STEP: {prg.precision_ten_step} | "
|
|
f"WIDE TEME: {prg.wide_time} | MICROTIME: {prg.microtime} | VERBOSE: {prg.verbose}"
|
|
)
|
|
|
|
if use_file:
|
|
file_name = 'foo2.csv'
|
|
folder_name = 'data'
|
|
script_path: Path = Path(__file__).resolve().parent
|
|
file_path = script_path.joinpath(folder_name, file_name)
|
|
current_size = 0
|
|
# , newline=''
|
|
with open(file_path, 'r', encoding="UTF-8") as fh:
|
|
fh.seek(0, io.SEEK_END)
|
|
prg.set_filesize(fh.tell())
|
|
fh.seek(0, io.SEEK_SET)
|
|
print(f"Is FH seekable: {fh.seekable()} | Is TTY: {fh.isatty()}")
|
|
print(
|
|
f"Buffer size: {io.DEFAULT_BUFFER_SIZE} | "
|
|
f"Do Buffering: {fh.line_buffering} | "
|
|
f"File size: {prg.filesize}"
|
|
)
|
|
data = fh.readline()
|
|
while data:
|
|
current_size += sys.getsizeof(data)
|
|
# print(f"Data: {data}", end = '', flush = True)
|
|
# print(f"Lenght: {len(data)} | Size: {sys.getsizeof(data):,}/{current_size:,}/{prg.filesize:,}")
|
|
# prg.ShowPosition(current_size)
|
|
# print(f"Tell: {fh.tell()}")
|
|
# ouput progress with current file pos
|
|
prg.show_position(fh.tell())
|
|
data = fh.readline()
|
|
else:
|
|
print(f"Starting: {create_time(prg.start if prg.start is not None else 0)}")
|
|
prg.set_linecount(256)
|
|
i = 1
|
|
while i <= prg.linecount:
|
|
sleep = randint(1, 9)
|
|
sleep /= 7
|
|
time.sleep(sleep)
|
|
# print(f"[{i}] Sleep for {sleep}")
|
|
prg.show_position()
|
|
i += 1
|
|
prg.set_end_time()
|
|
print(
|
|
f"Start: {create_time(prg.start if prg.start is not None else 0)}, "
|
|
f"End: {create_time(prg.end if prg.end is not None else 0)}, "
|
|
f"Run Time: {convert_timestamp(prg.run_time if prg.run_time is not None else 0)}, "
|
|
f"Verbose: {prg.verbose}"
|
|
)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
# __END__
|