diff --git a/update_package.py b/update_package.py index b632df3..28c1eda 100644 --- a/update_package.py +++ b/update_package.py @@ -1,8 +1,200 @@ +# -*- coding: utf-8 -*- from setuphelpers import * from setupdevhelpers import * import waptguihelper +##define_enable_rename_and_disable_user = False +##define_enable_set_password_requirements = False +##define_enable_configure_login_logout_features = False +##define_enable_configure_lanman_service = False +##define_enable_configure_uac_prompt_behavior = False +##define_enable_configure_external_device_settings = False +##define_enable_configure_windows_services = False +##define_enable_configure_windows_event_logging = False +##define_enable_configure_windows_settings = False +##define_enable_configure_network_settings = False + def update_package(): + # Modify the values from setup.py + define_enable_rename_and_disable_user = ask_message("Options", "Rename and disable default Users", flags=4, raise_error=False,) + define_enable_set_password_requirements = ask_message("Options", "Setup passwords requirements", flags=4, raise_error=False,) + define_enable_configure_login_logout_features = ask_message("Options", "Configure Login/Logout Feature", flags=4, raise_error=False,) + define_enable_configure_lanman_service = ask_message("Options", "Configure LanMan Service", flags=4, raise_error=False,) + define_enable_configure_uac_prompt_behavior = ask_message("Options", "Configure UAC", flags=4, raise_error=False,) + define_enable_configure_external_device_settings = ask_message("Options", "Configure external settings", flags=4, raise_error=False,) + define_enable_configure_windows_services = ask_message("Options", "Configure Windows services", flags=4, raise_error=False,) + define_enable_configure_windows_event_logging = ask_message("Options", "Configure Windows event logging", flags=4, raise_error=False,) + define_enable_configure_windows_settings = ask_message("Options", "Configure Windows settings", flags=4, raise_error=False,) + define_enable_configure_network_settings = ask_message("Options", "Configure networks settings", flags=4, raise_error=False,) + + + if define_enable_rename_and_disable_user == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_rename_and_disable_user"): + line = 'enable_rename_and_disable_user = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_set_password_requirements == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_set_password_requirements"): + line = 'enable_set_password_requirements = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_login_logout_features == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_login_logout_features"): + line = 'enable_configure_login_logout_features = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_lanman_service == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_lanman_service"): + line = 'enable_configure_lanman_service = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_uac_prompt_behavior == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_uac_prompt_behavior"): + line = 'enable_configure_uac_prompt_behavior = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_external_device_settings == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_external_device_settings"): + line = 'enable_configure_external_device_settings = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_windows_services == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_windows_services"): + line = 'enable_configure_windows_services = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_windows_event_logging == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_windows_event_logging"): + line = 'enable_configure_windows_event_logging = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_windows_settings == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_windows_settings"): + line = 'enable_configure_windows_settings = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + if define_enable_configure_network_settings == 6 : + new_lines = [] + with open("setup.py", "r", encoding="utf8") as f: + for line in f.readlines(): + if line.startswith("enable_configure_network_settings"): + line = 'enable_configure_network_settings = True''\n' + new_lines.append(line) + with open("setup.py", "w", encoding="utf8", newline="\n") as f: + f.writelines(new_lines) + else : + new_lines = [] + + ask_control_package(control.package) + control.save_control_to_wapt() + return ask_control_version(control.get_software_version()) + + + +def ask_control_version(version, inc_build=False): + """Requesting that the user supply package version for the `control.version`. Additionally it will make sure user will be able to upload_package from WAPT Console""" + package_updated = False + + # Changing version of the package + if Version(version, 4) > Version(control.get_software_version(), 4): + print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version))) + package_updated = True + else: + version_plus = ( + ".".join(version.split(".")[: len(version.split(".")) - 1]) + "." + str(int(version.split(".")[len(version.split(".")) - 1]) + 1) + ) + version = ask_dialog(control.package, "Version must be %s minimum to upload from WAPT Console" % version_plus, version_plus) + if not version: + version = control.get_software_version() + if Version(version, 4) > Version(control.get_software_version(), 4): + print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version))) + package_updated = True + + control.set_software_version(version) + if inc_build: + control.inc_build() + control.save_control_to_wapt() + return package_updated + + +def ask_control_package(control_package=None, conditionnal_package_name=None, remove_base_files=False): + """Requesting that the user provide a package name to be entered into the control.package field, and offering the possibility of removing the base files (icon.png and changelog.txt) for template package usage + + Args: + control_package (str) : prefilled control_package (default: actual control_package) + conditionnal_package_name (str) : only ask when the control.package contains conditionnal_package_name (default: always ask for control_package) + remove_base_files (bool) : removes base files if parameter is True and conditionnal_package_name is provided (default: False) + """ + if conditionnal_package_name is None or conditionnal_package_name in control.package: + control.package = waptguihelper.input_dialog( + control.package, + "You can redefine the package name", + control_package.replace(conditionnal_package_name, "") if conditionnal_package_name is not None else control_package, + ) + control.save_control_to_wapt() + - \ No newline at end of file