tis-schedule-wapt-upgrade-on-boot

1.1-11
Trigger "wapt-get upgrade" when the PC boot
662 downloads
Download
default icon

  Description 

  • package : tis-schedule-wapt-upgrade-on-boot
  • version : 1.1-11
  • architecture : all
  • categories : System and network,Security
  • maintainer : Tranquil IT
  • description : Trigger "wapt-get upgrade" when the PC boot
  • locale :
  • target_os : windows
  • min_wapt_version : 1.5
  • sources :
  • installed_size :
  • impacted_process :
  • description_fr : Lance un "wapt-get upgrade" quand le PC démarre
  • description_pl :
  • description_de :
  • description_es :
  • description_pt :
  • description_it :
  • description_nl :
  • description_ru :
  • editor :
  • licence :
  • signature_date : 2020-11-13T11:45:26.641124

  Setup.py 

# -*- coding: utf-8 -*-
from setuphelpers import *
from setuphelpers_windows import *
uninstallkey = []

# Defining variables
task_name = 'WAPTupgradeOnBoot'


def install():
    # Creating the scheduled task
    if task_exists(task_name):
        delete_task(task_name)
    try:
        print('Creating the task: %s' % task_name)
        create_onboot_task(task_name,'wapt-get','-S upgrade')
    except:
        print('Unable to create the task: %s' % task_name)

    # Removing the old scheduled task
    if task_exists('auto-wapt-upgrade-on-boot'):
        try:
            delete_task('auto-wapt-upgrade-on-boot')
        except:
            print('Unable to disable the task: auto-wapt-upgrade-on-boot')


def uninstall():
    # Removing the scheduled task
    if task_exists(task_name):
        try:
            delete_task(task_name)
        except:
            print('Unable to disable the task: %s' % task_name)


def audit():
    if not task_exists(task_name):
        print("task %s don't exist, WAPT is installing package to fix that" % task_name)
        install()
        return "WARNING"
    if not enable_task(task_name):
        print("task %s is disable, WAPT is going to enable the task" % task_name)
        enable_task(task_name)
        return "WARNING"
    else:
        print("task %s exist and is active" % task_name)
        return "OK"


def update_package():
    # Initializing variables
    version = control.version.split('-')[0]

    # Incrementing version of the package
    control.version = '%s-%s'%(version,int(control.version.split('-')[-1])+1)
    control.save_control_to_wapt()
    print('Changing package version to: %s in WAPT\\control' % control.version)




def create_onboot_task(name, cmd, parameters, max_runtime=10):
    """creates a Windows scheduled task on boot and activate it.

    Args:
        name (str): name of task for reference
        cmd(str) :  command line
        parameters (str) : arguments to append to cmd
        max_runtime (int): maximum running time in minutes

    Returns:
        PyITask: scheduled task
    """
    ts = pythoncom.CoCreateInstance(taskscheduler.CLSID_CTaskScheduler, None,
                                    pythoncom.CLSCTX_INPROC_SERVER,
                                    taskscheduler.IID_ITaskScheduler)

    if '%s.job' % name not in ts.Enum():
        task = ts.NewWorkItem(name)

        task.SetApplicationName(cmd)
        task.SetParameters(parameters)
        task.SetAccountInformation('', None)
        if max_runtime:
            task.SetMaxRunTime(max_runtime * 60*1000)
        #task.SetFlags(task.GetFlags() | taskscheduler.TASK_FLAG_)
        ts.AddWorkItem(name, task)
        run_time = time.localtime(time.time() + 300)
        tr_ind, tr = task.CreateTrigger()
        tt = tr.GetTrigger()
        tt.Flags = 0
        tt.BeginYear = int(time.strftime('%Y', run_time))
        tt.BeginMonth = int(time.strftime('%m', run_time))
        tt.BeginDay = int(time.strftime('%d', run_time))
        tt.TriggerType = int(taskscheduler.TASK_EVENT_TRIGGER_AT_SYSTEMSTART)
        tr.SetTrigger(tt)
        pf = task.QueryInterface(pythoncom.IID_IPersistFile)
        pf.Save(None, 1)
        # task.Run()
    else:
        raise KeyError("%s already exists" % name)

    task = ts.Activate(name)
    #exit_code, startup_error_code = task.GetExitCode()
    return task



										

  Changelog 



No changelog.txt.
									
  manifest.sha256