tis-disable-sleepmode 1.0.0-3

  • package : tis-disable-sleepmode
  • version : 1.0.0-3
  • architecture : all
  • locale :
  • description : Disable sleep mode - current power scheme saved before modifications
  • maintainer : TIS
  • date : 2018-05-11 18:14:52
  • min_wapt_version : 1.3.5
  • min_os_version : 6.1
  • max_os_version :
  • impacted_process :

setup.py

# -*- coding: utf-8 -*-
from setuphelpers import *
import re

uninstallkey = []

save_path = makepath("C:\powerplan")
save_file = makepath(save_path,"power.pow")

def get_uuid_from_string(raw_uuid_string):
    uuid_pattern = re.compile(ur'[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}')
    imported_uuid = uuid_pattern.search(raw_uuid_string)
    if imported_uuid:
        return_uuid = str(imported_uuid.group())
        return return_uuid
    else:
        print('No UUID found, break')
        return False

def get_active_power_scheme():
    try:
        active_string = run('"powercfg" -getactivescheme')
    except:
        print("Error retrieving activescheme")
        return False
    result = get_uuid_from_string(active_string)
    if result:
        return result
    else:
        print("Error no UUID in active scheme")
        return False

def save_powerscheme(plan_uuid,f_save_path):
    if plan_uuid:
        if not isfile(f_save_path):
            print("- Temporary duplicating currently active powerplan for backup and restore")
            res = run('"powercfg.exe" -duplicatescheme %s' % plan_uuid)
            imported_uuid = get_uuid_from_string(res)
            print("- Export power plan to %s" % f_save_path)
            run('"powercfg.exe" -export "%s" %s' % (f_save_path,imported_uuid))
            print("- Remove temporary power plan")
            run('"powercfg.exe" -delete %s' % imported_uuid)
        else:
            print("Powerscheme already saved")
    else:
        print('Plan UUID missing, abort')
        return False

def install():
    print('installing %s' % control.asrequirement())
    if isfile(save_file):
        print('Sleep mode already disabled, skipping')
    else:
        print('Disable sleep mode')

        ################ BACKUP ################
        if not isdir(save_path):
            mkdirs(save_path)
        powerplan = get_active_power_scheme()
        print("Active Power Scheme is %s" % powerplan)
        save_powerscheme(powerplan,save_file)

        ################ MODIFY ################
        run('"powercfg.exe" -change -monitor-timeout-ac 0')
        run('"powercfg.exe" -change -monitor-timeout-dc 0')
        run('"powercfg.exe" -change -disk-timeout-ac 0')
        run('"powercfg.exe" -change -disk-timeout-dc 0')
        run('"powercfg.exe" -change -standby-timeout-ac 0')
        run('"powercfg.exe" -change -standby-timeout-dc 0')
        run('"powercfg.exe" -change -hibernate-timeout-ac 0')
        run('"powercfg.exe" -change -hibernate-timeout-dc 0')

        ################# EXTRA #################
        print('Disable hibernation')
        run('"powercfg.exe" -h off')
        print('Do nothing when laptop lid is closed')
        run('"powercfg.exe" -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0')
        run('"powercfg.exe" -setdcvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0')

        ################# FINISH #################
        print("Sleep mode disabled")

def uninstall():
    print('uninstalling %s' % control.asrequirement())
    print('Restore saved power scheme')
    if isfile(save_file):
        res = run('"powercfg.exe" -import "%s"' % save_file)
        imported_uuid = get_uuid_from_string(res)
        to_delete_uuid = get_active_power_scheme()
        if imported_uuid:
            print('- Import saved power plan : %s' % imported_uuid)
            run('"powercfg.exe" -setactive %s' % imported_uuid)
            print('- Remove no-sleep power plan : %s' % to_delete_uuid)
            run('"powercfg.exe" -delete %s' % to_delete_uuid)
        ##run('"powercfg.exe" -restoredefaultschemes')
        remove_tree(save_path)
    else:
        print('No save file found, skipping')

if __name__ == '__main__':
    update_package()



    

Changelog

No changelog
    

manifest.sha256

setup.py b578df0e3ae1e96ee38dd86fd87cf82dc1b5bf8338f2da24f180bbbe6bf8fff2
WAPT/certificate.crt 13fb474c5c23c135a77aba592eb8821b9ecbcc463f5b7312312b87b20eac6779
WAPT/icon.png 774f38e4ee699071e0282c91ef80207eee4e2179ba7245d43441388884a9a2ea
WAPT/control 2c1ea25c1752a7bb723e74e3c9e933b8c5f9722a2432fefb0030ecbc154f41c7
WAPT/wapt.psproj 324f014e8690c45eb9cc515b7b8bf77b5ca20a7e2e283f7d1964197786696fae