cleanup
This commit is contained in:
44
assets.py
44
assets.py
@@ -1,44 +0,0 @@
|
||||
import os
|
||||
|
||||
def initialize_assets(assets_dir, xp_file, level_file, session_log, total_time_file, questions_file):
|
||||
if not os.path.isdir(assets_dir):
|
||||
print(f"Assets directory not found: {assets_dir}")
|
||||
print("Please create the 'assets' folder and include the required files:")
|
||||
print("- questions.txt: Contains the questions")
|
||||
print("- xp.txt (optional): Tracks XP, default 0")
|
||||
print("- level.txt (optional): Tracks Level, default 1")
|
||||
print("- total_time.txt (optional): Tracks total session time, default 0")
|
||||
exit(1)
|
||||
|
||||
# Check required files
|
||||
if not os.path.isfile(xp_file):
|
||||
with open(xp_file, 'w') as f:
|
||||
f.write("0")
|
||||
if not os.path.isfile(level_file):
|
||||
with open(level_file, 'w') as f:
|
||||
f.write("1")
|
||||
if not os.path.isfile(session_log):
|
||||
open(session_log, 'w').close()
|
||||
if not os.path.isfile(total_time_file):
|
||||
with open(total_time_file, 'w') as f:
|
||||
f.write("0")
|
||||
if not os.path.isfile(questions_file):
|
||||
print(f"Questions file not found: {questions_file}")
|
||||
print("Please create 'questions.txt' in the 'assets' folder.")
|
||||
exit(1)
|
||||
print(f"Assets initialized in {assets_dir}")
|
||||
|
||||
def display_summary(total_time_file, xp_file, level_file):
|
||||
with open(total_time_file, 'r') as f:
|
||||
total_time = int(f.read().strip())
|
||||
with open(xp_file, 'r') as f:
|
||||
xp = int(f.read().strip())
|
||||
with open(level_file, 'r') as f:
|
||||
level = int(f.read().strip())
|
||||
hours = total_time // 60
|
||||
minutes = total_time % 60
|
||||
print("Welcome to the RHEL Learning Script!")
|
||||
print(f"Total session time: {hours} hours and {minutes} minutes.")
|
||||
print(f"Current Level: {level}")
|
||||
print(f"Current XP: {xp}")
|
||||
print()
|
||||
@@ -51,3 +51,6 @@ Session end: 2025-01-08 00:04:59
|
||||
Session start: 2025-01-08 00:11:09
|
||||
XP and level updated: 10 XP, Level 2
|
||||
Session end: 2025-01-08 00:11:34
|
||||
Session start: 2025-01-08 00:14:22
|
||||
XP and level updated: 5 XP, Level 2
|
||||
Session end: 2025-01-08 00:14:36
|
||||
|
||||
@@ -1 +1 @@
|
||||
10
|
||||
5
|
||||
140
rhel_learning.sh
140
rhel_learning.sh
@@ -1,140 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables
|
||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
||||
ASSETS_DIR="$SCRIPT_DIR/assets"
|
||||
XP_FILE="$ASSETS_DIR/xp.txt"
|
||||
LEVEL_FILE="$ASSETS_DIR/level.txt"
|
||||
SESSION_LOG="$ASSETS_DIR/session.log"
|
||||
QUESTIONS_FILE="$ASSETS_DIR/questions.txt"
|
||||
TOTAL_TIME_FILE="$ASSETS_DIR/total_time.txt"
|
||||
URL="https://rol.redhat.com"
|
||||
TIMER_MINUTES=20
|
||||
|
||||
# Ensure assets directory and files exist
|
||||
initialize_assets() {
|
||||
if [ ! -d "$ASSETS_DIR" ]; then
|
||||
echo "Assets directory not found: $ASSETS_DIR"
|
||||
echo "Please create the 'assets' folder and include the required files:"
|
||||
echo "- questions.txt: Contains the questions"
|
||||
echo "- xp.txt (optional): Tracks XP, default 0"
|
||||
echo "- level.txt (optional): Tracks Level, default 1"
|
||||
echo "- total_time.txt (optional): Tracks total session time, default 0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check required files
|
||||
[ ! -f "$XP_FILE" ] && echo "0" > "$XP_FILE"
|
||||
[ ! -f "$LEVEL_FILE" ] && echo "1" > "$LEVEL_FILE"
|
||||
[ ! -f "$SESSION_LOG" ] && touch "$SESSION_LOG"
|
||||
[ ! -f "$TOTAL_TIME_FILE" ] && echo "0" > "$TOTAL_TIME_FILE"
|
||||
if [ ! -f "$QUESTIONS_FILE" ]; then
|
||||
echo "Questions file not found: $QUESTIONS_FILE"
|
||||
echo "Please create 'questions.txt' in the 'assets' folder."
|
||||
exit 1
|
||||
fi
|
||||
echo "Assets initialized in $ASSETS_DIR"
|
||||
}
|
||||
|
||||
# Log session start and end
|
||||
log_session() {
|
||||
local action=$1
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
if [ "$action" == "start" ]; then
|
||||
echo "Session started: $timestamp" >> "$SESSION_LOG"
|
||||
elif [ "$action" == "end" ]; then
|
||||
echo "Session ended: $timestamp, Duration: $TIMER_MINUTES minutes" >> "$SESSION_LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
# Display session summary
|
||||
display_summary() {
|
||||
local total_time=$(cat "$TOTAL_TIME_FILE")
|
||||
local xp=$(cat "$XP_FILE")
|
||||
local level=$(cat "$LEVEL_FILE")
|
||||
local hours=$((total_time / 60))
|
||||
local minutes=$((total_time % 60))
|
||||
echo "Welcome to the RHEL Learning Script!"
|
||||
echo "Total session time: $hours hours and $minutes minutes."
|
||||
echo "Current Level: $level"
|
||||
echo "Current XP: $xp"
|
||||
echo
|
||||
}
|
||||
|
||||
# Function to kill Steam processes
|
||||
kill_steam() {
|
||||
while true; do
|
||||
steam_pids=$(ps aux | grep steam | grep -v grep | awk '{print $2}')
|
||||
if [ -n "$steam_pids" ]; then
|
||||
echo "Killing Steam processes..."
|
||||
sudo /bin/kill -9 $steam_pids || echo "Failed to kill Steam processes"
|
||||
fi
|
||||
sleep 5 # Check every 5 seconds
|
||||
done
|
||||
}
|
||||
|
||||
# Timer function with window focus
|
||||
show_timer() {
|
||||
echo "The session will last $TIMER_MINUTES minutes."
|
||||
|
||||
# Open the URL in Chromium
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
chromium "$URL" >/dev/null 2>&1 &
|
||||
sleep 2 # Allow the browser to open
|
||||
wmctrl -r ":ACTIVE:" -b add,above
|
||||
else
|
||||
echo "No graphical environment detected. Skipping browser opening."
|
||||
fi
|
||||
|
||||
# Open a new terminal window and run the secondary script
|
||||
gnome-terminal -- bash -c "$SCRIPT_DIR/timer_and_questions.sh $TIMER_MINUTES $QUESTIONS_FILE $SESSION_LOG; exec bash"
|
||||
|
||||
# Add session time to total
|
||||
local total_time=$(cat "$TOTAL_TIME_FILE")
|
||||
total_time=$((total_time + TIMER_MINUTES))
|
||||
echo "$total_time" > "$TOTAL_TIME_FILE"
|
||||
}
|
||||
|
||||
# XP and level-up system
|
||||
add_xp() {
|
||||
local xp=$(cat "$XP_FILE")
|
||||
local level=$(cat "$LEVEL_FILE")
|
||||
local new_xp=$((xp + 10))
|
||||
if ((new_xp >= level * 100)); then
|
||||
level=$((level + 1))
|
||||
echo "LEVEL UP! You are now Level $level!"
|
||||
new_xp=$((new_xp - (level - 1) * 100))
|
||||
fi
|
||||
echo "$new_xp" > "$XP_FILE"
|
||||
echo "$level" > "$LEVEL_FILE"
|
||||
echo "XP and level updated: $new_xp XP, Level $level" >> "$SESSION_LOG"
|
||||
}
|
||||
|
||||
# Handle script interruption
|
||||
trap 'echo "Script interrupted. Cleaning up..."; kill $STEAM_KILL_PID; wmctrl -r ":ACTIVE:" -b remove,above; exit 1' INT TERM
|
||||
|
||||
# Initialize assets
|
||||
initialize_assets
|
||||
|
||||
# Log session start
|
||||
log_session "start"
|
||||
|
||||
# Display session summary
|
||||
display_summary
|
||||
|
||||
# Start killing Steam processes in the background
|
||||
kill_steam &
|
||||
STEAM_KILL_PID=$!
|
||||
|
||||
# Start session
|
||||
echo "Starting RHEL Learning Session..."
|
||||
show_timer
|
||||
|
||||
# Add XP
|
||||
add_xp
|
||||
|
||||
# Stop killing Steam processes
|
||||
kill $STEAM_KILL_PID
|
||||
|
||||
# Log session end
|
||||
log_session "end"
|
||||
@@ -1,64 +0,0 @@
|
||||
# rhel_learning/rhel_learning/README.md
|
||||
|
||||
# RHEL Learning Project
|
||||
|
||||
This project is a Python-based learning tool designed to help users enhance their knowledge of Red Hat Enterprise Linux (RHEL). It includes a session management system, XP tracking, and a question-and-answer format to facilitate learning.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
rhel_learning
|
||||
├── src
|
||||
│ ├── main.py # Entry point of the application
|
||||
│ ├── assets
|
||||
│ │ ├── xp.txt # Tracks XP earned during sessions
|
||||
│ │ ├── level.txt # Tracks the current level of the user
|
||||
│ │ ├── session.log # Logs session start and end times
|
||||
│ │ ├── questions.txt # Contains questions for learning sessions
|
||||
│ │ └── total_time.txt # Tracks total session time
|
||||
│ ├── utils
|
||||
│ │ ├── __init__.py # Marks the utils directory as a package
|
||||
│ │ ├── assets.py # Functions for managing asset files
|
||||
│ │ ├── session.py # Functions for logging sessions
|
||||
│ │ ├── steam.py # Functions for managing Steam processes
|
||||
│ │ ├── timer.py # Functions for running the session timer
|
||||
│ │ └── xp.py # Functions for managing XP and level-ups
|
||||
├── requirements.txt # Lists dependencies for the project
|
||||
└── README.md # Documentation for the project
|
||||
```
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
1. Clone the repository:
|
||||
```
|
||||
git clone <repository-url>
|
||||
cd rhel_learning
|
||||
```
|
||||
|
||||
2. Install the required dependencies:
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Ensure that the `assets` directory contains the necessary files:
|
||||
- `questions.txt`: Contains the questions for the learning sessions.
|
||||
- `xp.txt`: Initialized to 0 if not present.
|
||||
- `level.txt`: Initialized to 1 if not present.
|
||||
- `total_time.txt`: Initialized to 0 if not present.
|
||||
|
||||
## Usage
|
||||
|
||||
To start the learning session, run the following command:
|
||||
```
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
This will initialize the assets, log the session start, display the session summary, start the timer, and manage the XP and level-up system.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License. See the LICENSE file for more details.
|
||||
@@ -1,4 +0,0 @@
|
||||
Flask==2.0.1
|
||||
psutil==5.8.0
|
||||
wmctrl==0.1.0
|
||||
PyQt5==5.15.4
|
||||
@@ -1,9 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
def log_session(session_log, action):
|
||||
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
with open(session_log, 'a') as f:
|
||||
if action == "start":
|
||||
f.write(f"Session started: {timestamp}\n")
|
||||
elif action == "end":
|
||||
f.write(f"Session ended: {timestamp}, Duration: 20 minutes\n")
|
||||
15
steam.py
15
steam.py
@@ -1,15 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
def kill_steam():
|
||||
while True:
|
||||
steam_pids = subprocess.check_output("ps aux | grep steam | grep -v grep | awk '{print $2}'", shell=True).decode().strip().split()
|
||||
if steam_pids:
|
||||
print("Killing Steam processes...")
|
||||
for pid in steam_pids:
|
||||
try:
|
||||
os.kill(int(pid), 9)
|
||||
except Exception as e:
|
||||
print(f"Failed to kill Steam process {pid}: {e}")
|
||||
time.sleep(5) # Check every 5 seconds
|
||||
28
timer.py
28
timer.py
@@ -1,28 +0,0 @@
|
||||
import time
|
||||
import random
|
||||
|
||||
def show_timer(timer_minutes, questions_file, session_log):
|
||||
seconds = timer_minutes * 60
|
||||
for i in range(1, seconds + 1):
|
||||
print(f"Time remaining: {seconds - i} seconds", end='\r')
|
||||
time.sleep(1)
|
||||
print("\nSession complete!")
|
||||
ask_random_question(questions_file, session_log)
|
||||
|
||||
def ask_random_question(questions_file, session_log):
|
||||
with open(questions_file, 'r') as f:
|
||||
questions = f.readlines()
|
||||
random_question = random.choice(questions).strip().split('|')
|
||||
question, opt1, opt2, opt3, correct = random_question
|
||||
print(question)
|
||||
print(f"1. {opt1}")
|
||||
print(f"2. {opt2}")
|
||||
print(f"3. {opt3}")
|
||||
answer = input("Choose an answer (1-3): ")
|
||||
with open(session_log, 'a') as f:
|
||||
if answer == correct:
|
||||
print("Correct answer!")
|
||||
f.write(f"{question}|Correct\n")
|
||||
else:
|
||||
print(f"Wrong answer. The correct option was: {correct}")
|
||||
f.write(f"{question}|Wrong\n")
|
||||
@@ -1,44 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
TIMER_MINUTES=$1
|
||||
QUESTIONS_FILE=$2
|
||||
SESSION_LOG=$3
|
||||
|
||||
# Timer function
|
||||
run_timer() {
|
||||
local seconds=$((TIMER_MINUTES * 60))
|
||||
for ((i = 1; i <= seconds; i++)); do
|
||||
echo -ne "Time remaining: $((seconds - i)) seconds\r"
|
||||
sleep 1
|
||||
done
|
||||
echo -e "\nSession complete!"
|
||||
}
|
||||
|
||||
# Function to display a random question
|
||||
ask_random_question() {
|
||||
mapfile -t questions < "$QUESTIONS_FILE"
|
||||
local random_index=$((RANDOM % ${#questions[@]}))
|
||||
IFS='|' read -r question opt1 opt2 opt3 correct <<<"${questions[random_index]}"
|
||||
echo "$question"
|
||||
echo "1. $opt1"
|
||||
echo "2. $opt2"
|
||||
echo "3. $opt3"
|
||||
local answer
|
||||
read -p "Choose an answer (1-3): " answer
|
||||
if [ "$answer" -eq "$correct" ]; then
|
||||
echo "Correct answer!"
|
||||
echo "$question|Correct" >> "$SESSION_LOG"
|
||||
else
|
||||
echo "Wrong answer. The correct option was: $correct"
|
||||
echo "$question|Wrong" >> "$SESSION_LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run the timer
|
||||
run_timer
|
||||
|
||||
# Ask a random question
|
||||
ask_random_question
|
||||
|
||||
# Wait for user input to close the terminal
|
||||
read -p "Press Enter to close..."
|
||||
16
xp.py
16
xp.py
@@ -1,16 +0,0 @@
|
||||
def add_xp(xp_file, level_file, session_log):
|
||||
with open(xp_file, 'r') as f:
|
||||
xp = int(f.read().strip())
|
||||
with open(level_file, 'r') as f:
|
||||
level = int(f.read().strip())
|
||||
new_xp = xp + 10
|
||||
if new_xp >= level * 100:
|
||||
level += 1
|
||||
print(f"LEVEL UP! You are now Level {level}!")
|
||||
new_xp -= (level - 1) * 100
|
||||
with open(xp_file, 'w') as f:
|
||||
f.write(str(new_xp))
|
||||
with open(level_file, 'w') as f:
|
||||
f.write(str(level))
|
||||
with open(session_log, 'a') as f:
|
||||
f.write(f"XP and level updated: {new_xp} XP, Level {level}\n")
|
||||
Reference in New Issue
Block a user