v0.3.3 update

pull/45/head v0.3.3
Mason10198 2 years ago
parent cb81c6c6ee
commit afc9875c74

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
""" """
SkyControl v0.3.2 by Mason Nelson SkyControl v0.3.3 by Mason Nelson
================================== ==================================
A Control Script for SkywarnPlus A Control Script for SkywarnPlus

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
""" """
SkyDescribe v0.3.2 by Mason Nelson SkyDescribe v0.3.3 by Mason Nelson
================================================== ==================================================
Text to Speech conversion for Weather Descriptions Text to Speech conversion for Weather Descriptions

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
""" """
SkywarnPlus v0.3.2 by Mason Nelson SkywarnPlus v0.3.3 by Mason Nelson
=============================================================================== ===============================================================================
SkywarnPlus is a utility that retrieves severe weather alerts from the National SkywarnPlus is a utility that retrieves severe weather alerts from the National
Weather Service and integrates these alerts with an Asterisk/app_rpt based Weather Service and integrates these alerts with an Asterisk/app_rpt based

@ -1,7 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
""" """
SkywarnPlus Updater v0.3.2 by Mason Nelson SkywarnPlus Updater v0.3.3 by Mason Nelson
=============================================================================== ===============================================================================
Script to update SkywarnPlus to the latest version. This script will download Script to update SkywarnPlus to the latest version. This script will download
the latest version of SkywarnPlus from GitHub, and then merge the existing the latest version of SkywarnPlus from GitHub, and then merge the existing
@ -31,20 +31,28 @@ from ruamel.yaml import YAML
import argparse import argparse
# Set up command line arguments # Set up command line arguments
parser = argparse.ArgumentParser(description="Update SkywarnPlus script.") parser = argparse.ArgumentParser(description="Update SkywarnPlus")
parser.add_argument("-f", "--force", help="Force update without confirmation prompt", action="store_true") parser.add_argument(
"-f",
"--force",
help="Force update without confirmation prompt",
action="store_true",
)
args = parser.parse_args() args = parser.parse_args()
# Logging function # Logging function
def log(message): def log(message):
print("[UPDATE]:", message) print("[UPDATE]:", message)
# Function to load a yaml file # Function to load a yaml file
def load_yaml_file(filename): def load_yaml_file(filename):
yaml = YAML() yaml = YAML()
with open(filename, "r") as f: with open(filename, "r") as f:
return yaml.load(f) return yaml.load(f)
# Function to save a yaml file # Function to save a yaml file
def save_yaml_file(filename, data): def save_yaml_file(filename, data):
yaml = YAML() yaml = YAML()
@ -52,6 +60,7 @@ def save_yaml_file(filename, data):
with open(filename, "w") as f: with open(filename, "w") as f:
yaml.dump(data, f) yaml.dump(data, f)
# Function to merge two yaml files # Function to merge two yaml files
def merge_yaml_files(old_file, new_file): def merge_yaml_files(old_file, new_file):
# Load the old and new yaml files # Load the old and new yaml files
@ -61,7 +70,9 @@ def merge_yaml_files(old_file, new_file):
# Merge the new yaml file with values from the old file # Merge the new yaml file with values from the old file
for key in new_yaml_data: for key in new_yaml_data:
if key in old_yaml_data: if key in old_yaml_data:
if isinstance(new_yaml_data[key], dict) and isinstance(old_yaml_data[key], dict): if isinstance(new_yaml_data[key], dict) and isinstance(
old_yaml_data[key], dict
):
new_yaml_data[key].update(old_yaml_data[key]) new_yaml_data[key].update(old_yaml_data[key])
else: else:
new_yaml_data[key] = old_yaml_data[key] new_yaml_data[key] = old_yaml_data[key]
@ -69,13 +80,14 @@ def merge_yaml_files(old_file, new_file):
# Save the merged yaml data back to the new file # Save the merged yaml data back to the new file
save_yaml_file(new_file, new_yaml_data) save_yaml_file(new_file, new_yaml_data)
def remove_duplicate_comments(filename): def remove_duplicate_comments(filename):
# Keep track of the last comment block # Keep track of the last comment block
last_comment_block = [] last_comment_block = []
new_lines = [] new_lines = []
# Read the file line by line # Read the file line by line
with open(filename, 'r') as f: with open(filename, "r") as f:
lines = f.readlines() lines = f.readlines()
current_comment_block = [] current_comment_block = []
@ -83,7 +95,7 @@ def remove_duplicate_comments(filename):
stripped_line = line.strip() stripped_line = line.strip()
# If line is a comment or blank, it's part of the current block # If line is a comment or blank, it's part of the current block
if stripped_line.startswith('#') or not stripped_line: if stripped_line.startswith("#") or not stripped_line:
current_comment_block.append(line) current_comment_block.append(line)
else: else:
if current_comment_block: if current_comment_block:
@ -98,25 +110,33 @@ def remove_duplicate_comments(filename):
new_lines.extend(current_comment_block) new_lines.extend(current_comment_block)
# Write the new lines back to the file # Write the new lines back to the file
with open(filename, 'w') as f: with open(filename, "w") as f:
f.writelines(new_lines) f.writelines(new_lines)
# Check for root privileges # Check for root privileges
if os.geteuid() != 0: if os.geteuid() != 0:
exit("ERROR: This script must be run as root.") exit("ERROR: This script must be run as root.")
# Make sure the script is in the right directory # Make sure the script is in the right directory
if not os.path.isfile('SkywarnPlus.py'): if not os.path.isfile("SkywarnPlus.py"):
print('ERROR: Cannot find SkywarnPlus.py. Make sure this script is in the SkywarnPlus directory.') print(
"ERROR: Cannot find SkywarnPlus.py. Make sure this script is in the SkywarnPlus directory."
)
exit() exit()
# Prompt for confirmation unless -f flag is present # Prompt for confirmation unless -f flag is present
if not args.force: if not args.force:
print("\nThis script will update SkywarnPlus to the latest version.") print("\nThis script will update SkywarnPlus to the latest version.")
print("It will create a backup of the existing SkywarnPlus directory before updating.") print(
print("Be aware that if you've made significant changes to the code or directory structure, this may cause issues.") "It will create a backup of the existing SkywarnPlus directory before updating."
)
print(
"Be aware that if you've made significant changes to the code or directory structure, this may cause issues."
)
print("If you've made significant changes, it is recommended to update manually.\n") print("If you've made significant changes, it is recommended to update manually.\n")
confirmation = input("Do you want to continue with the update? (yes/no) ") print("ALWAYS DOUBLE CHECK YOUR CONFIG.YAML AFTER UPDATING! This script is not perfect and may not merge your config.yaml correctly.\n")
confirmation = input("\nDo you want to continue with the update? (yes/no) ")
if confirmation.lower() != "yes": if confirmation.lower() != "yes":
log("Update cancelled by user.") log("Update cancelled by user.")
exit() exit()
@ -126,29 +146,31 @@ root_dir = os.getcwd()
log("Current directory is {}".format(root_dir)) log("Current directory is {}".format(root_dir))
# Full path to the archive # Full path to the archive
zip_name = root_dir + '_backup_' + datetime.datetime.now().strftime('%Y%m%d_%H%M') zip_name = root_dir + "_backup_" + datetime.datetime.now().strftime("%Y%m%d_%H%M")
log("Creating backup at {}.zip...".format(zip_name)) log("Creating backup at {}.zip...".format(zip_name))
# Create the zip archive # Create the zip archive
shutil.make_archive(zip_name, 'zip', root_dir) shutil.make_archive(zip_name, "zip", root_dir)
# Download the new zip from GitHub # Download the new zip from GitHub
url = 'https://github.com/Mason10198/SkywarnPlus/releases/latest/download/SkywarnPlus.zip' url = (
"https://github.com/Mason10198/SkywarnPlus/releases/latest/download/SkywarnPlus.zip"
)
log("Downloading SkywarnPlus from {}...".format(url)) log("Downloading SkywarnPlus from {}...".format(url))
response = requests.get(url) response = requests.get(url)
with open('/tmp/SkywarnPlus.zip', 'wb') as out_file: with open("/tmp/SkywarnPlus.zip", "wb") as out_file:
out_file.write(response.content) out_file.write(response.content)
# Delete /tmp/SkywarnPlus if it already exists # Delete /tmp/SkywarnPlus if it already exists
if os.path.isdir('/tmp/SkywarnPlus'): if os.path.isdir("/tmp/SkywarnPlus"):
log("Removing old /tmp/SkywarnPlus directory...") log("Removing old /tmp/SkywarnPlus directory...")
shutil.rmtree('/tmp/SkywarnPlus') shutil.rmtree("/tmp/SkywarnPlus")
# Unzip the downloaded file # Unzip the downloaded file
log("Extracting SkywarnPlus.zip...") log("Extracting SkywarnPlus.zip...")
with zipfile.ZipFile('/tmp/SkywarnPlus.zip', 'r') as zip_ref: with zipfile.ZipFile("/tmp/SkywarnPlus.zip", "r") as zip_ref:
zip_ref.extractall('/tmp') zip_ref.extractall("/tmp")
# Merge the old config with the new config # Merge the old config with the new config
log("Merging old config with new config...") log("Merging old config with new config...")
@ -159,10 +181,10 @@ remove_duplicate_comments("/tmp/SkywarnPlus/config.yaml")
# Replace old directory with updated files # Replace old directory with updated files
log("Merging updated files into {}...".format(root_dir)) log("Merging updated files into {}...".format(root_dir))
for root, dirs, files in os.walk('/tmp/SkywarnPlus'): for root, dirs, files in os.walk("/tmp/SkywarnPlus"):
for file in files: for file in files:
old_file_path = os.path.join(root, file) old_file_path = os.path.join(root, file)
relative_path = os.path.relpath(old_file_path, '/tmp/SkywarnPlus') relative_path = os.path.relpath(old_file_path, "/tmp/SkywarnPlus")
new_file_path = os.path.join(root_dir, relative_path) new_file_path = os.path.join(root_dir, relative_path)
os.makedirs(os.path.dirname(new_file_path), exist_ok=True) os.makedirs(os.path.dirname(new_file_path), exist_ok=True)
@ -172,17 +194,17 @@ for root, dirs, files in os.walk('/tmp/SkywarnPlus'):
log("Setting .py files as executable...") log("Setting .py files as executable...")
for dirpath, dirs, files in os.walk(root_dir): for dirpath, dirs, files in os.walk(root_dir):
for filename in files: for filename in files:
if filename.endswith('.py'): if filename.endswith(".py"):
os.chmod(os.path.join(dirpath, filename), 0o755) # chmod +x os.chmod(os.path.join(dirpath, filename), 0o755) # chmod +x
# Delete temporary files and folders # Delete temporary files and folders
log("Deleting temporary files and folders...") log("Deleting temporary files and folders...")
shutil.rmtree('/tmp/SkywarnPlus') shutil.rmtree("/tmp/SkywarnPlus")
os.remove('/tmp/SkywarnPlus.zip') os.remove("/tmp/SkywarnPlus.zip")
# Delete old TmpDir if it still exists # Delete old TmpDir if it still exists
if os.path.isdir("/tmp/SkywarnPlus"): if os.path.isdir("/tmp/SkywarnPlus"):
log("Removing old /tmp/SkywarnPlus directory...") log("Removing old /tmp/SkywarnPlus directory...")
shutil.rmtree("/tmp/SkywarnPlus") shutil.rmtree("/tmp/SkywarnPlus")
log("Update complete!") log("Update complete!")

@ -1,4 +1,4 @@
# SkywarnPlus v0.3.2 Configuration File # SkywarnPlus v0.3.3 Configuration File
# Author: Mason Nelson (N5LSN/WRKF394) # Author: Mason Nelson (N5LSN/WRKF394)
# Please edit this file according to your specific requirements. # Please edit this file according to your specific requirements.
@ -46,7 +46,7 @@ Alerting:
SayAlert: true SayAlert: true
# Specify a WAV file in the root of the SOUNDS directory to be appended to the end of the alert message. # Specify a WAV file in the root of the SOUNDS directory to be appended to the end of the alert message.
#SayAlertSuffix: SayAlertSuffix:
# Enable instant voice announcement when weather alerts are cleared. # Enable instant voice announcement when weather alerts are cleared.
# Set to 'True' for enabling or 'False' for disabling. # Set to 'True' for enabling or 'False' for disabling.
@ -55,11 +55,11 @@ Alerting:
# Limit the maximum number of alerts to process in case of multiple alerts. # Limit the maximum number of alerts to process in case of multiple alerts.
# SkywarnPlus fetches all alerts, orders them by severity, and processes only the 'n' most severe alerts, where 'n' is the MaxAlerts value. # SkywarnPlus fetches all alerts, orders them by severity, and processes only the 'n' most severe alerts, where 'n' is the MaxAlerts value.
#MaxAlerts: 5 MaxAlerts: 99
# Specify an alternative path to the directory where sound files are located. # Specify an alternative path to the directory where sound files are located.
# Default is SkywarnPlus/SOUNDS. # Default is SkywarnPlus/SOUNDS.
#SoundsPath: SoundsPath: /usr/local/bin/SkywarnPlus/SOUNDS
# 'TimeType' Configuration # 'TimeType' Configuration
# #
@ -108,11 +108,11 @@ Tailmessage:
Enable: false Enable: false
# Specify a WAV file in the root of the SOUNDS directory to be appended to the end of the tail message. # Specify a WAV file in the root of the SOUNDS directory to be appended to the end of the tail message.
#TailmessageSuffix: TailmessageSuffix:
# Specify an alternative path and filename for saving the tail message. # Specify an alternative path and filename for saving the tail message.
# Default is /tmp/SkywarnPlus/wx-tail.wav. # Default is /tmp/SkywarnPlus/wx-tail.wav.
#TailmessagePath: TailmessagePath: /tmp/SkywarnPlus/wx-tail.wav
################################################################################################################################ ################################################################################################################################
@ -124,7 +124,7 @@ CourtesyTones:
# Specify an alternative directory where tone files are located. # Specify an alternative directory where tone files are located.
# Default is SkywarnPlus/SOUNDS/TONES. # Default is SkywarnPlus/SOUNDS/TONES.
#ToneDir: ToneDir: /usr/local/bin/SkywarnPlus/SOUNDS/TONES
# Define the sound files for courtesy tones. # Define the sound files for courtesy tones.
Tones: Tones:
@ -188,7 +188,7 @@ IDChange:
# Specify an alternative directory where ID files are located. # Specify an alternative directory where ID files are located.
# Default is SkywarnPlus/SOUNDS/ID. # Default is SkywarnPlus/SOUNDS/ID.
#IDDir: IDDir: /usr/local/bin/SkywarnPlus/SOUNDS/ID
# Define the sound files for IDs. # Define the sound files for IDs.
IDs: IDs:
@ -244,7 +244,7 @@ SkyDescribe:
# MAKE SURE YOU VERIFY YOUR EMAIL ADDRESS WITH VOICERSS.ORG OR YOUR API KEY WILL NOT WORK. # MAKE SURE YOU VERIFY YOUR EMAIL ADDRESS WITH VOICERSS.ORG OR YOUR API KEY WILL NOT WORK.
# API Key for VoiceRSS.org # API Key for VoiceRSS.org
APIKey: APIKey: YOUR_API_KEY_HERE
# VoiceRSS language code # VoiceRSS language code
Language: en-us Language: en-us
@ -350,10 +350,10 @@ Pushover:
Enable: false Enable: false
# Provide your user key obtained from Pushover. # Provide your user key obtained from Pushover.
UserKey: UserKey: YOUR_USER_KEY_HERE
# Provide the API token obtained from Pushover. # Provide the API token obtained from Pushover.
APIToken: APIToken: YOUR_API_KEY_HERE
# Enable verbose messaging # Enable verbose messaging
Debug: false Debug: false
@ -367,7 +367,7 @@ Logging:
Debug: false Debug: false
# Specify an alternative log file path. # Specify an alternative log file path.
#LogPath: LogPath: /tmp/SkywarnPlus.log
################################################################################################################################ ################################################################################################################################

Loading…
Cancel
Save

Powered by TurnKey Linux.