From 0d737d91c6fd6bd1f0eb1c1aca120393cc2f420b Mon Sep 17 00:00:00 2001 From: Nathaniel Kenschaft Date: Fri, 12 Jun 2020 22:07:52 -0400 Subject: [PATCH] made bgservice.py into a class --- BackgroundService/bgservice.py | 19 ++++++++++++------- BackgroundService/event_processor.py | 9 +++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/BackgroundService/bgservice.py b/BackgroundService/bgservice.py index 3ad361f..11136ec 100644 --- a/BackgroundService/bgservice.py +++ b/BackgroundService/bgservice.py @@ -5,13 +5,13 @@ import time import event_processor -class SkoolOSDaemmon: +class SkoolOSDaemon: """Constructor""" def __init__(self, work_dir): self.work_dir = work_dir self.start_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): pid = str(os.getpid()) file_ = open('/tmp/skoolosdaemonpid', 'w') @@ -19,12 +19,17 @@ class SkoolOSDaemmon: file_.close() def readable_time(self, input_time): return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time)) - def start_service(self): - start_time = time.time() - log_file = open('/tmp/skooloslog-' + start_time, 'w') - log_file.write("Started work: " + self.readable_time(start_time)) - sys.stdout = log_file + def start(self): + self.start_time = time.time() + self.log_file = open('/tmp/skooloslogs/' + str(self.start_time), 'w') + self.log_file.write("Started work: \n" + self.readable_time(self.start_time)) + sys.stdout = self.log_file 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(): diff --git a/BackgroundService/event_processor.py b/BackgroundService/event_processor.py index e2b3f5b..00f4d8a 100644 --- a/BackgroundService/event_processor.py +++ b/BackgroundService/event_processor.py @@ -29,10 +29,15 @@ def __method_format(method): def __process_generator(cls, method): def _method_name(self, event): - print("Method name: {} ()\n" + print("Event description: {}\n" "Path 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) setattr(cls, _method_name.__name__, _method_name)