mirror of
https://github.com/powerline/powerline.git
synced 2025-07-26 23:35:04 +02:00
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
|
# vim:fileencoding=UTF-8:noet
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, sys, errno, time
|
import os
|
||||||
|
import sys
|
||||||
|
import errno
|
||||||
|
import time
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
|
|
||||||
class INotifyError(Exception):
|
class INotifyError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class INotifyWatch(object):
|
class INotifyWatch(object):
|
||||||
|
|
||||||
is_stat_based = False
|
is_stat_based = False
|
||||||
@ -18,38 +22,38 @@ class INotifyWatch(object):
|
|||||||
# See <sys/inotify.h> for the flags defined below
|
# See <sys/inotify.h> for the flags defined below
|
||||||
|
|
||||||
# Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH.
|
# Supported events suitable for MASK parameter of INOTIFY_ADD_WATCH.
|
||||||
ACCESS = 0x00000001 # File was accessed.
|
ACCESS = 0x00000001 # File was accessed.
|
||||||
MODIFY = 0x00000002 # File was modified.
|
MODIFY = 0x00000002 # File was modified.
|
||||||
ATTRIB = 0x00000004 # Metadata changed.
|
ATTRIB = 0x00000004 # Metadata changed.
|
||||||
CLOSE_WRITE = 0x00000008 # Writtable file was closed.
|
CLOSE_WRITE = 0x00000008 # Writtable file was closed.
|
||||||
CLOSE_NOWRITE = 0x00000010 # Unwrittable file closed.
|
CLOSE_NOWRITE = 0x00000010 # Unwrittable file closed.
|
||||||
OPEN = 0x00000020 # File was opened.
|
OPEN = 0x00000020 # File was opened.
|
||||||
MOVED_FROM = 0x00000040 # File was moved from X.
|
MOVED_FROM = 0x00000040 # File was moved from X.
|
||||||
MOVED_TO = 0x00000080 # File was moved to Y.
|
MOVED_TO = 0x00000080 # File was moved to Y.
|
||||||
CREATE = 0x00000100 # Subfile was created.
|
CREATE = 0x00000100 # Subfile was created.
|
||||||
DELETE = 0x00000200 # Subfile was deleted.
|
DELETE = 0x00000200 # Subfile was deleted.
|
||||||
DELETE_SELF = 0x00000400 # Self was deleted.
|
DELETE_SELF = 0x00000400 # Self was deleted.
|
||||||
MOVE_SELF = 0x00000800 # Self was moved.
|
MOVE_SELF = 0x00000800 # Self was moved.
|
||||||
|
|
||||||
# Events sent by the kernel.
|
# Events sent by the kernel.
|
||||||
UNMOUNT = 0x00002000 # Backing fs was unmounted.
|
UNMOUNT = 0x00002000 # Backing fs was unmounted.
|
||||||
Q_OVERFLOW = 0x00004000 # Event queued overflowed.
|
Q_OVERFLOW = 0x00004000 # Event queued overflowed.
|
||||||
IGNORED = 0x00008000 # File was ignored.
|
IGNORED = 0x00008000 # File was ignored.
|
||||||
|
|
||||||
# Helper events.
|
# Helper events.
|
||||||
CLOSE = (CLOSE_WRITE | CLOSE_NOWRITE) # Close.
|
CLOSE = (CLOSE_WRITE | CLOSE_NOWRITE) # Close.
|
||||||
MOVE = (MOVED_FROM | MOVED_TO) # Moves.
|
MOVE = (MOVED_FROM | MOVED_TO) # Moves.
|
||||||
|
|
||||||
# Special flags.
|
# Special flags.
|
||||||
ONLYDIR = 0x01000000 # Only watch the path if it is a directory.
|
ONLYDIR = 0x01000000 # Only watch the path if it is a directory.
|
||||||
DONT_FOLLOW = 0x02000000 # Do not follow a sym link.
|
DONT_FOLLOW = 0x02000000 # Do not follow a sym link.
|
||||||
EXCL_UNLINK = 0x04000000 # Exclude events on unlinked objects.
|
EXCL_UNLINK = 0x04000000 # Exclude events on unlinked objects.
|
||||||
MASK_ADD = 0x20000000 # Add to the mask of an already existing watch.
|
MASK_ADD = 0x20000000 # Add to the mask of an already existing watch.
|
||||||
ISDIR = 0x40000000 # Event occurred against dir.
|
ISDIR = 0x40000000 # Event occurred against dir.
|
||||||
ONESHOT = 0x80000000 # Only send event once.
|
ONESHOT = 0x80000000 # Only send event once.
|
||||||
|
|
||||||
# All events which a program can wait on.
|
# All events which a program can wait on.
|
||||||
ALL_EVENTS = (ACCESS | MODIFY | ATTRIB | CLOSE_WRITE | CLOSE_NOWRITE |
|
ALL_EVENTS = (ACCESS | MODIFY | ATTRIB | CLOSE_WRITE | CLOSE_NOWRITE |
|
||||||
OPEN | MOVED_FROM | MOVED_TO | CREATE | DELETE |
|
OPEN | MOVED_FROM | MOVED_TO | CREATE | DELETE |
|
||||||
DELETE_SELF | MOVE_SELF)
|
DELETE_SELF | MOVE_SELF)
|
||||||
|
|
||||||
@ -58,7 +62,8 @@ class INotifyWatch(object):
|
|||||||
NONBLOCK = 0x800
|
NONBLOCK = 0x800
|
||||||
|
|
||||||
def __init__(self, inotify_fd, add_watch, rm_watch, read, expire_time=10):
|
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._add_watch, self._rm_watch = add_watch, rm_watch
|
||||||
self._read = read
|
self._read = read
|
||||||
# We keep a reference to os to prevent it from being deleted
|
# We keep a reference to os to prevent it from being deleted
|
||||||
@ -101,9 +106,9 @@ class INotifyWatch(object):
|
|||||||
if num < 0:
|
if num < 0:
|
||||||
en = ctypes.get_errno()
|
en = ctypes.get_errno()
|
||||||
if en == errno.EAGAIN:
|
if en == errno.EAGAIN:
|
||||||
break # No more data
|
break # No more data
|
||||||
if en == errno.EINTR:
|
if en == errno.EINTR:
|
||||||
continue # Interrupted, try again
|
continue # Interrupted, try again
|
||||||
raise OSError(en, self.os.strerror(en))
|
raise OSError(en, self.os.strerror(en))
|
||||||
buf.append(self._buf.raw[:num])
|
buf.append(self._buf.raw[:num])
|
||||||
raw = b''.join(buf)
|
raw = b''.join(buf)
|
||||||
@ -194,6 +199,7 @@ class INotifyWatch(object):
|
|||||||
del self._rm_watch
|
del self._rm_watch
|
||||||
del self._inotify_fd
|
del self._inotify_fd
|
||||||
|
|
||||||
|
|
||||||
def get_inotify(expire_time=10):
|
def get_inotify(expire_time=10):
|
||||||
''' Initialize the inotify based file watcher '''
|
''' Initialize the inotify based file watcher '''
|
||||||
import ctypes
|
import ctypes
|
||||||
@ -226,14 +232,13 @@ def get_inotify(expire_time=10):
|
|||||||
read = prototype(('read', libc), (
|
read = prototype(('read', libc), (
|
||||||
(1, "fd"), (1, "buf"), (1, "count")), use_errno=True)
|
(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:
|
if inotify_fd == -1:
|
||||||
raise INotifyError(os.strerror(ctypes.get_errno()))
|
raise INotifyError(os.strerror(ctypes.get_errno()))
|
||||||
return INotifyWatch(inotify_fd, add_watch, rm_watch, read, expire_time=expire_time)
|
return INotifyWatch(inotify_fd, add_watch, rm_watch, read, expire_time=expire_time)
|
||||||
|
|
||||||
class StatWatch(object):
|
|
||||||
|
|
||||||
|
class StatWatch(object):
|
||||||
is_stat_based = True
|
is_stat_based = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -266,6 +271,7 @@ class StatWatch(object):
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
self.watches = {}
|
self.watches = {}
|
||||||
|
|
||||||
|
|
||||||
def create_file_watcher(use_stat=False, expire_time=10):
|
def create_file_watcher(use_stat=False, expire_time=10):
|
||||||
'''
|
'''
|
||||||
Create an object that can watch for changes to specified files. To use:
|
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__':
|
if __name__ == '__main__':
|
||||||
watcher = create_file_watcher()
|
watcher = create_file_watcher()
|
||||||
print ('Using watcher: %s'%watcher.__class__.__name__)
|
print ('Using watcher: %s' % watcher.__class__.__name__)
|
||||||
print ('Watching %s, press Ctrl-C to quit'%sys.argv[-1])
|
print ('Watching %s, press Ctrl-C to quit' % sys.argv[-1])
|
||||||
watcher.watch(sys.argv[-1])
|
watcher.watch(sys.argv[-1])
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if watcher(sys.argv[-1]):
|
if watcher(sys.argv[-1]):
|
||||||
print ('%s has changed'%sys.argv[-1])
|
print ('%s has changed' % sys.argv[-1])
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
watcher.close()
|
watcher.close()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user