Some fixes for flake8, remove executable bit and shebang
This commit is contained in:
parent
559b5caef2
commit
5d1089f252
|
@ -1,16 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:noet
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import os, sys, errno, time
|
||||
import os
|
||||
import sys
|
||||
import errno
|
||||
import time
|
||||
from threading import RLock
|
||||
|
||||
|
||||
class INotifyError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class INotifyWatch(object):
|
||||
|
||||
is_stat_based = False
|
||||
|
@ -58,7 +62,8 @@ class INotifyWatch(object):
|
|||
NONBLOCK = 0x800
|
||||
|
||||
def __init__(self, inotify_fd, add_watch, rm_watch, read, expire_time=10):
|
||||
import ctypes, struct
|
||||
import ctypes
|
||||
import struct
|
||||
self._add_watch, self._rm_watch = add_watch, rm_watch
|
||||
self._read = read
|
||||
# We keep a reference to os to prevent it from being deleted
|
||||
|
@ -194,6 +199,7 @@ class INotifyWatch(object):
|
|||
del self._rm_watch
|
||||
del self._inotify_fd
|
||||
|
||||
|
||||
def get_inotify(expire_time=10):
|
||||
''' Initialize the inotify based file watcher '''
|
||||
import ctypes
|
||||
|
@ -226,14 +232,13 @@ def get_inotify(expire_time=10):
|
|||
read = prototype(('read', libc), (
|
||||
(1, "fd"), (1, "buf"), (1, "count")), use_errno=True)
|
||||
|
||||
|
||||
inotify_fd = init1(INotifyWatch.CLOEXEC|INotifyWatch.NONBLOCK)
|
||||
inotify_fd = init1(INotifyWatch.CLOEXEC | INotifyWatch.NONBLOCK)
|
||||
if inotify_fd == -1:
|
||||
raise INotifyError(os.strerror(ctypes.get_errno()))
|
||||
return INotifyWatch(inotify_fd, add_watch, rm_watch, read, expire_time=expire_time)
|
||||
|
||||
class StatWatch(object):
|
||||
|
||||
class StatWatch(object):
|
||||
is_stat_based = True
|
||||
|
||||
def __init__(self):
|
||||
|
@ -266,6 +271,7 @@ class StatWatch(object):
|
|||
with self.lock:
|
||||
self.watches = {}
|
||||
|
||||
|
||||
def create_file_watcher(use_stat=False, expire_time=10):
|
||||
'''
|
||||
Create an object that can watch for changes to specified files. To use:
|
||||
|
@ -289,15 +295,14 @@ def create_file_watcher(use_stat=False, expire_time=10):
|
|||
|
||||
if __name__ == '__main__':
|
||||
watcher = create_file_watcher()
|
||||
print ('Using watcher: %s'%watcher.__class__.__name__)
|
||||
print ('Watching %s, press Ctrl-C to quit'%sys.argv[-1])
|
||||
print ('Using watcher: %s' % watcher.__class__.__name__)
|
||||
print ('Watching %s, press Ctrl-C to quit' % sys.argv[-1])
|
||||
watcher.watch(sys.argv[-1])
|
||||
try:
|
||||
while True:
|
||||
if watcher(sys.argv[-1]):
|
||||
print ('%s has changed'%sys.argv[-1])
|
||||
print ('%s has changed' % sys.argv[-1])
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
watcher.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue