Refactor setup.py: Removed unused imports, simplified code, and improved readability
This commit is contained in:
104
setup.py
104
setup.py
@@ -1,108 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuphelpers import *
|
||||
import shutil
|
||||
import re
|
||||
import subprocess
|
||||
import string
|
||||
from waptcrypto import *
|
||||
import random
|
||||
import platform
|
||||
import json
|
||||
|
||||
|
||||
r"""
|
||||
Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
|
||||
|
||||
"""
|
||||
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
|
||||
#uninstallstring='"C:\Program Files\RustDesk\RustDesk.exe" --uninstall'
|
||||
|
||||
def update_package():
|
||||
# Declaring local variables
|
||||
package_updated = False
|
||||
proxies = get_proxies()
|
||||
if not proxies:
|
||||
proxies = get_proxies_from_wapt_console()
|
||||
api_url = "https://api.github.com/repos/rustdesk/rustdesk/releases/latest"
|
||||
download_dict = {
|
||||
"windows-all": "x86_64.exe",
|
||||
"windows-x64": "x86_64.exe",
|
||||
"windows-x86": "x86_64.exe",
|
||||
}
|
||||
|
||||
# Getting latest version information from official sources
|
||||
print("API used is: %s" % api_url)
|
||||
json_load = json.loads(wgets(api_url, proxies=proxies))
|
||||
for to_download in json_load["assets"]:
|
||||
if download_dict[f"{control.target_os}-{control.architecture}"] in to_download["name"]:
|
||||
download_url = to_download["browser_download_url"]
|
||||
newversion = json_load["tag_name"]
|
||||
print (newversion)
|
||||
latest_bin = to_download["name"]
|
||||
break
|
||||
|
||||
# Downloading latest binaries
|
||||
print("Latest %s version is: %s" % (control.name, newversion))
|
||||
print("Download URL is: %s" % download_url)
|
||||
if not isfile(latest_bin):
|
||||
print("Downloading: %s" % latest_bin)
|
||||
wget(download_url, latest_bin, proxies=proxies)
|
||||
else:
|
||||
print("Binary is present: %s" % latest_bin)
|
||||
|
||||
# Checking version from file
|
||||
version_from_file = get_version_from_binary(latest_bin)
|
||||
print (version_from_file)
|
||||
if Version(version_from_file) != Version(newversion) and version_from_file != "":
|
||||
print("Changing version to the version number of the binary")
|
||||
os.rename(latest_bin, latest_bin.replace(newversion, version_from_file))
|
||||
else:
|
||||
print("Binary file version corresponds to online version")
|
||||
|
||||
# Changing version of the package
|
||||
if Version(newversion) > Version(control.get_software_version()):
|
||||
print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(newversion)))
|
||||
package_updated = True
|
||||
else:
|
||||
print("Software version up-to-date (%s)" % Version(newversion))
|
||||
control.set_software_version(newversion)
|
||||
control.save_control_to_wapt()
|
||||
|
||||
# Deleting outdated binaries
|
||||
remove_outdated_binaries(newversion)
|
||||
|
||||
# Validating update-package-sources
|
||||
return package_updated
|
||||
|
||||
def install():
|
||||
bin_name = glob.glob("rustdesk-*.exe")[0]
|
||||
# préraration du dossier de config
|
||||
destdir = makepath('C:', 'Windows', 'ServiceProfiles', 'LocalService', 'AppData', 'Roaming', 'RustDesk', 'config')
|
||||
|
||||
if isdir(destdir):
|
||||
print("Config folder exist")
|
||||
|
||||
else:
|
||||
print("Create Config folder")
|
||||
mkdirs(destdir)
|
||||
|
||||
shutil.copy ("RustDesk2.toml", "C:/Windows/ServiceProfiles/LocalService/AppData/Roaming/RustDesk/config")
|
||||
|
||||
# Installing the software
|
||||
print("Installing: ", bin_name)
|
||||
install_exe_if_needed(bin_name,
|
||||
silentflags='--silent-install',
|
||||
install_exe_if_needed(
|
||||
"rustdesk.exe",
|
||||
silentflags="--silent-install",
|
||||
key="RustDesk",
|
||||
min_version=control.get_software_version(),
|
||||
)
|
||||
# Create the uninstall key
|
||||
uninstallkey.clear()
|
||||
|
||||
|
||||
def uninstall():
|
||||
run_notfatal(r'"C:\Program Files\RustDesk\RustDesk.exe" --uninstall')
|
||||
remove_tree(r'C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk', ignore_errors=True,)
|
||||
remove_tree(
|
||||
r"C:\Windows\ServiceProfiles\LocalService\AppData\Roaming\RustDesk",
|
||||
ignore_errors=True,
|
||||
)
|
||||
|
||||
|
||||
def audit():
|
||||
def get_rustdesk_id():
|
||||
# Run the command and capture its output
|
||||
result = subprocess.run(['C:\\Program Files\\RustDesk\\rustdesk.exe', '--get-id'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
result = subprocess.run(["C:\\Program Files\\RustDesk\\rustdesk.exe", "--get-id"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
# Check if the command was successful
|
||||
if result.returncode == 0:
|
||||
# Store the output in a variable
|
||||
@@ -114,7 +39,6 @@ def audit():
|
||||
# If there was an error, print the error message
|
||||
print("Error:", result.stderr)
|
||||
return final_id
|
||||
|
||||
WAPT.write_audit_data("RustDesk", "id", get_rustdesk_id(), max_count=3)
|
||||
return "OK"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user