81 lines
3.6 KiB
Python
81 lines
3.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
from setuphelpers import *
|
|
from setupdevhelpers import *
|
|
import waptguihelper
|
|
|
|
|
|
def update_package():
|
|
# Modify the values from setup.py
|
|
define_allow_force_reboot = ask_message("Allow Force Reboot", "Allow Force Reboot", flags=4, raise_error=False,)
|
|
define_boot_limit = ask_input("Uptime for prevent user", "Uptime for prevent user in Days", "7")
|
|
if define_allow_force_reboot == 6 :
|
|
define_boot_limit_max = ask_input("Uptime for force shutdown", "Uptime for force shutdown", "30")
|
|
new_lines = []
|
|
with open("setup.py", "r", encoding="utf8") as f:
|
|
for line in f.readlines():
|
|
if line.startswith("allow_force_reboot"):
|
|
line = 'allow_force_reboot = True\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("boot_limit_max ="):
|
|
line = 'boot_limit_max = '+ f'{define_boot_limit_max}''\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("allow_force_reboot"):
|
|
line = 'allow_force_reboot = 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("boot_limit ="):
|
|
line = 'boot_limit = '+ f'{define_boot_limit}''\n'
|
|
new_lines.append(line)
|
|
with open("setup.py", "w", encoding="utf8", newline="\n") as f:
|
|
f.writelines(new_lines)
|
|
|
|
# Edit Control
|
|
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)
|
|
|
|
|
|
|