extended commit (see note)
- Slight overhaul of init() system; added ``edbob.init_modules()`` function. - Added ``read_service()`` method to ``AppConfigParser`` class, for use with Windows services. - Added generic ``Service`` class to ``edbob.win32`` module. (File monitor now inherits from it.) - Tweaked ``edbob.db`` initialization somewhat. (``Base.metadata`` no longer binds to ``edbob.db.engine``.) - Fixed guest role bug in ``edbob.db.auth.has_permission()`` function. - Added "automagical" enumeration support for database extensions. - Added ``EMAIL_PREFERENCE`` enum to ``contact`` database extension. - Tweaked ``edbob.pyramid.includeme()``. - Tweaked ``people`` Pyramid views.
This commit is contained in:
parent
526ff5dd6b
commit
c7e0bfef6a
18 changed files with 457 additions and 248 deletions
|
@ -35,7 +35,7 @@ import threading
|
|||
import edbob
|
||||
from edbob.errors import email_exception
|
||||
from edbob.filemon import get_monitor_profiles
|
||||
from edbob.win32 import file_is_free
|
||||
from edbob.win32 import Service, file_is_free
|
||||
|
||||
if sys.platform == 'win32': # docs should build for everyone
|
||||
import win32api
|
||||
|
@ -50,36 +50,23 @@ if sys.platform == 'win32': # docs should build for everyone
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FileMonitorService(win32serviceutil.ServiceFramework):
|
||||
class FileMonitorService(Service):
|
||||
"""
|
||||
Implements edbob's file monitor Windows service.
|
||||
"""
|
||||
|
||||
_svc_name_ = "Edbob File Monitor"
|
||||
_svc_name_ = 'EdbobFileMonitor'
|
||||
_svc_display_name_ = "Edbob : File Monitoring Service"
|
||||
_svc_description_ = ("Monitors one or more folders for incoming files, "
|
||||
"and performs configured actions as new files arrive.")
|
||||
|
||||
appname = 'edbob'
|
||||
|
||||
def __init__(self, args):
|
||||
"""
|
||||
Constructor.
|
||||
"""
|
||||
|
||||
# super(FileMonitorService, self).__init__(args)
|
||||
win32serviceutil.ServiceFramework.__init__(self, args)
|
||||
|
||||
# Create "wait stop" event, for main worker loop.
|
||||
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
|
||||
|
||||
def Initialize(self):
|
||||
"""
|
||||
Service initialization.
|
||||
"""
|
||||
|
||||
# Read configuration file(s).
|
||||
edbob.init(self.appname)
|
||||
if not Service.Initialize(self):
|
||||
return False
|
||||
|
||||
# Read monitor profile(s) from config.
|
||||
self.monitored = get_monitor_profiles(self.appname)
|
||||
|
@ -118,50 +105,6 @@ class FileMonitorService(win32serviceutil.ServiceFramework):
|
|||
|
||||
return True
|
||||
|
||||
def SvcDoRun(self):
|
||||
"""
|
||||
This method is invoked when the service starts.
|
||||
"""
|
||||
|
||||
import servicemanager
|
||||
|
||||
# Write start occurrence to Windows Event Log.
|
||||
servicemanager.LogMsg(
|
||||
servicemanager.EVENTLOG_INFORMATION_TYPE,
|
||||
servicemanager.PYS_SERVICE_STARTED,
|
||||
(self._svc_name_, ''))
|
||||
|
||||
# Figure out what we're supposed to be doing.
|
||||
if self.Initialize():
|
||||
|
||||
# Wait infinitely for stop request, while threads do their thing.
|
||||
log.info("SvcDoRun: All threads started; waiting for stop request.")
|
||||
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
|
||||
log.info("SvcDoRun: Stop request received.")
|
||||
|
||||
else: # Nothing to be done...
|
||||
msg = "Nothing to do! No valid monitor profiles found in config."
|
||||
servicemanager.LogWarningMsg(msg)
|
||||
log.warning("SvcDoRun: %s" % msg)
|
||||
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
|
||||
|
||||
# Write stop occurrence to Windows Event Log.
|
||||
servicemanager.LogMsg(
|
||||
servicemanager.EVENTLOG_INFORMATION_TYPE,
|
||||
servicemanager.PYS_SERVICE_STOPPED,
|
||||
(self._svc_name_, ''))
|
||||
|
||||
def SvcStop(self):
|
||||
"""
|
||||
This method is invoked when the service is requested to stop itself.
|
||||
"""
|
||||
|
||||
# Let the SCM know we're trying to stop.
|
||||
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
|
||||
|
||||
# Let worker loop know its job is done.
|
||||
win32event.SetEvent(self.hWaitStop)
|
||||
|
||||
|
||||
def monitor_files(queue, path, profile):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue