Add a few things; nfs_lazy_reboot2.yml/nfs_lazy_reboot3.yml are valid; v2 is best POC

This commit is contained in:
2025-07-30 16:49:16 -04:00
parent 6bcacd8a97
commit 35476c9b25
11 changed files with 405 additions and 26 deletions

View File

@ -0,0 +1,60 @@
import os
import readline
import argparse
from datetime import datetime
import time
# Tab completion setup for file paths
def complete_path(text, state):
expanded = os.path.expanduser(os.path.expandvars(text))
if os.path.isdir(expanded):
try:
entries = os.listdir(expanded)
matches = [os.path.abspath(os.path.join(expanded, entry)) + '/'
if os.path.isdir(os.path.join(expanded, entry))
else os.path.abspath(os.path.join(expanded, entry))
for entry in entries]
except FileNotFoundError:
matches = []
else:
dirname = os.path.dirname(expanded) or '.'
basename = os.path.basename(expanded)
try:
entries = [entry for entry in os.listdir(dirname) if entry.startswith(basename)]
matches = [os.path.abspath(os.path.join(dirname, entry)) for entry in entries]
except FileNotFoundError:
matches = []
matches.sort()
try:
return matches[state]
except IndexError:
return None
readline.set_completer_delims(' \t\n;')
readline.set_completer(complete_path)
readline.parse_and_bind('tab: complete')
# Parse command-line arguments
parser = argparse.ArgumentParser(description="Write messages to a file.")
parser.add_argument("filename", nargs="?", help="Path to the file to write to.")
args = parser.parse_args()
# Ask for filename if not provided
file_path = args.filename or input("Enter filename: ")
# Message writing loop
name = "hi"
age = 30
max_iterations = 1000
try:
for i in range(max_iterations):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = "[{}] My name is {} and I am {} years old.\n".format(timestamp, name, age)
with open(file_path, "a") as file:
file.write(message)
time.sleep(1)
except KeyboardInterrupt:
print("\n[Interrupted] Ctrl+C detected. Stopped writing to file.")

View File

@ -0,0 +1,62 @@
import os
import readline
import argparse
from datetime import datetime
import time
# --- Tab Completion ---
def complete_path(text, state):
expanded = os.path.expanduser(os.path.expandvars(text))
if os.path.isdir(expanded):
try:
entries = os.listdir(expanded)
matches = [os.path.abspath(os.path.join(expanded, entry)) + '/'
if os.path.isdir(os.path.join(expanded, entry))
else os.path.abspath(os.path.join(expanded, entry))
for entry in entries]
except FileNotFoundError:
matches = []
else:
dirname = os.path.dirname(expanded) or '.'
basename = os.path.basename(expanded)
try:
entries = [entry for entry in os.listdir(dirname) if entry.startswith(basename)]
matches = [os.path.abspath(os.path.join(dirname, entry)) for entry in entries]
except FileNotFoundError:
matches = []
matches.sort()
try:
return matches[state]
except IndexError:
return None
readline.set_completer_delims(' \t\n;')
readline.set_completer(complete_path)
readline.parse_and_bind('tab: complete')
# --- Argument Parsing ---
parser = argparse.ArgumentParser(description="Write messages to a file with optional verbosity and interval.")
parser.add_argument("filename", nargs="?", help="Path to the file to write to.")
parser.add_argument("--verbose", action="store_true", help="Print each message to console.")
parser.add_argument("--interval", type=float, default=1.0, help="Delay between writes in seconds.")
args = parser.parse_args()
# --- Filename prompt fallback ---
file_path = args.filename or input("Enter filename: ")
# --- Message writing loop ---
name = "hi"
age = 30
max_iterations = 1000
try:
for i in range(max_iterations):
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = f"[{timestamp}] My name is {name} and I am {age} years old.\n"
with open(file_path, "a") as file:
file.write(message)
if args.verbose:
print(message.strip())
time.sleep(args.interval)
except KeyboardInterrupt:
print("\n[Interrupted] Ctrl+C detected. Stopped writing to file.")