本文整理汇总了Python中watchdog.observers.polling.PollingObserver类的典型用法代码示例。如果您正苦于以下问题:Python PollingObserver类的具体用法?Python PollingObserver怎么用?Python PollingObserver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PollingObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: watch
def watch(self):
observer = PollingObserver(0.1)
observer.schedule(self, self.path)
observer.start()
self.file = open(self.path + "\Power.log", "r")
self.on_modified(None)
self.watching = True
示例2: watch
def watch(directory=None, auto_clear=False, beep_on_failure=True,
onpass=None, onfail=None, poll=False, extensions=[]):
"""
Starts a server to render the specified file or directory
containing a README.
"""
if directory and not os.path.isdir(directory):
raise ValueError('Directory not found: ' + directory)
directory = os.path.abspath(directory or '')
# Initial run
event_handler = ChangeHandler(directory, auto_clear, beep_on_failure,
onpass, onfail, extensions)
event_handler.run()
# Setup watchdog
if poll:
observer = PollingObserver()
else:
observer = Observer()
observer.schedule(event_handler, path=directory, recursive=True)
observer.start()
# Watch and run tests until interrupted by user
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
示例3: get_contracts_code_observer
def get_contracts_code_observer(project_dir):
observer = PollingObserver()
build_path = utils.get_build_dir(project_dir)
event_handler = ContractCodeChangedEventHandler(project_dir=project_dir)
observer.schedule(event_handler, build_path, recursive=False)
return observer
示例4: watch_server
def watch_server(root_dir):
# create event handler
event_handler = OneDirServerEventHandler()
# create observer
observer = PollingObserver()
# observe the given directory recursively
observer.schedule(event_handler, path=root_dir, recursive=True)
return observer
示例5: get_active_dir_observer
def get_active_dir_observer(project_dir, event_handler):
""" Setup a polling observer on the project's
blockchains directory. This directory contains the
.active-chain symlink which is watched for.
"""
bchain = get_blockchains_dir(project_dir)
observer = PollingObserver()
observer.schedule(event_handler, bchain, recursive=False)
return observer
示例6: __init__
class Watcher:
def __init__(self):
# self.observer = Observer() # Use this if SS_DIR is local
self.observer = PollingObserver() # Use this if SS_DIR is remote mount
def run(self):
event_handler = file_changed()
self.observer.schedule(event_handler, SS_DIR, recursive=True)
self.observer.start()
loop1()
示例7: __init__
def __init__(self, basedir='.', polling=False):
"""Initialize the Monitor."""
if not polling:
self.observer = Observer()
else:
self.observer = PollingObserver()
self.handlers = []
self.basedir = basedir
self.running = False
示例8: watch_record
def watch_record(indexer, use_polling=False):
"""
Start watching `cfstore.record_path`.
:type indexer: rash.indexer.Indexer
"""
if use_polling:
from watchdog.observers.polling import PollingObserver as Observer
Observer # fool pyflakes
else:
from watchdog.observers import Observer
event_handler = RecordHandler(indexer)
observer = Observer()
observer.schedule(event_handler, path=indexer.record_path, recursive=True)
indexer.logger.debug("Start observer.")
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
indexer.logger.debug("Got KeyboardInterrupt. Stopping observer.")
observer.stop()
indexer.logger.debug("Joining observer.")
observer.join()
indexer.logger.debug("Finish watching record.")
示例9: watch
def watch(self):
"""
Start watching
"""
logger.info('Watching directory %s' % self.directory)
# Set up handler for when we see new files
callback = self.callback
class NewFileEventHandler(FileSystemEventHandler):
def on_created(self, event):
if not event.is_directory:
logger.info('Detected new file: %s' % event.src_path)
callback(event.src_path)
event_handler = NewFileEventHandler()
# Use polling observer (rather than filesystem-specific observers),
# because it is more reliable.
observer = PollingObserver(timeout=self.sleep_time)
# Start the observer
observer.schedule(event_handler, self.directory, recursive=False)
observer.start()
# Wait while the observer is running
try:
while True:
sleep(self.sleep_time)
# Exit gracefully
except KeyboardInterrupt:
logger.info('Detected interrupt. Stopping observer.')
observer.stop()
observer.join()
示例10: SuiteTable
class SuiteTable(object):
def __init__(self, dbfile=":memory:", poll=False):
self.db = sqlite3.connect(dbfile, check_same_thread=False)
self.log = logging.getLogger(__name__)
self._create_db()
# set up watchdog observer to monitor changes to
# keyword files (or more correctly, to directories
# of keyword files)
self.observer = PollingObserver() if poll else Observer()
self.observer.start()
def _create_db(self):
if not self._table_exists("collection_table"):
self.db.execute("""
CREATE TABLE collection_table
(collection_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT COLLATE NOCASE,
type COLLATE NOCASE,
version TEXT,
scope TEXT,
namedargs TEXT,
path TEXT,
doc TEXT,
doc_format TEXT)
""")
self.db.execute("""
CREATE INDEX collection_index
ON collection_table (name)
""")
if not self._table_exists("keyword_table"):
self.db.execute("""
CREATE TABLE keyword_table
(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT COLLATE NOCASE,
collection_id INTEGER,
doc TEXT,
args TEXT)
""")
self.db.execute("""
CREATE INDEX keyword_index
ON keyword_table (name)
""")
def _table_exists(self, name):
cursor = self.db.execute("""
SELECT name FROM sqlite_master
WHERE type='table' AND name='%s'
""" % name)
return len(cursor.fetchall()) > 0
示例11: get_static_assets_observer
def get_static_assets_observer(project_dir):
build_path = utils.get_build_dir(project_dir)
observer = PollingObserver()
contracts_js_event_handler = ContractsJSChangedEventHandler(project_dir=project_dir)
observer.schedule(contracts_js_event_handler, build_path, recursive=False)
if project_has_assets(project_dir):
assets_watch_path = get_static_assets_dir(project_dir)
assets_event_handler = AssetsChangedEventHandler(project_dir=project_dir)
observer.schedule(assets_event_handler, assets_watch_path, recursive=True)
return observer
示例12: get_contracts_observer
def get_contracts_observer(project_dir, contract_filters=None, compiler_kwargs=None):
if contract_filters is None:
contract_filters = []
if compiler_kwargs is None:
compiler_kwargs = {}
contracts_dir = utils.get_contracts_dir(project_dir)
libraries_dir = get_project_libraries_dir(project_dir)
event_handler = ContractSourceChangedEventHandler(
project_dir=project_dir, contract_filters=contract_filters, compiler_kwargs=compiler_kwargs
)
observer = PollingObserver()
observer.schedule(event_handler, contracts_dir, recursive=True)
observer.schedule(event_handler, libraries_dir, recursive=True)
return observer
示例13: watch
def watch(self):
observer = PollingObserver()
observer.schedule(self.pickup_event_processor, path=self.pickup_dir)
observer.start()
try:
while self.keep_running:
sleep(3)
except KeyboardInterrupt:
observer.stop()
observer.join()
示例14: main
def main():
"""Script entry point."""
from watchdog.observers.polling import PollingObserver
from .parser import AAConfigParser
from .tricks import AutoRunTrick
parser = _create_main_argparser()
args = parser.parse_args()
configm = _apply_main_args(args)
# The reason to use PollingObserver() is it's os-independent. And it's
# more reliable.
observer = PollingObserver()
parser = AAConfigParser(configm)
handler_for_watch = parser.schedule_with(observer, AutoRunTrick)
handlers = set.union(*tuple(handler_for_watch.values()))
for handler in handlers:
handler.start()
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
for handler in handlers:
handler.stop()
示例15: watch_assets
def watch_assets(options):
"""
Watch for changes to asset files, and regenerate js/css
"""
# Don't watch assets when performing a dry run
if tasks.environment.dry_run:
return
observer = PollingObserver()
CoffeeScriptWatcher().register(observer)
SassWatcher().register(observer)
XModuleSassWatcher().register(observer)
XModuleAssetsWatcher().register(observer)
print("Starting asset watcher...")
observer.start()
if not getattr(options, 'background', False):
# when running as a separate process, the main thread needs to loop
# in order to allow for shutdown by contrl-c
try:
while True:
observer.join(2)
except KeyboardInterrupt:
observer.stop()
print("\nStopped asset watcher.")