def _walk(path): path = encode_path(path) for root, dirs, files in os.walk(path): raise_if_aborted() if dirs or files: for d in dirs: if hidden(d): dirs.remove(d) dirs = (decode_path(os.path.join(root, d)) for d in dirs) files = (decode_path(os.path.join(root, f)) for f in files if not hidden(f)) yield dirs, files
def select_emitter(path): import xbmcvfs import settings from utils import log if is_url(path) and xbmcvfs.exists(path): return VFSPoller if os.path.exists(encode_path(path)): if settings.POLLING: return LocalPoller if _is_remote_filesystem(path): log("select_observer: path <%s> identified as remote filesystem" % path) return LocalPoller return NativeEmitter raise IOError("No such directory: '%s'" % path)
def _is_remote_filesystem(path): from utils import log from watchdog.utils import platform if not platform.is_linux(): return False remote_fs_types = ['cifs', 'smbfs', 'nfs', 'nfs4'] escaped_path = encode_path(path.rstrip('/').replace(' ', '\\040')) try: with open('/proc/mounts', 'r') as f: for line in f: _, mount_point, fstype = line.split()[:3] if mount_point == escaped_path: log("[fstype] type is \"%s\" '%s' " % (fstype, path.decode('utf-8'))) return fstype in remote_fs_types log("[fstype] path not in /proc/mounts '%s' " % escaped_path.decode('utf-8')) return False except (IOError, ValueError) as e: log("[fstype] failed to read /proc/mounts. %s, %s" % (type(e), e)) return False
def _get_mtime(path): return os.stat(encode_path(path)).st_mtime
def _list_files(root): root = encode_path(root) paths = [os.path.join(root, name) for name in os.listdir(root) if not hidden(name)] return [decode_path(path) for path in paths if not os.path.isdir(path)]