|
|
@ -36,10 +36,18 @@ class MyListener(ServiceListener): |
|
|
|
info = zc.get_service_info(type_, name) |
|
|
|
info = zc.get_service_info(type_, name) |
|
|
|
print(f"Service {name} added, service info: {info}") |
|
|
|
print(f"Service {name} added, service info: {info}") |
|
|
|
if info and info.addresses: |
|
|
|
if info and info.addresses: |
|
|
|
|
|
|
|
# Only add if TXT record contains 'MiniDexed' |
|
|
|
|
|
|
|
txt_records = info.properties |
|
|
|
|
|
|
|
if txt_records: |
|
|
|
|
|
|
|
for k, v in txt_records.items(): |
|
|
|
|
|
|
|
# v may be bytes, decode if needed |
|
|
|
|
|
|
|
val = v.decode() if isinstance(v, bytes) else v |
|
|
|
|
|
|
|
if (b"MiniDexed" in k or b"MiniDexed" in v) or ("MiniDexed" in str(k) or "MiniDexed" in str(val)): |
|
|
|
ip = socket.inet_ntoa(info.addresses[0]) |
|
|
|
ip = socket.inet_ntoa(info.addresses[0]) |
|
|
|
if ip not in self.ip_list: |
|
|
|
if ip not in self.ip_list: |
|
|
|
self.ip_list.append(ip) |
|
|
|
self.ip_list.append(ip) |
|
|
|
self.name_list.append(info.server.rstrip('.')) |
|
|
|
self.name_list.append(info.server.rstrip('.')) |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Constants |
|
|
|
# Constants |
|
|
@ -82,6 +90,8 @@ def extract_zip(zip_path): |
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
parser = argparse.ArgumentParser(description="MiniDexed Updater") |
|
|
|
parser = argparse.ArgumentParser(description="MiniDexed Updater") |
|
|
|
parser.add_argument("-v", action="store_true", help="Enable verbose FTP debug output") |
|
|
|
parser.add_argument("-v", action="store_true", help="Enable verbose FTP debug output") |
|
|
|
|
|
|
|
parser.add_argument("--ip", type=str, help="IP address of the device to upload to (skip mDNS discovery)") |
|
|
|
|
|
|
|
parser.add_argument("--version", type=int, choices=[1,2,3], help="Version to upload: 1=Latest official, 2=Continuous, 3=Local build (skip prompt)") |
|
|
|
args = parser.parse_args() |
|
|
|
args = parser.parse_args() |
|
|
|
|
|
|
|
|
|
|
|
import time |
|
|
|
import time |
|
|
@ -97,6 +107,14 @@ if __name__ == "__main__": |
|
|
|
] |
|
|
|
] |
|
|
|
if has_local_build: |
|
|
|
if has_local_build: |
|
|
|
release_options.append(("Local build (from src/)", None)) |
|
|
|
release_options.append(("Local build (from src/)", None)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.version: |
|
|
|
|
|
|
|
selected_idx = args.version - 1 |
|
|
|
|
|
|
|
if selected_idx < 0 or selected_idx >= len(release_options): |
|
|
|
|
|
|
|
print(f"Invalid version selection: {args.version}") |
|
|
|
|
|
|
|
sys.exit(1) |
|
|
|
|
|
|
|
github_url = release_options[selected_idx][1] |
|
|
|
|
|
|
|
else: |
|
|
|
print("Which release do you want to update?") |
|
|
|
print("Which release do you want to update?") |
|
|
|
for idx, (desc, _) in enumerate(release_options): |
|
|
|
for idx, (desc, _) in enumerate(release_options): |
|
|
|
print(f" [{idx+1}] {desc}") |
|
|
|
print(f" [{idx+1}] {desc}") |
|
|
@ -167,6 +185,12 @@ if __name__ == "__main__": |
|
|
|
# Using mDNS to find the IP address of the device(s) that advertise the FTP service "_ftp._tcp." |
|
|
|
# Using mDNS to find the IP address of the device(s) that advertise the FTP service "_ftp._tcp." |
|
|
|
ip_addresses = [] |
|
|
|
ip_addresses = [] |
|
|
|
device_names = [] |
|
|
|
device_names = [] |
|
|
|
|
|
|
|
selected_ip = None |
|
|
|
|
|
|
|
selected_name = None |
|
|
|
|
|
|
|
if args.ip: |
|
|
|
|
|
|
|
selected_ip = args.ip |
|
|
|
|
|
|
|
selected_name = args.ip |
|
|
|
|
|
|
|
else: |
|
|
|
zeroconf = Zeroconf() |
|
|
|
zeroconf = Zeroconf() |
|
|
|
listener = MyListener(ip_addresses, device_names) |
|
|
|
listener = MyListener(ip_addresses, device_names) |
|
|
|
browser = ServiceBrowser(zeroconf, "_ftp._tcp.local.", listener) |
|
|
|
browser = ServiceBrowser(zeroconf, "_ftp._tcp.local.", listener) |
|
|
@ -319,7 +343,15 @@ if __name__ == "__main__": |
|
|
|
with open(local_path, 'rb') as f: |
|
|
|
with open(local_path, 'rb') as f: |
|
|
|
ftp.storbinary(f'STOR {remote_path}', f, 8192, callback=progress_callback) |
|
|
|
ftp.storbinary(f'STOR {remote_path}', f, 8192, callback=progress_callback) |
|
|
|
print(f"\nUploaded {file} to {selected_ip}.") |
|
|
|
print(f"\nUploaded {file} to {selected_ip}.") |
|
|
|
|
|
|
|
except ftplib.all_errors as e: |
|
|
|
|
|
|
|
print(f"FTP error: {e}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
ftp.sendcmd("BYE") |
|
|
|
ftp.sendcmd("BYE") |
|
|
|
print(f"Disconnected from {selected_ip}.") |
|
|
|
print(f"Disconnected from {selected_ip}.") |
|
|
|
except ftplib.all_errors as e: |
|
|
|
except ftplib.all_errors as e: |
|
|
|
print(f"FTP error: {e}") |
|
|
|
if str(e).strip().lower() == "timed out": |
|
|
|
|
|
|
|
# Suppress expected timeout after BYE |
|
|
|
|
|
|
|
print(f"Disconnected from {selected_ip}.") |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
print(f"FTP error after BYE: {e}") |
|
|
|