Merge pull request #147 from ReturnFI/beta

Refactor QR code generation to use Python
This commit is contained in:
Whispering Wind
2025-05-13 23:49:38 +03:30
committed by GitHub
3 changed files with 15 additions and 12 deletions

View File

@ -12,8 +12,6 @@ updates:
commit-message: commit-message:
prefix: "chore" prefix: "chore"
include: "scope" include: "scope"
reviewers:
- "ReturnFI"
labels: labels:
- "dependencies" - "dependencies"
- "python" - "python"

View File

@ -6,6 +6,8 @@ import json
import subprocess import subprocess
import argparse import argparse
import re import re
import qrcode
from io import StringIO
from typing import Tuple, Optional, Dict, List, Any from typing import Tuple, Optional, Dict, List, Any
from init_paths import * from init_paths import *
from paths import * from paths import *
@ -83,17 +85,20 @@ def generate_uri(username: str, auth_password: str, ip: str, port: str,
return f"{uri_base}?{params_str}#{username}-IPv{ip_version}" return f"{uri_base}?{params_str}#{username}-IPv{ip_version}"
def generate_qr_code(uri: str) -> List[str]: def generate_qr_code(uri: str) -> List[str]:
"""Generate QR code for the URI using qrencode.""" """Generate terminal-friendly ASCII QR code using pure Python."""
try: try:
result = subprocess.run( qr = qrcode.QRCode(
['qrencode', '-t', 'UTF8', '-s', '3', '-m', '2'], version=1,
input=uri.encode(), error_correction=qrcode.constants.ERROR_CORRECT_L,
capture_output=True, box_size=1,
check=True border=2,
) )
return result.stdout.decode().splitlines() qr.add_data(uri)
except subprocess.CalledProcessError: qr.make(fit=True)
return ["QR Code generation failed. Is qrencode installed?"]
output = StringIO()
qr.print_ascii(out=output, invert=True)
return output.getvalue().splitlines()
except Exception as e: except Exception as e:
return [f"Error generating QR code: {str(e)}"] return [f"Error generating QR code: {str(e)}"]

View File

@ -76,7 +76,7 @@ check_os_version() {
} }
install_packages() { install_packages() {
local REQUIRED_PACKAGES=("jq" "qrencode" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "git" "bc" "zip" "cron" "lsof") local REQUIRED_PACKAGES=("jq" "curl" "pwgen" "python3" "python3-pip" "python3-venv" "git" "bc" "zip" "cron" "lsof")
local MISSING_PACKAGES=() local MISSING_PACKAGES=()
log_info "Checking required packages..." log_info "Checking required packages..."