Add plays end_metrics.yml and reboot_test3.yml; Add script write_file_msg.py; Update hosts
This commit is contained in:
66
scripts/write_file_msg.py
Executable file
66
scripts/write_file_msg.py
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/python3
|
||||
import time
|
||||
import os
|
||||
import readline
|
||||
from datetime import datetime
|
||||
|
||||
# Changable optonis:
|
||||
message = "Testing testing testing..."
|
||||
max_iterations = 5
|
||||
|
||||
|
||||
# Autocomplete path stuffs:
|
||||
def complete_path(text, state):
|
||||
expanded = os.path.expanduser(os.path.expandvars(text))
|
||||
|
||||
if os.path.isdir(expanded):
|
||||
try:
|
||||
entries = os.listdir(expanded)
|
||||
completion_list = [
|
||||
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:
|
||||
completion_list = []
|
||||
else:
|
||||
dirname = os.path.dirname(expanded)
|
||||
basename = os.path.basename(expanded)
|
||||
|
||||
if not dirname:
|
||||
dirname = '.'
|
||||
|
||||
try:
|
||||
entries = [entry for entry in os.listdir(dirname) if entry.startswith(basename)]
|
||||
completion_list = [
|
||||
os.path.abspath(os.path.join(dirname, entry))
|
||||
for entry in entries
|
||||
]
|
||||
except FileNotFoundError:
|
||||
completion_list = []
|
||||
|
||||
completion_list.sort()
|
||||
try:
|
||||
return completion_list[state]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
readline.set_completer_delims(' \t\n;')
|
||||
readline.set_completer(complete_path)
|
||||
readline.parse_and_bind("tab: complete")
|
||||
|
||||
file_path = input("File to write to: ")
|
||||
|
||||
try:
|
||||
for i in range(max_iterations):
|
||||
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
tm = "{} -- {}: itr=>{}".format(ts, message, i)
|
||||
print(f"{file_path} -> {tm}")
|
||||
|
||||
with open(file_path, "a") as file:
|
||||
file.write(tm + '\n')
|
||||
|
||||
time.sleep(.2)
|
||||
except KeyboardInterrupt:
|
||||
print("Ctrl-C hit; exiting...")
|
Reference in New Issue
Block a user