def _main(self, lib, opts, args): try: log_path = self.config['log_path'].as_filename() except: log_path = None logging.basicConfig( filename=log_path, level=logging.WARNING, format="%(asctime)s [%(filename)s:%(lineno)s] %(levelname)s %(message)s" ) _logger.setLevel(logging.INFO) logging.getLogger('beets').addHandler(logging.getLogger().handlers[0]) self.register_listener('import_begin', self.on_import_begin) self.register_listener('import_task_created', self.on_import_task_created) self.register_listener('item_imported', self.on_item_imported) i = InotifyTree(self.dropbox_path) _logger.info("Drop2beets starting to watch %s", self.dropbox_path) for event in i.event_gen(): if event is None: continue event_type = event[1] folder = event[2] filename = event[3] if 'IN_ISDIR' in event_type: continue #print("event_type=%s, folder=%s, filename=%s" % (event_type, folder, filename)) if 'IN_MOVED_TO' in event_type or 'IN_CLOSE_WRITE' in event_type: _logger.info("Processing %s", filename) full_path = "%s/%s" % (folder, filename) import_files(lib, [full_path], None)
def __init__(self, **options): self.load_config(options) self._thread = None self._thread_lock = RLock() self._stop_event = Event() self._stop_event.set() InotifyTree.__init__(self, self.config["dir"], self.config["event_mask"]) with app.app_context(): Interface.__init__(self, "watcher")
def build(indir, outdir, media, watch): build_func(indir, outdir, media) if watch: from inotify.adapters import InotifyTree click.secho('Watching {}'.format(indir), fg='blue') i = InotifyTree(indir.encode('utf-8')) try: for event in i.event_gen(): if event is not None: (header, type_names, watch_path, filename) = event if 'IN_MODIFY' in type_names: build_func(indir, outdir, media) except KeyboardInterrupt: return
def notify(cls, root: str, spec: str) -> Callable: ''' todo: docs ''' from inotify.adapters import InotifyTree from inotify.constants import IN_CLOSE_WRITE, IN_CREATE task = InotifyTree(root, IN_CLOSE_WRITE | IN_CREATE) uniq = lambda i: (i[2], int(time() / 60)) for tick, _ in groupby(task.event_gen(yield_nones=0), key=uniq): file = '{}/{}'.format(tick[0], spec) if not '.git' in file and path.isfile(file): logger().debug('Observed change in %s', tick[0]) yield lambda i=file: cls.__parser(i)
async def live_watch_inputs(self, topdir, suffix=FAST5_SUFFIX): from inotify.adapters import InotifyTree from inotify.constants import IN_CLOSE_WRITE, IN_MOVED_TO watch_flags = IN_CLOSE_WRITE | IN_MOVED_TO topdir = os.path.abspath(topdir + '/') + '/' # add / for commonprefix is_fast5_to_analyze = lambda fn: fn[:1] != '.' and fn.lower().endswith( suffix) try: evgen = InotifyTree(topdir, mask=watch_flags).event_gen() while True: event = await self.run_in_executor_mon(next, evgen) if event is None: continue header, type_names, path, filename = event if 'IN_ISDIR' in type_names: continue if header.mask & watch_flags and is_fast5_to_analyze(filename): common = os.path.commonprefix([topdir, path]) if common != topdir: errprint( "ERROR: Change of {} detected, which is outside " "{}.".format(path, topdir)) continue relpath = os.path.join(path[len(common):], filename) for readpath in get_read_ids(relpath, topdir): if readpath not in self.reads_done: self.queue_processing(readpath) except CancelledError: pass
def run(self): # mask out a few boring events mask = inotify.constants.IN_ALL_EVENTS & ~( inotify.constants.IN_ACCESS | inotify.constants.IN_CLOSE_NOWRITE | inotify.constants.IN_OPEN) # set up the watchers notifier = InotifyTree(self._src, block_duration_s=3600, mask=mask) # perform an initial sync self._sync_thread() for event in notifier.event_gen(): if event is None: continue self._schedule_sync()
def main(): arguments = Arguments() dictConfig({ 'version': 1, 'formatters': { 'default': { 'format': '%(asctime)s [%(levelname)-8s] %(pathname)s:%(lineno)s (%(funcName)s) %(message)s', 'datefmt': "%Y-%m-%d %H:%M:%S", }, }, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'level': max(0, 10 * (4 - arguments.verbosity_level)), }, 'file': { 'backupCount': 14, 'class': 'logging.handlers.TimedRotatingFileHandler', 'filename': join(arguments.output_path, 'wisdom-cli.log'), 'formatter': 'default', 'level': 'DEBUG', 'when': 'midnight', }, }, 'root': { 'handlers': ['console', 'file'], 'level': 'DEBUG', }, }) info('wisdom-cli "%s"', '" "'.join(argv)) if arguments.watch_path: from inotify.adapters import InotifyTree from inotify.constants import IN_CLOSE_WRITE inotify = InotifyTree(arguments.watch_path, IN_CLOSE_WRITE, 24 * 60 * 60) while True: time_nano_from = perf_counter_ns() try: process(arguments) except Exception: error(format_exc()) time_nano_till = perf_counter_ns() span_nano = time_nano_till - time_nano_from span_micro = span_nano // 1000 span_milli = span_micro // 1000 total_full = span_milli // 1000 total_milli = span_milli % 1000 info(f'{total_full} seconds {total_milli} milliseconds elapsed.') for e in inotify.event_gen(): if e: _, _, path, name = e info('inotify "%s/%s"', path, name) else: break sleep(0.1) else: process(arguments)
# AwesomeShop is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more # details. # # You should have received a copy of the GNU Affero General Public License # along with AwesomeShop. If not, see <http://www.gnu.org/licenses/>. """Automatic generation of HTML files from PLIM sources""" import os import re from inotify.adapters import InotifyTree from plim import preprocessor FROM='front' TO='webroot' i = InotifyTree(FROM) for event in i.event_gen(): if event is not None and 'IN_CLOSE_WRITE' in event[1]: if event[3].endswith('.plim'): filename = os.path.join(event[2], event[3]) target = re.sub(FROM+'/(.*).plim', TO+r'/\1.html', filename) dirname = os.path.dirname(target) result = preprocessor(file(filename, 'r').read()) if not os.path.exists(dirname): os.makedirs(dirname) file(target, 'w').write(result) print "Regenerated", target