Skip to content

Commit

Permalink
Merge pull request #6 from mikecarr/next
Browse files Browse the repository at this point in the history
Merge next to master
  • Loading branch information
mikecarr authored Oct 4, 2024
2 parents 67ea545 + eda88a0 commit e64ef96
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 66 deletions.
11 changes: 11 additions & 0 deletions .vscode/sftp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Radxa Zero 3E",
"host": "10.0.1.14",
"protocol": "sftp",
"port": 22,
"username": "root",
"remotePath": "/root/workspace/py_config_gs",
"uploadOnSave": false,
"useTempFile": false,
"openSsh": false
}
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include py_config_gs/settings.json
include py_config_gs/py-config-gs.json
recursive-include systemd *
recursive-include py_config_gs/templates *
recursive-include py_config_gs/static *
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ pip install .
or
python setup.py install
```
## config file
```
cp /usr/local/lib/python3.9/dist-packages/config/settings.json /config
cp /usr/local/lib/python3.9/dist-packages/config/py-config-gs.json /config
cp /usr/local/lib/python3.9/dist-packages/etc/systemd/system/py-config-gs.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start py-config-gs
# Optional, you can always run the command above out in the field if you are worried about resource consumption
sudo systemctl enable py-config-gs
```

Expand Down
Binary file modified images/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* Pixelpilot updates
sudo service openipc stop # sudo systemctl start openipc.service
sudo curl -fsSL https://github.com/OpenIPC/PixelPilot_rk/releases/download/latest/pixelpilot -o /usr/local/bin/pixelpilot
sudo chmod +x /usr/local/bin/pixelpilot
79 changes: 65 additions & 14 deletions py_config_gs/app.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import logging
from flask import Flask, render_template, request, Response, redirect, url_for, send_from_directory
from flask import Flask, render_template, request, Response, redirect, url_for, send_from_directory, flash
import json
import os
import subprocess
from importlib.metadata import version


app_version = version('py-config-gs')
#app_version = version('py-config-gs')
with open('version.txt', 'r') as f:
app_version = f.read().strip()


# Configure logging
logging.basicConfig(level=logging.DEBUG, # Set the log level to DEBUG
format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

app = Flask(__name__)
app.secret_key = os.getenv('SECRET_KEY', 'default_secret_key')

#SETTINGS_FILE = "/Users/mcarr/config/settings.json"
#SETTINGS_FILE = "/config/settings.json"
if os.getenv('FLASK_ENV') == 'development':
# In development, use the home folder settings file
SETTINGS_FILE = os.path.expanduser('~/config/settings.json')
SETTINGS_FILE = os.path.expanduser('~/config/py-config-gs.json')
else:
# In production, use the config folder
SETTINGS_FILE = '/config/settings.json'
SETTINGS_FILE = '/config/py-config-gs.json'

# Log the SETTINGS_FILE path
logger.info(f'Settings file path: {SETTINGS_FILE}')
Expand Down Expand Up @@ -58,15 +60,26 @@ def stream_journal():

@app.route('/journal')
def journal():
return render_template('journal.html')
return render_template('journal.html', version=app_version)

@app.route('/stream')
def stream():
return Response(stream_journal(), content_type='text/event-stream')

@app.route('/')
def home():
return render_template('home.html', config_files=config_files, version=app_version)
# List of services that you want to control
services = ['openipc']
service_statuses = {}

# Fetches the current status (enabled/disabled) for each service.
for service in services:
# Check if the service is enabled or disabled
result = subprocess.run(['systemctl', 'is-enabled', service], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
status = result.stdout.decode('utf-8').strip()
service_statuses[service] = status

return render_template('home.html', config_files=config_files, version=app_version, services=service_statuses )

@app.route('/edit/<filename>', methods=['GET', 'POST'])
def edit(filename):
Expand All @@ -82,7 +95,7 @@ def edit(filename):
with open(file_path, 'r') as f:
content = f.read()

return render_template('edit.html', filename=filename, content=content)
return render_template('edit.html', filename=filename, content=content, version=app_version)

@app.route('/save/<filename>', methods=['POST'])
def save(filename):
Expand All @@ -98,7 +111,7 @@ def videos():
video_files = [f for f in os.listdir(VIDEO_DIR) if f.endswith(('.mp4', '.mkv', '.avi'))]
logger.debug(f'VIDEO_DIR: {VIDEO_DIR}')
logger.debug(f'Video files found: {video_files}')
return render_template('videos.html', video_files=video_files)
return render_template('videos.html', video_files=video_files, version=app_version)


@app.route('/play/<filename>')
Expand All @@ -119,10 +132,10 @@ def get_temperature():
gpu_temp_f = (gpu_temp * 9/5) + 32

return {
'soc_temperature': f"{soc_temp:.1f} °C",
'soc_temperature_f': f"{soc_temp_f:.1f} °F",
'gpu_temperature': f"{gpu_temp:.1f} °C",
'gpu_temperature_f': f"{gpu_temp_f:.1f} °F"
'soc_temperature': f"{soc_temp:.1f}",
'soc_temperature_f': f"{soc_temp_f:.1f}",
'gpu_temperature': f"{gpu_temp:.1f}",
'gpu_temperature_f': f"{gpu_temp_f:.1f}"
}

except Exception as e:
Expand All @@ -141,6 +154,44 @@ def backup():
logger.debug('Backup created for configuration files.')
return redirect(url_for('home'))

@app.route('/run_command', methods=['POST'])
def run_command():
selected_command = request.form.get('command')

# Construct the first command based on the dropdown value
cli_command = f"echo cli -s {selected_command} > /dev/udp/localhost/14550"
logger.debug(f'Running command: {cli_command}')

# Run the commands
subprocess.run(cli_command, shell=True)
subprocess.run("echo killall -1 majestic > /dev/udp/localhost/14550", shell=True)

# Redirect back to the home page after the commands are run
return redirect(url_for('home'))

@app.route('/service_action', methods=['POST'])
def service_action():
service_name = request.form.get('service_name')
action = request.form.get('action')

if service_name and action:
try:
if action == 'enable':
subprocess.run(['sudo', 'systemctl', 'enable', service_name], check=True)
flash(f'Service {service_name} enabled successfully.', 'success')
elif action == 'disable':
subprocess.run(['sudo', 'systemctl', 'disable', service_name], check=True)
flash(f'Service {service_name} disabled successfully.', 'success')
elif action == 'restart':
subprocess.run(['sudo', 'systemctl', 'restart', service_name], check=True)
flash(f'Service {service_name} restarted successfully.', 'success')
else:
flash('Invalid action.', 'error')
except subprocess.CalledProcessError as e:
flash(f'Failed to {action} service {service_name}: {e}', 'error')

return redirect(url_for('home'))

def main():
app.run(host='0.0.0.0', port=SERVER_PORT)

Expand Down
File renamed without changes.
92 changes: 85 additions & 7 deletions py_config_gs/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ body {
background-color: #f4f4f4;
}

h1, h2 {
h1,
h2 {
color: #333;
}

Expand Down Expand Up @@ -86,12 +87,6 @@ p {
}

/* Footer Styles */
/* footer {
margin-top: 20px;
text-align: center;
font-size: 0.8em;
color: #666;
} */
footer {
position: fixed;
bottom: 0;
Expand All @@ -100,3 +95,86 @@ footer {
text-align: center;
padding: 10px;
}

/* Styled Box */
.styled-box {
border: 1px solid #ccc;
background-color: #f0f0f0;
padding: 10px;
margin: 15px 0;
border-radius: 5px;
font-family: Arial, sans-serif;
}

/* Warning Styles */
.warning {
color: red;
font-weight: bold;
font-style: italic;
margin-bottom: 20px;
}

/* Table Styles */
table {
width: 100%; /* Make the table take full width */
border-collapse: collapse;
margin: 20px 0;
font-size: 16px;
}

table th, table td {
padding: 15px; /* Increase padding for more space inside cells */
text-align: left;
border: 1px solid #ddd;
}

table th {
background-color: #f2f2f2;
font-weight: bold;
}

table th:nth-child(1),
table td:nth-child(1) {
width: 30%; /* Service column */
}

table th:nth-child(2),
table td:nth-child(2) {
width: 20%; /* Status column */
}

table th:nth-child(3),
table td:nth-child(3) {
width: 50%; /* Actions column */
}

/* Status Styles */
.status-enabled {
color: green;
font-weight: bold;
}

.status-disabled {
color: red;
font-weight: bold;
}

/* Button Styles */
button {
padding: 8px 12px; /* Increase button size */
margin: 0 5px;
border: none;
cursor: pointer;
background-color: #007bff;
color: white;
border-radius: 4px;
}

button[type="submit"]:hover {
background-color: #0056b3;
}

/* Form Styles */
form {
display: inline;
}
2 changes: 1 addition & 1 deletion py_config_gs/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}My Flask App{% endblock %}</title>
<title>{% block title %}Py-Config-GS{% endblock %}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</head>
<body>
Expand Down
4 changes: 4 additions & 0 deletions py_config_gs/templates/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

{% block content %}
<div class="content">
<div class="warning">
WARNING: YOU ARE RESPONSIBLE FOR ANY CHANGES YOU MAKE, ALWAYS MAKE SURE YOU HAVE A BACKUP
</div>

<h2>Edit Configuration File: {{ filename }}</h2>
<form method="POST">
<textarea name="content" rows="20" cols="80">{{ content }}</textarea><br>
Expand Down
Loading

0 comments on commit e64ef96

Please sign in to comment.