56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
import sys
|
|
import os
|
|
import re
|
|
import subprocess
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
def main():
|
|
PROG = os.path.basename(__file__)
|
|
REDUCED = "no"
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "-r":
|
|
REDUCED = "yes"
|
|
sys.argv.pop(1)
|
|
|
|
if len(sys.argv) != 3:
|
|
og_raise_error(1, f"Usage: {PROG} [-r] ndisk npart")
|
|
|
|
ndisk = sys.argv[1]
|
|
npart = sys.argv[2]
|
|
|
|
OGLOG = "/path/to/log" # Replace with actual log path
|
|
SERVERLOGDIR = None
|
|
|
|
# Simulate the mount command and awk processing
|
|
mounts = subprocess.check_output(['mount']).decode('utf-8')
|
|
for line in mounts.splitlines():
|
|
parts = line.split()
|
|
if len(parts) > 3 and parts[2] == OGLOG:
|
|
SERVERLOGDIR = parts[1]
|
|
break
|
|
|
|
if SERVERLOGDIR is None:
|
|
og_raise_error(1, "Could not determine server log directory")
|
|
|
|
SOFTFILE = f"soft-{og_get_ip_address()}-{ndisk}-{npart}"
|
|
softfile_path = os.path.join(OGLOG, SOFTFILE)
|
|
|
|
try:
|
|
if REDUCED == "no":
|
|
software_list = og_list_software(ndisk, npart)
|
|
else:
|
|
software_list = "\n".join(
|
|
line for line in og_list_software(ndisk, npart).splitlines()
|
|
if not re.search(r"\(KB[0-9]{6}\)", line)
|
|
)
|
|
|
|
with open(softfile_path, 'w') as f:
|
|
f.write(software_list)
|
|
except Exception as e:
|
|
og_raise_error(1, str(e))
|
|
|
|
print(softfile_path)
|
|
|
|
if __name__ == "__main__":
|
|
main() |