本文整理汇总了Python中watchdog.utils.platform.is_linux函数的典型用法代码示例。如果您正苦于以下问题:Python is_linux函数的具体用法?Python is_linux怎么用?Python is_linux使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_linux函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
def decode(path):
if isinstance(path, bytes_cls):
try:
path = path.decode(fs_encoding, 'strict')
except UnicodeDecodeError:
if not platform.is_linux():
raise
path = path.decode(fs_fallback_encoding, 'strict')
return path
示例2: encode
def encode(path):
if isinstance(path, str_cls):
try:
path = path.encode(fs_encoding, 'strict')
except (UnicodeEncodeError) as e:
if not platform.is_linux():
raise
path = path.encode(fs_fallback_encoding, 'strict')
return path
示例3: start_watching
def start_watching(path=None, use_full_emitter=False):
path = p('') if path is None else path
global emitter
if platform.is_linux() and use_full_emitter:
emitter = InotifyFullEmitter(event_queue, ObservedWatch(path, recursive=True))
else:
emitter = Emitter(event_queue, ObservedWatch(path, recursive=True))
if platform.is_darwin():
# FSEvents will report old evens (like create for mkdtemp in test
# setup. Waiting for a considerable time seems to 'flush' the events.
time.sleep(10)
emitter.start()
示例4: _is_remote_filesystem
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
示例5: _get_native_observer
def _get_native_observer():
"""
Return native observer... or fail.
"""
from watchdog.utils import platform
if platform.is_linux():
from watchdog.observers.inotify import InotifyObserver
return InotifyObserver
if platform.is_windows():
# TODO: find a reliable way of checking Windows version and import
# polling explicitly for Windows XP
try:
from watchdog.observers.read_directory_changes import (
WindowsApiObserver)
return WindowsApiObserver
except:
raise AssertionError('Native observer not supported.')
raise AssertionError('Native observer not supported.')
示例6:
subdirectories under a directory, additional watches must be created.
This emitter implementation therefore automatically adds watches for
sub-directories if running in recursive mode.
Some extremely useful articles and documentation:
.. _inotify FAQ: http://inotify.aiken.cz/?section=inotify&page=faq&lang=en
.. _intro to inotify: http://www.linuxjournal.com/article/8478
"""
from __future__ import with_statement
from watchdog.utils import platform
import errno
if platform.is_linux():
import os
import struct
import threading
import ctypes
from ctypes import\
c_int,\
c_char_p,\
c_uint32
from pathtools.path import absolute_path
from watchdog.utils import\
has_attribute,\
ctypes_find_library
from watchdog.observers.api import\
示例7: wait_for_move_event
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import unicode_literals
import os
import random
import pytest
from tests import tmpdir, p # pytest magic
from .shell import mkdir, touch, mv
from watchdog.observers.api import ObservedWatch
from watchdog.utils import platform
pytestmark = pytest.mark.skipif(not platform.is_linux(), reason="")
if platform.is_linux():
from watchdog.observers.inotify import InotifyEmitter
from watchdog.observers.inotify_buffer import InotifyBuffer
def wait_for_move_event(read_event):
while True:
event = read_event()
if isinstance(event, tuple) or event.is_move:
return event
@pytest.mark.timeout(5)
def test_move_from(p):
mkdir(p('dir1'))
示例8: setup_function
from __future__ import unicode_literals
import os
import pytest
import logging
import contextlib
from tests import Queue
from functools import partial
from .shell import rm, mkdtemp
from watchdog.utils import platform
from watchdog.events import DirCreatedEvent, DirDeletedEvent, DirModifiedEvent
from watchdog.observers.api import ObservedWatch
if platform.is_linux():
from watchdog.observers.inotify import InotifyFullEmitter, InotifyEmitter
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def setup_function(function):
global p, event_queue
tmpdir = os.path.realpath(mkdtemp())
p = partial(os.path.join, tmpdir)
event_queue = Queue()
@contextlib.contextmanager
def watching(path=None, use_full_emitter=False):
path = p('') if path is None else path
global emitter
示例9: wait_for_move_event
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import unicode_literals
import pytest
from watchdog.utils import platform
if not platform.is_linux():
pytest.skip("GNU/Linux only.", allow_module_level=True)
import os
import random
from watchdog.observers.inotify_buffer import InotifyBuffer
from .shell import mkdir, touch, mv, rm
def wait_for_move_event(read_event):
while True:
event = read_event()
if isinstance(event, tuple) or event.is_move:
return event
示例10: setup_function
# limitations under the License.
from __future__ import unicode_literals
import os
import time
import pytest
import logging
from tests import Queue
from functools import partial
from .shell import mkdir, touch, mv, rm, mkdtemp
from watchdog.utils import platform
from watchdog.utils.unicode_paths import str_cls
from watchdog.events import *
from watchdog.observers.api import ObservedWatch
pytestmark = pytest.mark.skipif(not platform.is_linux() and not platform.is_darwin(), reason="")
if platform.is_linux():
from watchdog.observers.inotify import InotifyEmitter as Emitter
elif platform.is_darwin():
from watchdog.observers.fsevents2 import FSEventsEmitter as Emitter
logging.basicConfig(level=logging.DEBUG)
def setup_function(function):
global p, event_queue
tmpdir = os.path.realpath(mkdtemp())
p = partial(os.path.join, tmpdir)
event_queue = Queue()
示例11: setup_function
import os
import threading
import time
import pytest
import logging
from tests import Queue
from functools import partial
from .shell import mkdir, touch, mv, rm, mkdtemp
from watchdog.utils import platform
from watchdog.utils.unicode_paths import str_cls
from watchdog.events import *
from watchdog.observers.api import ObservedWatch
# pytestmark = pytest.mark.skipif(not platform.is_linux() and not platform.is_darwin(),
# reason="")
if platform.is_linux():
from watchdog.observers.inotify import InotifyEmitter as Emitter
from watchdog.observers.inotify import InotifyFullEmitter
elif platform.is_darwin():
from watchdog.observers.fsevents2 import FSEventsEmitter as Emitter
elif platform.is_windows():
from watchdog.observers.read_directory_changes import WindowsApiEmitter as Emitter
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def setup_function(function):
global p, event_queue
tmpdir = os.path.realpath(mkdtemp())
p = partial(os.path.join, tmpdir)
示例12: list
from keyring.backend import _load_backend
"ensure that all keyring backends are loaded"
backends = ('file', 'Gnome', 'Google', 'keyczar', 'multi', 'OS_X', 'pyfs', 'SecretService', 'Windows')
list(map(_load_backend, backends))
import keyring.backend
keyring.backend._load_backends = _load_backends
if getattr(sys, 'frozen', False):
def _certs_where():
return str((Path(sys._MEIPASS)) / 'res' / 'cacert.pem')
requests.certs.where = _certs_where
os.environ['REQUESTS_CA_BUNDLE'] = requests.certs.where()
logging.info("Setting certificate path to " + requests.certs.where())
fs_encoding = sys.getfilesystemencoding()
if not fs_encoding and platform.is_linux():
def _watchdog_encode(path):
if isinstance(path, unicode):
path = path.encode('utf-8', 'strict')
return path
def _watchdog_decode(path):
if isinstance(path, str):
path = path.decode('utf-8', 'strict')
return path
import watchdog.utils.unicode_paths
watchdog.utils.unicode_paths.encode = _watchdog_encode
watchdog.utils.unicode_paths.decode = _watchdog_decode