-
Notifications
You must be signed in to change notification settings - Fork 2
/
submitter.py
executable file
·48 lines (32 loc) · 1.09 KB
/
submitter.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
#!/usr/bin/python
import asyncore
import pyinotify
import sys
import os
import logging
from time import sleep
from manager.db import Database
from config.general import SAMPLES_DIR
logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s',
datefmt='%d-%m-%Y %H:%M:%S')
LOG = logging.getLogger("automated-arancino.submitter")
class EventHandler(pyinotify.ProcessEvent):
def __init__(self):
self.db = Database()
def process_IN_CLOSE_WRITE(self, event):
LOG.info("New sample {0}".format(event.pathname))
self.submit_new_sample(event.pathname)
def submit_new_sample(self, sample_path):
# TODO
LOG.info("Adding task: {0}".format(sample_path))
Database().add_task(sample_path)
def main():
wm = pyinotify.WatchManager()
# watched events
mask = pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE
notifier = pyinotify.AsyncNotifier(wm, EventHandler())
wdd = wm.add_watch(SAMPLES_DIR, mask, rec=True)
asyncore.loop()
if __name__ == "__main__":
main()