Files
comi-audit-freespace-template/update_package.py
2024-03-11 10:43:52 +01:00

99 lines
4.9 KiB
Python

# -*- coding: utf-8 -*-
from setuphelpers import *
from setupdevhelpers import *
import waptguihelper
def update_package():
# Modify the values from setup.py
define_send_message_to_user = ask_message("Allow display Cleanmgr", "Allow display Cleanmgr", flags=4, raise_error=False,)
define_free_space_warning = ask_input("Alert Threshold", "Alert Threshold in Go", "20")
define_free_space_error = ask_input("Error Threshold", "Error Threshold in Go", "5")
if define_send_message_to_user == 6 :
new_lines = []
with open("setup.py", "r", encoding="utf8") as f:
for line in f.readlines():
if line.startswith("send_message_to_user"):
line = 'send_message_to_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 = []
with open("setup.py", "r", encoding="utf8") as f:
for line in f.readlines():
if line.startswith("send_message_to_user"):
line = 'send_message_to_user = False''\n'
new_lines.append(line)
with open("setup.py", "w", encoding="utf8", newline="\n") as f:
f.writelines(new_lines)
new_lines = []
with open("setup.py", "r", encoding="utf8") as f:
for line in f.readlines():
if line.startswith("free_space_warning"):
line = 'free_space_warning = '+ f'{define_free_space_warning}''\n'
new_lines.append(line)
with open("setup.py", "w", encoding="utf8", newline="\n") as f:
f.writelines(new_lines)
new_lines = []
with open("setup.py", "r", encoding="utf8") as f:
for line in f.readlines():
if line.startswith("free_space_error"):
line = 'free_space_error = '+ f'{define_free_space_error}''\n'
new_lines.append(line)
with open("setup.py", "w", encoding="utf8", newline="\n") as f:
f.writelines(new_lines)
# Edit Control
ask_control_package(control.package, "-template")
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_dialog(title, text, default="", stay_on_top=False):
"""This function opens a dialog box with a action input"""
return waptguihelper.input_dialog(title, text, default, stay_on_top)
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()