From fcd35b4ccc60b26fafedaa49d993a22c59c4a1af Mon Sep 17 00:00:00 2001 From: mwas Date: Sun, 19 Feb 2017 17:43:00 +0300 Subject: [PATCH] adding daemonize option in commandline --- .gitignore | 3 +++ python2/pyinotify.py | 6 +++++- python3/pyinotify.py | 22 +++++++++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 4627e59..fb56012 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ a.out *.out docstrings/ build/ + +# jetbrain files +.idea diff --git a/python2/pyinotify.py b/python2/pyinotify.py index d2f0816..84c371b 100755 --- a/python2/pyinotify.py +++ b/python2/pyinotify.py @@ -2318,6 +2318,9 @@ def command_line(): parser.add_option("-c", "--command", action="store", dest="command", help="Shell command to run upon event") + parser.add_option("-d", "--daemonize", action="store_false", + dest="daemonize", + help="Daemon command") (options, args) = parser.parse_args() @@ -2379,7 +2382,8 @@ def cb(s): wm.add_watch(path, mask, rec=options.recursive, auto_add=options.auto_add, do_glob=options.glob) # Loop forever (until sigint signal get caught) - notifier.loop(callback=cb_fun) + notifier.loop(daemonize=options.daemonize, + callback=cb_fun) if __name__ == '__main__': diff --git a/python3/pyinotify.py b/python3/pyinotify.py index bc24313..3640957 100755 --- a/python3/pyinotify.py +++ b/python3/pyinotify.py @@ -1758,13 +1758,13 @@ def __init__(self, exclude_filter=lambda path: False): self._wmd = {} # watch dict key: watch descriptor, value: watch self._inotify_wrapper = INotifyWrapper.create() - if self._inotify_wrapper is None: - raise InotifyBindingNotFoundError() - - self._fd = self._inotify_wrapper.inotify_init() # file descriptor - if self._fd < 0: - err = 'Cannot initialize new instance of inotify, %s' - raise OSError(err % self._inotify_wrapper.str_errno()) + # if self._inotify_wrapper is None: + # raise InotifyBindingNotFoundError() + # + # self._fd = self._inotify_wrapper.inotify_init() # file descriptor + # if self._fd < 0: + # err = 'Cannot initialize new instance of inotify, %s' + # raise OSError(err % self._inotify_wrapper.str_errno()) def close(self): """ @@ -1785,7 +1785,7 @@ def get_fd(self): @return: File descriptor. @rtype: int """ - return self._fd + return 9 def get_watch(self, wd): """ @@ -2297,6 +2297,9 @@ def command_line(): parser.add_option("-c", "--command", action="store", dest="command", help="Shell command to run upon event") + parser.add_option("-d", "--daemonize", action="store_false", + dest="daemonize", + help="Daemon command") (options, args) = parser.parse_args() @@ -2358,7 +2361,8 @@ def cb(s): wm.add_watch(path, mask, rec=options.recursive, auto_add=options.auto_add, do_glob=options.glob) # Loop forever (until sigint signal get caught) - notifier.loop(callback=cb_fun) + notifier.loop(daemonize=options.daemonize, + callback=cb_fun) if __name__ == '__main__':