79 lines
3.7 KiB
Python
79 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
from setuphelpers import *
|
|
from setupdevhelpers import *
|
|
import waptguihelper
|
|
|
|
def update_package():
|
|
# Modify the values from setup.py
|
|
define_hour_reboot = ask_input("Heure de Reboot", "Heure de Reboot", "18:00")
|
|
define_day_reboot = ask_input("Jour de Reboot", "Jour de Reboot", "SUN")
|
|
|
|
with open("setup.py", "r", encoding="utf8") as f:
|
|
for line in f.readlines():
|
|
if line.startswith("hour_reboot"):
|
|
line = 'hour_reboot = '+ f'{define_hour_reboot}''\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("day_reboot"):
|
|
line = 'day_reboot = '+ f'{define_day_reboot}''\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()
|
|
|