read log files from end, added user management

This commit is contained in:
2026-06-04 13:21:56 -04:00
parent 8a11acfcfd
commit 0796982fd7
8 changed files with 471 additions and 66 deletions
+41 -25
View File
@@ -18,22 +18,16 @@ from parser import (
parse_result_filename,
parse_target_filename,
parse_timestamp,
parse_scan_exclusions,
)
_SMB_SESSIONS = set()
_WIN_DRIVE_PATH_RE = re.compile(r"^[A-Za-z]:[\\/]")
_SCAN_STATE_LOCK = threading.Lock()
_ACTIVE_SCAN_COUNT = 0
_DEFAULT_SCAN_EXCLUSIONS = ""
_ELAPSED_TIME_LINE_RE = re.compile(r"Elapsed\s+time\s*:\s*(\d+):(\d{1,2}):(\d{1,2}(?:\.\d+)?)", re.IGNORECASE)
def _parse_scan_exclusions(value):
raw = value if value not in (None, "") else _DEFAULT_SCAN_EXCLUSIONS
if raw == "" or raw is None:
return None
parts = re.split(r"[,\n;]", str(raw))
return {token.strip().upper() for token in parts if token.strip()}
def _build_match_tokens(parsed):
@@ -299,22 +293,51 @@ def _parse_elapsed_time_to_seconds(line):
seconds = float(match.group(3))
return int(hours * 3600 + minutes * 60 + seconds)
def extract_elapsed_seconds_from_logs(result_dir_path, files):
elapsed_seconds = None
def extract_elapsed_seconds(result_dir_path, files):
log_files = [name for name in files if _is_candidate_log_file(name)]
for log_name in log_files:
log_path = _join_path(result_dir_path, log_name)
try:
for line in _read_text_lines(log_path):
parsed = _parse_elapsed_time_to_seconds(line)
if parsed is not None:
elapsed_seconds = parsed
# Read the log file in reverse to find the most recent "Elapsed time" line
path = _normalize_input_path(log_path)
chunk_size = 8192
if _is_unc_path(path):
_register_smb_session_if_needed(path)
file_obj = smbclient.open_file(path, mode="rb")
else:
file_obj = open(path, "rb")
with file_obj as fh:
fh.seek(0, os.SEEK_END)
file_size = fh.tell()
position = file_size
carry = b""
while position > 0:
read_size = min(chunk_size, position)
position -= read_size
fh.seek(position)
chunk = fh.read(read_size)
data = chunk + carry
lines = data.split(b"\n")
carry = lines[0]
for raw_line in reversed(lines[1:]):
parsed = _parse_elapsed_time_to_seconds(raw_line.decode("utf-8", errors="ignore"))
if parsed is not None:
return parsed
if carry:
parsed = _parse_elapsed_time_to_seconds(carry.decode("utf-8", errors="ignore"))
if parsed is not None:
return parsed
except OSError as exc:
print(f"[scanner] Cannot read log file {log_path}: {exc}")
return elapsed_seconds
return None
def scan_results_only(results_dir, results_dir_ref):
@@ -374,7 +397,7 @@ def full_scan(target_dir, results_dir, results_dir_ref):
def scan_targets(target_dir):
target_dir = _normalize_input_path(target_dir)
exclusions = _parse_scan_exclusions(get_config("scan_exclusions"))
exclusions = parse_scan_exclusions(get_config("scan_exclusions"))
batch_tests = []
try:
@@ -484,7 +507,7 @@ def process_result_dir(results_dir, result_dir_name):
print(f"[scanner] Cannot read result dir {result_dir_name}: {exc}")
return None
elapsed_seconds = extract_elapsed_seconds_from_logs(result_dir_path, files)
elapsed_seconds = extract_elapsed_seconds(result_dir_path, files)
measurement_db = next((name for name in files if name.lower() == "measurement.db"), None)
if not measurement_db:
@@ -514,13 +537,6 @@ def process_result_dir(results_dir, result_dir_name):
}
def parse_deleted_result_dir_name(dir_name):
segments = re.split(r"[_\-]", dir_name)
test_id = next((s for s in segments if re.match(r"^R\d+[A-Z0-9]+$", s, re.IGNORECASE)), None)
device = next((s for s in segments if re.match(r"^CGW\d+$", s, re.IGNORECASE)), None)
return test_id, device
def extract_measurement_data(db_file_path):
result = {"duration_seconds": None, "tputResults": []}
local_db_path = None