From 48e6cae95677a91f6788cdd6d29cefa8b2e168a2 Mon Sep 17 00:00:00 2001 From: Gabriel Gendron Date: Mon, 11 Mar 2024 10:16:21 +0100 Subject: [PATCH] Creation du depot --- .env | 2 + .vscode/launch.json | 305 ++++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 13 ++ WAPT/certificate.crt | 20 +++ WAPT/control | 44 ++++++ WAPT/icon.png | Bin 0 -> 2823 bytes WAPT/manifest.sha256 | 1 + WAPT/signature.sha256 | 1 + WAPT/wapt.psproj | 235 ++++++++++++++++++++++++++++++++ luti.json | 28 ++++ setup.py | 181 +++++++++++++++++++++++++ update_package.py | 80 +++++++++++ 12 files changed, 910 insertions(+) create mode 100644 .env create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 WAPT/certificate.crt create mode 100644 WAPT/control create mode 100644 WAPT/icon.png create mode 100644 WAPT/manifest.sha256 create mode 100644 WAPT/signature.sha256 create mode 100644 WAPT/wapt.psproj create mode 100644 luti.json create mode 100644 setup.py create mode 100644 update_package.py diff --git a/.env b/.env new file mode 100644 index 0000000..7d8f006 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +VIRTUAL_ENV=C:\Program Files (x86)\wapt\ +PYTHONPATH=C:\Program Files (x86)\wapt\ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..584d5a5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,305 @@ +{ + "version": "0.2.4", + "configurations": [ + { + "name": "WAPT: install", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "install", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "linux": { + "sudo": true + }, + "osx": { + "sudo": true + }, + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: remove", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "remove", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "linux": { + "sudo": true + }, + "osx": { + "sudo": true + }, + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: uninstall", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "uninstall", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "linux": { + "sudo": true + }, + "osx": { + "sudo": true + }, + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: session-setup", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "session-setup", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: audit", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "audit", + "-f", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "linux": { + "sudo": true + }, + "osx": { + "sudo": true + }, + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: update-package", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "update-package-sources", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: -i build-upload", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "-i", + "--use-gui", + "build-upload", + "--no-ide", + "${workspaceFolder}" + ], + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "WAPT: build-package", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "${config:python.wapt-get}", + "args": [ + "build-package", + "--no-ide", + "${workspaceFolder}" + ], + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: import setup.py", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_import_setup_template.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: import update_package.py", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_import_update_template.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: complete-package", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_complete_control.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: translate-control", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_translate_control.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: unify-control files", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_unify_control.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: duplicate-os-package-code", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_duplicate_os_package_code.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: duplicate update_package.py", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_duplicate_update_package.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: change luti.json", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/change_luti_json.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: import .gitignore", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_import_gitignore.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + }, + { + "name": "DEV: quick testing", + "type": "python", + "request": "launch", + "justMyCode": false, + "program": "C:/Program Files (x86)/wapt/public/persistent/package-tools/package-template/launch_quick_testing.py", + "console": "integratedTerminal", + "python": "${command:python.interpreterPath}", + "pythonArgs": [ + "-I", + "-B" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1b136ec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "python.defaultInterpreterPath": "C:\\Program Files (x86)\\wapt\\waptpython.exe", + "python.pythonPath": "C:\\Program Files (x86)\\wapt\\waptpython.exe", + "python.wapt-get": "C:\\Program Files (x86)\\wapt\\wapt-get.py", + "python.formatting.provider": "black", + "python.formatting.blackArgs": + [ + "--line-length", + "150" + ], + "editor.insertSpaces": true, + "files.eol": "\n" +} \ No newline at end of file diff --git a/WAPT/certificate.crt b/WAPT/certificate.crt new file mode 100644 index 0000000..6fd2b31 --- /dev/null +++ b/WAPT/certificate.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDNzCCAh+gAwIBAgIUSsaILn1scDCUhHvihORUTceVhO8wDQYJKoZIhvcNAQEL +BQAwJDELMAkGA1UEBhMCRlIxFTATBgNVBAMMDGdnZW5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000000..7699c42 --- /dev/null +++ b/WAPT/control @@ -0,0 +1,44 @@ +package : comi-info-shutdown +version : 2.3-34 +architecture : all +section : base +priority : optional +name : Shutdown Information +categories : Security +maintainer : WAPT Team,Tranquil IT,Jimmy PELÉ +description : Annoy user about how long their PC is on - Only work with WAPT Enterprise +depends : +conflicts : +maturity : PROD +locale : all +target_os : windows +min_wapt_version : 1.8.2 +sources : Ennuyer l'utilisateur à propos de la durée d'allumage de son PC - Fonctionne seulement avec WAPT Enterprise +installed_size : +impacted_process : +description_fr : Gêne l'utilisateur quant à la durée d'utilisation de son PC - Ne fonctionne qu'avec WAPT Enterprise +description_pl : Denerwowanie użytkownika o tym, jak długo komputer jest włączony - Działa tylko z WAPT Enterprise +description_de : Verärgert den Benutzer darüber, wie lange sein PC eingeschaltet ist - Funktioniert nur mit WAPT Enterprise +description_es : Molestar al usuario sobre el tiempo que su PC está encendido - Sólo funciona con WAPT Enterprise +description_pt : Utilizador irritado sobre quanto tempo o seu PC está ligado - Trabalhar apenas com a WAPT Enterprise +description_it : Infastidisce l'utente per quanto tempo il suo PC rimane acceso - Funziona solo con WAPT Enterprise +description_nl : De gebruiker ergeren over hoe lang hun PC aanstaat - Werkt alleen met WAPT Enterprise +description_ru : Раздражает пользователя тем, как долго включен его компьютер - Работает только с WAPT Enterprise +audit_schedule : 3h +editor : +keywords : +licence : +homepage : +package_uuid : f6f50aa7-8c73-411b-bc14-12e9b8af4bee +valid_from : +valid_until : +forced_install_on : +changelog : +min_os_version : +max_os_version : +icon_sha256sum : d9bb8c943e30af428be08e0ba3175a9320c235be8a950e086203c89e0dbd106f +signer : ggendron_pem +signer_fingerprint: 244cdf15fa2ea3ead58e4abf232fdf9a30a8a28a798677f71d6a3e76e65f9003 +signature : l6mpqV5G3SEmAE66Fhi0XBMedYpCCQNB5WzAFkz2Xi0aPAxt2MIeujcolMB4TQzM3jSD7cckoA6WIyjvAng+zIhy8ufCjFoPVHs7PxJY/SAXcZn/m0Z1kKLT2sA2JtuPNgTbZM+WXSnII0kOYisoE2y/+OzokhwNujboKAirBDhDRyNC3mbAZ94Rj6I/OGD+T0yKatR9XAidRulqzXen0PmFFljh3iCh5pglGIaS7u0Y6hILr9MZYRwNWsOTEMGktDUXIpZwneITUuyEJa2xtzEsmT5aoAH88dLcsWSNX2Dw2o+rFwvvVxpg/v4IXW334yhvNkA3uouUdvwQUZPy8w== +signature_date : 2024-01-29T15:40:10.000000 +signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,min_os_version,max_os_version,icon_sha256sum,signer,signer_fingerprint,signature_date,signed_attributes \ No newline at end of file diff --git a/WAPT/icon.png b/WAPT/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6adbaf088301e693d8ed7ed2886ae605ca72205d GIT binary patch literal 2823 zcmV+i3;6VjP)EX>4Tx04R}tkv&MmKpe$iQ>7x64t5X`%ut?x`&UicTt|@eeTcErxZ*E_(bAarW+RVI`Q*kxkDLhl#~f2g@DI%7#ijMI2F7jq-(@ z%L?Z$&T6H`TKD8H3>LKI4A*H6A%R6Ck%9;rHEf^)3sG7%QcR?2Kknflbo?oD$>iDq zBgZ_dP$4;f@IUz7ty!F$aFc>@p!>zPKSqGSF3_yo_V=-EH%|cnGjOG~{nZ9A^GSNW ztwoN2&^B;!-PYti;Bp5Tc+w?9awI=Zp;!do&*+=-K>sb!yXyAV+Q;bwkfpAcZh(VB zV6;TpYaZ|J>Fn*_Gp+u90Q84)+mec%OaK4?24YJ`L;(K){{a7>y{D4^000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jmAI5CS)C_6!gJ000qmMObu0Z*6U5Zgc=wK~Pj6 zX=870l9D|(000Q)NklX&*W;?a&8aI@6avv`mMAPAN5v5{3d(3IW=b#g1ji3nU~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5RPr3=3tYE_Us1;kG;O_Rj}rkG%TIU!B2^ zJ6aWIq1#&Bf~~0yQ$a;~La6^_z?mW{P*>>=Ece`@L%!eKddsck=5JzZc5d0RG~FQ6 zZYMJB-N)$a{Fsmb{jUJ<{D8mf>8k>G_P4)#x~ZYzsgjZsB5IWB zsR`n7ox0lE6-7JjHUfdO41V?*LQyE+vV}623q?^F8a;>IZoeuRr!&VnI~&B`-4y_Q z3E}>0KAF4yzJ1gw2#l|e8#MTSPkav z&=8a3<9M2z*|gD#uE#lbCO|}uVm6r;MNdpjaBl1Zp>Tw}+>MkJmyqeO(c3?WC36G1 zA<+%ld|Pw1|GEJz2UA^L<-K|P4yViIVtjIvNGOEMcMCVdkQjEiH z=k%E~T$q?(E*wE9W(NBE>FMeA4fORsKH%>P+z^0N+tqrHx1_kZy|$*>yKC3ioNl+9 z@ySVql;r2 OK", + "taskid_luti": "72e807a9-2875-48e1-8114-fde203e71c00", + "commit": "84eca861b5d8c53b57687792cb7d0e26750c565a", + "folder_in_git_repo": "tis-info-shutdown/windows" +} \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6d9f62b --- /dev/null +++ b/setup.py @@ -0,0 +1,181 @@ +# -*- coding: utf-8 -*- +from setuphelpers import * +from setupdevhelpers import * +import psutil +import time +import datetime +import ctypes + +try: + from waptenterprise.waptservice.enterprise import get_active_sessions, start_interactive_process +except: + from waptservice.enterprise import get_active_sessions, start_interactive_process +import win32api +import sys +import platform + +# 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 +allow_force_reboot = True +boot_limit = 4 +boot_limit_max = 7 +force_reboot_timeout = 7200 # In seconds +message_box_title = "Information message about your PC uptime - The IT Support" +message_box_title_fr = "Message d'information à propos de la durée d'allumage du PC - Le Support Informatique" +# boot_limit_message = "This PC must be reboot because he's up since too long, Would you like to reboot now?" +boot_limit_message_string = "This PC must be rebooted because he's up since: %s, Would you like to reboot now?" +boot_limit_message_fr_string = "Ce PC doit être redémarré, car il est allumé depuis : %s, Voulez-vous redémarrer maintenant ?" +# boot_limit_max_message = "This PC will be FORCE reboot in 2 hours because he's up since too long" +boot_limit_max_message_string = "This PC will be FORCE reboot in %s hours because he's up since: %s" +boot_limit_max_message_fr_string = "Ce PC va être redémarré de manière FORCÉ dans %s heures, car il est allumé depuis : %s" + + +def install(): + pass + r""" # Initializing variables + wapt_enterprise_dir = makepath(WAPT.wapt_base_dir,'waptenterprise') + + # Checking that the WAPT Agent is well in Enterprise version + if isdir(wapt_enterprise_dir): + print('Continuing: WAPT Agent is well installed in Enterprise version') + else: + error('WAPT Agent is NOT installed in Enterprise version, please upgrade') + """ + + +def session_setup(): + print("This PC is up since:") + print(convert_time_to_date(uptime_seconds())) + + # Translating message + if get_language() == "fr": + message_box_title = message_box_title_fr + boot_limit_message_string = boot_limit_message_fr_string + boot_limit_max_message_string = boot_limit_max_message_fr_string + + # Avoiding user pop-up spamming + check_timeout = 1800 + date_format = "%Y-%m-%d %H:%M:%S" # datetime.datetime.strptime(date_pwsh, "%Y/%m/%d %H:%M:%S") + date = run_powershell('Get-Date -Format "yyyy-MM-dd HH:mm:ss"') # datetime.datetime.now() + date_reg = registry_readstring(HKEY_CURRENT_USER, r"SOFTWARE\WAPT\Shutdown Information", "Last Check") + if date_reg != "": + date_diff = datetime.datetime.strptime(date, date_format) - datetime.datetime.strptime(date_reg, date_format) + if date_diff.total_seconds() < check_timeout: + return "Already checked" + registry_set(HKEY_CURRENT_USER, r"SOFTWARE\WAPT\Shutdown Information", "Last Check", date) + + # Notify the user + if allow_force_reboot: + if uptime_days() > boot_limit_max: + # message_box( + # message_box_title, + # boot_limit_max_message_string % (convert_time_to_hours(force_reboot_timeout), convert_time_to_date(uptime_seconds(), translate=True)), + # ) + ask_message(message_box_title, boot_limit_max_message_string % (convert_time_to_hours(force_reboot_timeout), convert_time_to_date(uptime_seconds(), translate=True)), flags=0, raise_error=False,) + #reboot_machine(force=1, timeout=force_reboot_timeout) + print("reboot") + return "ERROR" + else : + print("toto") + if uptime_days() > boot_limit: + #message_box_ask_reboot(message_box_title, boot_limit_message_string % convert_time_to_date(uptime_seconds(), translate=True)) + if ask_message(message_box_title, boot_limit_message_string % convert_time_to_date(uptime_seconds(), translate=True), flags=4, raise_error=False,) == "6" : + reboot_machine() + return "WARNING" + if uptime_days() < boot_limit: + return "OK" + + +def audit(): + print("This PC is up since:") + print(convert_time_to_date(uptime_seconds())) + + if allow_force_reboot: + if uptime_days() > boot_limit_max: + run_session_setup(control.package) + print("Force rebooting the PC after the defined timeout.") + reboot_machine(force=1, timeout=force_reboot_timeout) + return "ERROR" + if uptime_days() > boot_limit: + run_session_setup(control.package) + return "WARNING" + if uptime_days() < boot_limit: + return "OK" + + +def run_session_setup(package_name): + for session_id in get_active_sessions(): + start_interactive_process("wapt-get", "--hide session-setup %s -f" % package_name, session_id=session_id) # , minimize=True + + +# def message_box(title, text, style=0): +# if platform.python_version_tuple()[0] == "3": +# import importlib + +# importlib.reload(sys) +# else: +# reload(sys) +# sys.setdefaultencoding("utf-8") + +# MB_OK = 0 +# MB_OKCANCEL = 1 +# MB_YESNOCANCEL = 3 +# MB_YESNO = 4 +# ctypes.windll.user32.MessageBoxW(0, "%s" % text, "%s" % title, style) +# return + + +# def message_box_ask_reboot(title, text): +# if platform.python_version_tuple()[0] == "3": +# import importlib + +# importlib.reload(sys) +# else: +# reload(sys) +# sys.setdefaultencoding("utf-8") + +# ID_OK = 0 +# ID_CANCEL = 2 +# ID_ABORT = 3 +# ID_YES = 6 +# ID_NO = 7 + +# response = ctypes.windll.user32.MessageBoxW(0, "%s" % text, "%s" % title, 4) +# if response == ID_YES: +# reboot_machine() +# else: +# pass + + +def uptime_seconds(): + return time.time() - psutil.boot_time() + + +def uptime_minutes(): + return (time.time() - psutil.boot_time()) / 60 + + +def uptime_hours(): + return (time.time() - psutil.boot_time()) / 3600 + + +def uptime_days(): + return ((time.time() - psutil.boot_time()) / 3600) / 24 + + +def convert_time_to_hours(seconds): + return seconds / 3600 + + +def convert_time_to_date(seconds, translate=False): + from datetime import datetime, timedelta + + sec = timedelta(seconds=seconds) + d = datetime(1, 1, 1) + sec + # print("DAYS:HOURS:MIN:SEC") + # up 23 weeks, 3 days, 23 hours, 16 minutes + # up 23 weeks 3 days 23 hours 16 minutes + if translate: + if get_language() == "fr": + return "%d jours %d heures %d minutes %d secondes" % (d.day - 1, d.hour, d.minute, d.second) + return "%d days %d hours %d minutes %d seconds" % (d.day - 1, d.hour, d.minute, d.second) diff --git a/update_package.py b/update_package.py new file mode 100644 index 0000000..ce8663a --- /dev/null +++ b/update_package.py @@ -0,0 +1,80 @@ +# -*- 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) + + +