creation depot
This commit is contained in:
71
setup.py
Normal file
71
setup.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuphelpers import *
|
||||
from setupdevhelpers import *
|
||||
|
||||
try:
|
||||
from waptenterprise.waptservice.enterprise import get_active_sessions, start_interactive_process
|
||||
except:
|
||||
from waptservice.enterprise import get_active_sessions, start_interactive_process
|
||||
|
||||
free_space_warning = 20
|
||||
free_space_error = 5
|
||||
send_message_to_user = True
|
||||
|
||||
message_box_title = "Information message about your PC FreeSpace - The IT Support"
|
||||
message_box_title_fr = "Message d'information à propos de l'espace disque du PC - Le Support Informatique"
|
||||
boot_limit_message_string = "Free space is required on your computer because there is less than: " +f'{free_space_error}' +"GB, Do you want to run a disk cleanup?"
|
||||
boot_limit_message_fr_string = "De l’espace libre est requis sur votre ordinateur car il reste moins de : " +f'{free_space_error}' +" Go, Voulez-vous lancer un nettoyage du disque ?"
|
||||
|
||||
def install():
|
||||
pass
|
||||
|
||||
def session_setup():
|
||||
# Translating message
|
||||
if get_language() == "fr":
|
||||
message_box_title = message_box_title_fr
|
||||
boot_limit_message_string = boot_limit_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\Freespace 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\Freespace Information", "Last Check", date)
|
||||
|
||||
# Notify the user
|
||||
if ask_message(message_box_title, boot_limit_message_string, flags=4, raise_error=False,) == 6 :
|
||||
run_session_cleaner()
|
||||
print("reboot")
|
||||
return "ERROR"
|
||||
|
||||
|
||||
def audit():
|
||||
if get_os_name() == "Windows":
|
||||
sys_drive = makepath(systemdrive)
|
||||
else:
|
||||
sys_drive = makepath("/")
|
||||
system_free_space = str(round(get_disk_free_space(sys_drive) / 1073741824, 1))
|
||||
system_free_space_str = str(system_free_space + "G")
|
||||
print(system_free_space_str)
|
||||
if free_space_error > int(float(system_free_space)) :
|
||||
print('ERROR')
|
||||
if send_message_to_user:
|
||||
run_session_setup(control.package)
|
||||
return 'ERROR'
|
||||
if free_space_warning > int(float(system_free_space)) :
|
||||
|
||||
return 'WARNING'
|
||||
WAPT.write_audit_data_if_changed("audit-freespace", sys_drive, system_free_space_str, keep_days=365)
|
||||
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 run_session_cleaner():
|
||||
for session_id in get_active_sessions():
|
||||
start_interactive_process("cleanmgr", session_id=session_id) # , minimize=True
|
||||
Reference in New Issue
Block a user