#!/usr/bin/env python ###### #Scheduler library for Lliurex #Add to N4D the scheduled tasks #This class reads the json file with the scheduled tasks and #distributes the info among the clients # -*- coding: utf-8 -*- import os import json from datetime import date class SchedulerServer(): def __init__(self): self.dbg=0 self.tasks_dir="/etc/scheduler/tasks.d" self.schedTasksDir=self.tasks_dir+"/scheduled" self.available_tasks_dir="/etc/scheduler/conf.d/tasks" self.custom_tasks=self.available_tasks_dir+"/personal.json" self.remote_tasks_dir=self.tasks_dir+"/remote" self.local_tasks_dir=self.tasks_dir+"/local" self.commands_file='/etc/scheduler/conf.d/commands/commands.json' #def __init__ def _debug(self,msg): if (self.dbg): print("Scheduler: %s" %msg) #def _debug def get_tasks(self,*args): return(self._read_wrkfiles(self.tasks_dir)) #def get_tasks def get_local_tasks(self,*args): today=date.today() local_tasks={} tasks_data=self._read_wrkfiles(self.tasks_dir)['data'].copy() status=False for task_name,serial_data in tasks_data.items(): sw_continue=False for serial,data in serial_data.items(): print("DATA: %s"%data) sw_pass=False if 'autoremove' in data.keys(): if (data['mon'].isdigit()): mon=int(data['mon']) if mon=1000: val=0 val+=1 objects["VariablesManager"].set_variable("SCHEDULED_TASKS",val) self._debug("New value is %s"%val) #def _register_cron_update