Update and rename pyarmor_encoded_files.py to pyarmor_encoded_files.sh

This commit is contained in:
Stefan Pejcic 2024-11-05 18:40:40 +01:00 committed by GitHub
parent d4cdb9b696
commit e24b9706e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 69 additions and 33 deletions

View File

@ -1,33 +0,0 @@
import os
app_path = '/usr/local/panel'
def is_pyarmor_encoded(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as f:
first_line = f.readline()
return '# PyArmor' in first_line
except UnicodeDecodeError:
return True
def check_all_files_encoded():
unencoded_files = []
for root, dirs, files in os.walk(app_path):
for file in files:
if file.endswith('.py'):
file_path = os.path.join(root, file)
if not is_pyarmor_encoded(file_path):
unencoded_files.append(file_path)
return unencoded_files
unencoded_files = check_all_files_encoded()
if unencoded_files:
print("The following files are not encoded with PyArmor:")
for file in unencoded_files:
print(file)
else:
print("All Python files are properly encoded with PyArmor!")

View File

@ -0,0 +1,69 @@
#!/bin/bash
#############
# Function to set app_path based on the input attribute
set_app_path() {
case "$1" in
admin)
echo "/usr/local/admin"
;;
panel)
check_directory "/usr/local/panel/panel"
echo "/usr/local/panel/panel"
;;
*)
echo "Invalid attribute. Please use 'admin' or 'panel'."
exit 1
;;
esac
}
# Function to check if a file is encoded with PyArmor
is_pyarmor_encoded() {
local file_path="$1"
if [[ ! -f "$file_path" ]]; then
return 1
fi
# Read the first line of the file and check for PyArmor
read -r first_line < "$file_path"
[[ "$first_line" == *"# PyArmor"* ]]
}
# Function to check if directory exists
check_directory() {
local dir="$1"
if [[ ! -d "$dir" ]]; then
cd /root && docker compose up -d openpanel >/dev/null 2>&1
docker cp openpanel:/usr/local/panel /usr/local/panel >/dev/null 2>&1
fi
}
# Main script logic
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <admin|panel>"
exit 1
fi
# Set app_path based on user input
app_path=$(set_app_path "$1")
unencoded_files=()
# Traverse the app_path and check each .py file
while IFS= read -r -d '' file; do
if ! is_pyarmor_encoded "$file"; then
unencoded_files+=("$file")
fi
done < <(find "$app_path" -type f -name '*.py' -print0)
# Output the results
if [[ ${#unencoded_files[@]} -gt 0 ]]; then
echo -e "The following files are not encoded with PyArmor:"
for file in "${unencoded_files[@]}"; do
echo -e "- \e[31m$file\e[0m"
done
else
echo "✓ All Python files are properly encoded with PyArmor!"
fi