-
Notifications
You must be signed in to change notification settings - Fork 0
/
ACSBridge.py
executable file
·62 lines (49 loc) · 1.76 KB
/
ACSBridge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
from ACSBridgeLib.HTTPListener import HTTPListenerProcess
from ACSBridgeLib.DirWatcher import DirWatcherProcess
## for loading configuration options
import yaml
## for logging
import logging
## for looping
import time
from multiprocessing import Queue
def main():
## load config:
f = open( 'config.yaml' )
config = yaml.safe_load( f )
f.close()
## Set up logging
logging.basicConfig( filename=config['LOG_FILE'],
level=logging.DEBUG,
format='%(asctime)s\t%(levelname)s: %(message)s',
datefmt='%Y-%m-%d %H:%M' )
logger = logging.getLogger( 'main' )
## extra configuration to make some levels of logging print to the console
handler = logging.StreamHandler()
handler.setLevel( logging.INFO )
## sets the format for console output (a little less wordy)
handler.setFormatter( logging.Formatter( '%(asctime)s %(levelname)s: %(message)s',
'%m-%d %H:%M') )
logger.addHandler( handler )
logger.info( "Logging set up writing to " + config['LOG_FILE'] )
## Set up process for HTTP listener
#HTTPQueue = Queue()
#HTTPProcess = HTTPListenerProcess( HTTPQueue, logger, config['PORT_IN'], config['PORT_OUT'], config['CCURE_DIR'] )
#HTTPProcess.daemon = True
#HTTPProcess.run()
DirWatcherQueue = Queue()
WatcherProcess = DirWatcherProcess( DirWatcherQueue, logger, config['CCURE_DIR'], config['CCURE_LOG_PATTERN'],
config['SMTP_SERVER'], config['SMTP_USER'], config['SMTP_PASS'], config['MAIL_FROM'], config['MAIL_TO'] )
#DirWatcherProcess.daemon = True
WatcherProcess.run()
try:
while True:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
logger.info( "Keyboard interrupt recieved. Shutting down server." )
# HTTPQueue.put( 1 )
DirWatcherQueue.put( 1 )
## run main
if __name__ == '__main__':
main()