'''Monitor changes to the tag markup files and update symlinks when necessary.''' import pyinotify import sys from lib.tagfiles import TagCollection from update_hierarchy import update_symlinks from lib.daemon import Daemon class DigitagDaemon(Daemon): name = 'digitagdaemon' loggingsubject = 'DigitagDaemon' logdir = '/home/petteri/digitag/logs' def __init__(self, path): Daemon.__init__(self) self.path = path def do_update(self): tc = TagCollection() tc.import_recursively(self.path, 'Merkinnat.txt') if tc.msgs: self.logger.warning('Import messages:\n' + '\n'.join(tc.msgs)) msgs = [] update_symlinks(self.path, os.path.join(path, 'Luokiteltuna'), tc, msgs) if msgs: self.logger.warning('Symlink creation messages:\n' + '\n'.join(msgs)) return tc.msgs + msgs def run(self): class EventProcessing: def process_IN_ wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm, if __name__ == '__main__': if len(sys.argv) != 2: sys.stderr.write('Usage: ' + sys.argv[0] + ' basedirectory\n') sys.exit(1) d = DigitagDaemon(sys.argv[1]) msgs = d.do_update() if msgs: print 'Startup messages:\n' + '\n'.join(msgs) d.start()