test macro

main
vitrinekast 8 months ago
parent 893e5ddce3
commit af0f985b59

@ -24,6 +24,7 @@ def run_command(command, based = False):
result = subprocess.run(command, capture_output=True, input=based) result = subprocess.run(command, capture_output=True, input=based)
result.check_returncode() result.check_returncode()
stripped = result.stdout.decode('UTF-8').strip() stripped = result.stdout.decode('UTF-8').strip()
if "No entries" in stripped: if "No entries" in stripped:
return "" return ""
else: else:
@ -32,6 +33,7 @@ def run_command(command, based = False):
# Run all the commands for getting the logs, and assign to variables # Run all the commands for getting the logs, and assign to variables
print("start running the log commands"); print("start running the log commands");
last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True) last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True)
last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout) last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout)
users_created_today = run_command(["sudo", "journalctl", "-S","today","_COMM=useradd","-r","--output-fields=MESSAGE"]).splitlines() users_created_today = run_command(["sudo", "journalctl", "-S","today","_COMM=useradd","-r","--output-fields=MESSAGE"]).splitlines()
@ -98,8 +100,7 @@ print("Output the files");
# Export the html as book.html, which is used as an input for pandoc # Export the html as book.html, which is used as an input for pandoc
with open("/home/xpub/www/html/tl-dr/book.html", "w") as f: with open("/home/xpub/www/html/tl-dr/book.html", "w") as f:
print(output, file=f) print(output, file=f)
print("execute the bash script now to create the books"); subprocess.run(['sh', '/home/xpub/www/html/tl-dr/create_book.sh', book_name])
subprocess.run(['sh', 'create_book.sh', book_name])
print("Finished"); print("Finished");
# At the moment, we are not storing logs in the log folder anymore # At the moment, we are not storing logs in the log folder anymore

@ -24,6 +24,16 @@
<body> <body>
{% macro log_output(logs) -%}
{% if logs|length > 0 %}
<ul>
{% for item in logs %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endif %}
{%- endmacro %}
<article> <article>
<h1>Debug fiesta!</h1> <h1>Debug fiesta!</h1>
<pre> <pre>
@ -107,26 +117,23 @@ user_deleted : {{ user_deleted }}
%} %}
</mark> </mark>
{% endif %} {% endif %}
<p><em>tldr@chopchop:~ $</em>sudo journalctl -S today _COMM=useradd -r</p>
<mark>
Users are assigned to groups, which allow them rights to read or edit files, run commands or apply infrastructural
changes. For chopchop, we all have 'sudo rights': the ability to perform any command, including the more sensitive
ones. Sudo is a command that's short for 'superuser do', with it, a user has more privileges, like installing or
updating a package or performing a restart.
</mark>
{% if users_created_today is defined %} {% if users_created_today is defined %}
<mark> <p><em>tldr@chopchop:~ $</em>sudo journalctl -S today _COMM=useradd -r</p>
<mark>
Users are assigned to groups, which allow them rights to read or edit files, run commands or apply infrastructural
changes. For chopchop, we all have 'sudo rights': the ability to perform any command, including the more sensitive
ones. Sudo is a command that's short for 'superuser do', with it, a user has more privileges, like installing or
updating a package or performing a restart.
</mark>
{{ log_output(users_created_today) }}
{% if users_created_today|length > 0 %} {% if users_created_today|length > 0 %}
{{last_user_name}} user was added, and the network of trust grew ever so slightly. Users will be trusted with not <mark> {{last_user_name}} user was added, and the network of trust grew ever so slightly. Users will be trusted with not just the keys and passwords to the "house" which is the server, but with a portion of responsibility to keep it afloat and contribute to what makes it a community of practices (and network of knowledge and dependence).</mark>
just the keys and passwords to the "house" which is the server, but with a portion of responsibility to keep it
afloat and contribute to what makes it a community of practices (and network of knowledge and dependence).
{% else %} {% else %}
No new users were created today. The trust network remains the same size. <mark>No new users were created today. The trust network remains the same size.</mark>
{% endif %} {% endif %}
</mark>
{% endif %} {% endif %}
{% if list_package_installs|length > 0 %} {% if list_package_installs|length > 0 %}
@ -135,11 +142,8 @@ user_deleted : {{ user_deleted }}
<mark> <mark>
Today the following packages were installed: Today the following packages were installed:
</mark> </mark>
<ul>
{% for item in list_package_installs %} {{ log_output(list_package_installs) }}
<li>{{ item }}</li>
{% endfor %}
</ul>
<mark> <mark>
Packages are often installed to use different software or coding languages or build alternative tools. Often Packages are often installed to use different software or coding languages or build alternative tools. Often
users have to talk about and consider which packages they need and why, as well as how much storage they take up users have to talk about and consider which packages they need and why, as well as how much storage they take up

Loading…
Cancel
Save