[Python-modules-commits] [pyinotify] 02/03: Import pyinotify_0.9.6.orig.tar.gz
Corey Bryant
coreycb-guest at moszumanska.debian.org
Wed Dec 16 19:57:46 UTC 2015
This is an automated email from the git hooks/post-receive script.
coreycb-guest pushed a commit to branch master
in repository pyinotify.
commit 6ed645289ebd8d8022339f01bda7fcdfed9d78c0
Author: Corey Bryant <corey.bryant at canonical.com>
Date: Wed Dec 16 14:40:02 2015 -0500
Import pyinotify_0.9.6.orig.tar.gz
---
python2/pyinotify.py | 122 +++++++++++++++++++--------------------------------
python3/pyinotify.py | 108 ++++++++++++++++-----------------------------
setup.py | 2 +-
3 files changed, 84 insertions(+), 148 deletions(-)
diff --git a/python2/pyinotify.py b/python2/pyinotify.py
index 2dae002..3ccc4c1 100755
--- a/python2/pyinotify.py
+++ b/python2/pyinotify.py
@@ -95,7 +95,7 @@ except ImportError:
__author__ = "seb at dbzteam.org (Sebastien Martini)"
-__version__ = "0.9.5"
+__version__ = "0.9.6"
__metaclass__ = type # Use new-style classes by default
@@ -258,10 +258,6 @@ class _CtypesLibcINotifyWrapper(INotifyWrapper):
assert self._libc is not None
return self._libc.inotify_rm_watch(fd, wd)
- def _sysctl(self, *args):
- assert self._libc is not None
- return self._libc.sysctl(*args)
-
# Logging
def logger_init():
@@ -278,97 +274,65 @@ log = logger_init()
# inotify's variables
-class SysCtlINotify:
+class ProcINotify:
"""
- Access (read, write) inotify's variables through sysctl. Usually it
- requires administrator rights to update them.
+ Access (read, write) inotify's variables through /proc/sys/. Note that
+ usually it requires administrator rights to update them.
Examples:
- Read max_queued_events attribute: myvar = max_queued_events.value
- Update max_queued_events attribute: max_queued_events.value = 42
"""
-
- inotify_attrs = {'max_user_instances': 1,
- 'max_user_watches': 2,
- 'max_queued_events': 3}
-
- def __init__(self, attrname, inotify_wrapper):
- # FIXME: right now only supporting ctypes
- assert ctypes
- self._attrname = attrname
- self._inotify_wrapper = inotify_wrapper
- sino = ctypes.c_int * 3
- self._attr = sino(5, 20, SysCtlINotify.inotify_attrs[attrname])
-
- @staticmethod
- def create(attrname):
- """
- Factory method instanciating and returning the right wrapper.
- """
- # FIXME: right now only supporting ctypes
- if ctypes is None:
- return None
- inotify_wrapper = _CtypesLibcINotifyWrapper()
- if not inotify_wrapper.init():
- return None
- return SysCtlINotify(attrname, inotify_wrapper)
+ def __init__(self, attr):
+ self._base = "/proc/sys/fs/inotify"
+ self._attr = attr
def get_val(self):
"""
- Gets attribute's value. Raises OSError if the operation failed.
+ Gets attribute's value.
@return: stored value.
@rtype: int
+ @raise IOError: if corresponding file in /proc/sys cannot be read.
"""
- oldv = ctypes.c_int(0)
- size = ctypes.c_int(ctypes.sizeof(oldv))
- sysctl = self._inotify_wrapper._sysctl
- res = sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(size),
- None, 0)
- if res == -1:
- raise OSError(self._inotify_wrapper.get_errno(),
- self._inotify_wrapper.str_errno())
- return oldv.value
+ file_obj = file(os.path.join(self._base, self._attr), 'r')
+ try:
+ val = int(file_obj.readline())
+ finally:
+ file_obj.close()
+ return val
def set_val(self, nval):
"""
- Sets new attribute's value. Raises OSError if the operation failed.
+ Sets new attribute's value.
@param nval: replaces current value by nval.
@type nval: int
+ @raise IOError: if corresponding file in /proc/sys cannot be written.
"""
- oldv = ctypes.c_int(0)
- sizeo = ctypes.c_int(ctypes.sizeof(oldv))
- newv = ctypes.c_int(nval)
- sizen = ctypes.c_int(ctypes.sizeof(newv))
- sysctl = self._inotify_wrapper._sysctl
- res = sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(sizeo),
- ctypes.c_voidp(ctypes.addressof(newv)),
- sizen)
- if res == -1:
- raise OSError(self._inotify_wrapper.get_errno(),
- self._inotify_wrapper.str_errno())
+ file_obj = file(os.path.join(self._base, self._attr), 'w')
+ try:
+ file_obj.write(str(nval) + '\n')
+ finally:
+ file_obj.close()
value = property(get_val, set_val)
def __repr__(self):
- return '<%s=%d>' % (self._attrname, self.get_val())
+ return '<%s=%d>' % (self._attr, self.get_val())
# Inotify's variables
#
-# FIXME: currently these variables are only accessible when ctypes is used,
-# otherwise there are set to None.
+# Note: may raise IOError if the corresponding value in /proc/sys
+# cannot be accessed.
#
-# read: myvar = max_queued_events.value
-# update: max_queued_events.value = 42
+# Examples:
+# - read: myvar = max_queued_events.value
+# - update: max_queued_events.value = 42
#
for attrname in ('max_queued_events', 'max_user_instances', 'max_user_watches'):
- globals()[attrname] = SysCtlINotify.create(attrname)
+ globals()[attrname] = ProcINotify(attrname)
class EventsCodes:
@@ -1149,8 +1113,8 @@ class Notifier:
@type default_proc_fun: instance of ProcessEvent
@param read_freq: if read_freq == 0, events are read asap,
if read_freq is > 0, this thread sleeps
- max(0, read_freq - timeout) seconds. But if
- timeout is None it may be different because
+ max(0, read_freq - (timeout / 1000)) seconds. But
+ if timeout is None it may be different because
poll is blocking waiting for something to read.
@type read_freq: int
@param threshold: File descriptor will be read only if the accumulated
@@ -1161,8 +1125,9 @@ class Notifier:
until the amount of events to read is >= threshold.
At least with read_freq set you might sleep.
@type threshold: int
- @param timeout:
- https://docs.python.org/3/library/select.html#polling-objects
+ @param timeout: see read_freq above. If provided, it must be set in
+ milliseconds. See
+ https://docs.python.org/2/library/select.html#polling-objects
@type timeout: int
"""
# Watch Manager instance
@@ -1228,7 +1193,8 @@ class Notifier:
milliseconds.
@param timeout: If specified it overrides the corresponding instance
- attribute _timeout.
+ attribute _timeout. timeout must be sepcified in
+ milliseconds.
@type timeout: int
@return: New events to read.
@@ -1441,9 +1407,12 @@ class Notifier:
Close inotify's instance (close its file descriptor).
It destroys all existing watches, pending events,...
This method is automatically called at the end of loop().
+ Afterward it is invalid to access this instance.
"""
- self._pollobj.unregister(self._fd)
- os.close(self._fd)
+ if self._fd is not None:
+ self._pollobj.unregister(self._fd)
+ os.close(self._fd)
+ self._fd = None
self._sys_proc_fun = None
@@ -1468,7 +1437,7 @@ class ThreadedNotifier(threading.Thread, Notifier):
@type default_proc_fun: instance of ProcessEvent
@param read_freq: if read_freq == 0, events are read asap,
if read_freq is > 0, this thread sleeps
- max(0, read_freq - timeout) seconds.
+ max(0, read_freq - (timeout / 1000)) seconds.
@type read_freq: int
@param threshold: File descriptor will be read only if the accumulated
size to read becomes >= threshold. If != 0, you likely
@@ -1478,8 +1447,9 @@ class ThreadedNotifier(threading.Thread, Notifier):
until the amount of events to read is >= threshold. At
least with read_freq you might sleep.
@type threshold: int
- @param timeout:
- https://docs.python.org/3/library/select.html#polling-objects
+ @param timeout: see read_freq above. If provided, it must be set in
+ milliseconds. See
+ https://docs.python.org/2/library/select.html#select.poll.poll
@type timeout: int
"""
# Init threading base class
@@ -1911,7 +1881,7 @@ class WatchManager:
although unicode paths are accepted there are converted to byte
strings before a watch is put on that path. The encoding used for
converting the unicode object is given by sys.getfilesystemencoding().
- If |path| si already watched it is ignored, but if it is called with
+ If |path| is already watched it is ignored, but if it is called with
option rec=True a watch is put on each one of its not-watched
subdirectory.
diff --git a/python3/pyinotify.py b/python3/pyinotify.py
index df4034a..4eb03b0 100755
--- a/python3/pyinotify.py
+++ b/python3/pyinotify.py
@@ -92,7 +92,7 @@ except ImportError:
__author__ = "seb at dbzteam.org (Sebastien Martini)"
-__version__ = "0.9.5"
+__version__ = "0.9.6"
# Compatibity mode: set to True to improve compatibility with
@@ -251,10 +251,6 @@ class _CtypesLibcINotifyWrapper(INotifyWrapper):
assert self._libc is not None
return self._libc.inotify_rm_watch(fd, wd)
- def _sysctl(self, *args):
- assert self._libc is not None
- return self._libc.sysctl(*args)
-
# Logging
def logger_init():
@@ -271,94 +267,58 @@ log = logger_init()
# inotify's variables
-class SysCtlINotify:
+class ProcINotify:
"""
- Access (read, write) inotify's variables through sysctl. Usually it
- requires administrator rights to update them.
+ Access (read, write) inotify's variables through /proc/sys/. Note that
+ usually it requires administrator rights to update them.
Examples:
- Read max_queued_events attribute: myvar = max_queued_events.value
- Update max_queued_events attribute: max_queued_events.value = 42
"""
-
- inotify_attrs = {'max_user_instances': 1,
- 'max_user_watches': 2,
- 'max_queued_events': 3}
-
- def __init__(self, attrname, inotify_wrapper):
- # FIXME: right now only supporting ctypes
- assert ctypes
- self._attrname = attrname
- self._inotify_wrapper = inotify_wrapper
- sino = ctypes.c_int * 3
- self._attr = sino(5, 20, SysCtlINotify.inotify_attrs[attrname])
-
- @staticmethod
- def create(attrname):
- # FIXME: right now only supporting ctypes
- if ctypes is None:
- return None
- inotify_wrapper = _CtypesLibcINotifyWrapper()
- if not inotify_wrapper.init():
- return None
- return SysCtlINotify(attrname, inotify_wrapper)
+ def __init__(self, attr):
+ self._base = "/proc/sys/fs/inotify"
+ self._attr = attr
def get_val(self):
"""
- Gets attribute's value. Raises OSError if the operation failed.
+ Gets attribute's value.
@return: stored value.
@rtype: int
+ @raise IOError: if corresponding file in /proc/sys cannot be read.
"""
- oldv = ctypes.c_int(0)
- size = ctypes.c_int(ctypes.sizeof(oldv))
- sysctl = self._inotify_wrapper._sysctl
- res = sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(size),
- None, 0)
- if res == -1:
- raise OSError(self._inotify_wrapper.get_errno(),
- self._inotify_wrapper.str_errno())
- return oldv.value
+ with open(os.path.join(self._base, self._attr), 'r') as file_obj:
+ return int(file_obj.readline())
def set_val(self, nval):
"""
- Sets new attribute's value. Raises OSError if the operation failed.
+ Sets new attribute's value.
@param nval: replaces current value by nval.
@type nval: int
+ @raise IOError: if corresponding file in /proc/sys cannot be written.
"""
- oldv = ctypes.c_int(0)
- sizeo = ctypes.c_int(ctypes.sizeof(oldv))
- newv = ctypes.c_int(nval)
- sizen = ctypes.c_int(ctypes.sizeof(newv))
- sysctl = self._inotify_wrapper._sysctl
- res = sysctl(self._attr, 3,
- ctypes.c_voidp(ctypes.addressof(oldv)),
- ctypes.addressof(sizeo),
- ctypes.c_voidp(ctypes.addressof(newv)),
- sizen)
- if res == -1:
- raise OSError(self._inotify_wrapper.get_errno(),
- self._inotify_wrapper.str_errno())
+ with open(os.path.join(self._base, self._attr), 'w') as file_obj:
+ file_obj.write(str(nval) + '\n')
value = property(get_val, set_val)
def __repr__(self):
- return '<%s=%d>' % (self._attrname, self.get_val())
+ return '<%s=%d>' % (self._attr, self.get_val())
# Inotify's variables
#
-# FIXME: currently these variables are only accessible when ctypes is used,
-# otherwise there are set to None.
+# Note: may raise IOError if the corresponding value in /proc/sys
+# cannot be accessed.
#
-# read: myvar = max_queued_events.value
-# update: max_queued_events.value = 42
+# Examples:
+# - read: myvar = max_queued_events.value
+# - update: max_queued_events.value = 42
#
for attrname in ('max_queued_events', 'max_user_instances', 'max_user_watches'):
- globals()[attrname] = SysCtlINotify.create(attrname)
+ globals()[attrname] = ProcINotify(attrname)
class EventsCodes:
@@ -1139,7 +1099,7 @@ class Notifier:
@type default_proc_fun: instance of ProcessEvent
@param read_freq: if read_freq == 0, events are read asap,
if read_freq is > 0, this thread sleeps
- max(0, read_freq - timeout) seconds. But if
+ max(0, read_freq - (timeout / 1000)) seconds. But if
timeout is None it may be different because
poll is blocking waiting for something to read.
@type read_freq: int
@@ -1151,8 +1111,9 @@ class Notifier:
until the amount of events to read is >= threshold.
At least with read_freq set you might sleep.
@type threshold: int
- @param timeout:
- http://docs.python.org/lib/poll-objects.html#poll-objects
+ @param timeout: see read_freq above. If provided, it must be set in
+ milliseconds. See
+ https://docs.python.org/3/library/select.html#select.poll.poll
@type timeout: int
"""
# Watch Manager instance
@@ -1218,7 +1179,8 @@ class Notifier:
milliseconds.
@param timeout: If specified it overrides the corresponding instance
- attribute _timeout.
+ attribute _timeout. timeout must be sepcified in
+ milliseconds.
@type timeout: int
@return: New events to read.
@@ -1431,9 +1393,12 @@ class Notifier:
Close inotify's instance (close its file descriptor).
It destroys all existing watches, pending events,...
This method is automatically called at the end of loop().
+ Afterward it is invalid to access this instance.
"""
- self._pollobj.unregister(self._fd)
- os.close(self._fd)
+ if self._fd is not None:
+ self._pollobj.unregister(self._fd)
+ os.close(self._fd)
+ self._fd = None
self._sys_proc_fun = None
@@ -1458,7 +1423,7 @@ class ThreadedNotifier(threading.Thread, Notifier):
@type default_proc_fun: instance of ProcessEvent
@param read_freq: if read_freq == 0, events are read asap,
if read_freq is > 0, this thread sleeps
- max(0, read_freq - timeout) seconds.
+ max(0, read_freq - (timeout / 1000)) seconds.
@type read_freq: int
@param threshold: File descriptor will be read only if the accumulated
size to read becomes >= threshold. If != 0, you likely
@@ -1468,8 +1433,9 @@ class ThreadedNotifier(threading.Thread, Notifier):
until the amount of events to read is >= threshold. At
least with read_freq you might sleep.
@type threshold: int
- @param timeout:
- see http://docs.python.org/lib/poll-objects.html#poll-objects
+ @param timeout: see read_freq above. If provided, it must be set in
+ milliseconds. See
+ https://docs.python.org/3/library/select.html#select.poll.poll
@type timeout: int
"""
# Init threading base class
diff --git a/setup.py b/setup.py
index bec0c61..15d68ab 100755
--- a/setup.py
+++ b/setup.py
@@ -103,7 +103,7 @@ if compile_ext_mod or should_compile_ext_mod():
setup(
name='pyinotify',
- version='0.9.5',
+ version='0.9.6',
description='Linux filesystem events monitoring',
author='Sebastien Martini',
author_email='seb at dbzteam.org',
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pyinotify.git
More information about the Python-modules-commits
mailing list