mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
made bgservice.py into a class
This commit is contained in:
parent
778446baa2
commit
0d737d91c6
|
@ -5,13 +5,13 @@ import time
|
||||||
import event_processor
|
import event_processor
|
||||||
|
|
||||||
|
|
||||||
class SkoolOSDaemmon:
|
class SkoolOSDaemon:
|
||||||
"""Constructor"""
|
"""Constructor"""
|
||||||
def __init__(self, work_dir):
|
def __init__(self, work_dir):
|
||||||
self.work_dir = work_dir
|
self.work_dir = work_dir
|
||||||
self.start_time = None
|
self.start_time = None
|
||||||
self.end_time = None
|
self.end_time = None
|
||||||
"""Stores the pid of the program to be terminated externally"""
|
self.log_file = None
|
||||||
def write_pid_file(self):
|
def write_pid_file(self):
|
||||||
pid = str(os.getpid())
|
pid = str(os.getpid())
|
||||||
file_ = open('/tmp/skoolosdaemonpid', 'w')
|
file_ = open('/tmp/skoolosdaemonpid', 'w')
|
||||||
|
@ -19,12 +19,17 @@ class SkoolOSDaemmon:
|
||||||
file_.close()
|
file_.close()
|
||||||
def readable_time(self, input_time):
|
def readable_time(self, input_time):
|
||||||
return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time))
|
return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time))
|
||||||
def start_service(self):
|
def start(self):
|
||||||
start_time = time.time()
|
self.start_time = time.time()
|
||||||
log_file = open('/tmp/skooloslog-' + start_time, 'w')
|
self.log_file = open('/tmp/skooloslogs/' + str(self.start_time), 'w')
|
||||||
log_file.write("Started work: " + self.readable_time(start_time))
|
self.log_file.write("Started work: \n" + self.readable_time(self.start_time))
|
||||||
sys.stdout = log_file
|
sys.stdout = self.log_file
|
||||||
event_processor.watch_dir(self.work_dir)
|
event_processor.watch_dir(self.work_dir)
|
||||||
|
def stop(self):
|
||||||
|
self.end_time = time.time()
|
||||||
|
self.log_file.write("Stop time: \n" + self.readable_time(self.end_time))
|
||||||
|
self.log_file.write("Total work time: " +
|
||||||
|
time.strftime("%H:%M:%S", time.gmtime(self.end_time - self.start_time)))
|
||||||
|
|
||||||
|
|
||||||
def Main():
|
def Main():
|
||||||
|
|
|
@ -29,10 +29,15 @@ def __method_format(method):
|
||||||
|
|
||||||
def __process_generator(cls, method):
|
def __process_generator(cls, method):
|
||||||
def _method_name(self, event):
|
def _method_name(self, event):
|
||||||
print("Method name: {} ()\n"
|
print("Event description: {}\n"
|
||||||
"Path name: {}\n"
|
"Path name: {}\n"
|
||||||
"Event Name: {}\n"
|
"Event Name: {}\n"
|
||||||
"Timestamp: {}\n".format(__method_format(method), event.pathname, event.maskname, readable_time(time.time())))
|
"Timestamp: {}\n".format(__method_format(method),
|
||||||
|
event.pathname,
|
||||||
|
event.maskname,
|
||||||
|
readable_time(time.time())
|
||||||
|
)
|
||||||
|
)
|
||||||
_method_name.__name__ = "process_{}".format(method)
|
_method_name.__name__ = "process_{}".format(method)
|
||||||
setattr(cls, _method_name.__name__, _method_name)
|
setattr(cls, _method_name.__name__, _method_name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user