本文整理汇总了Python中watchdog.observers.Observer方法的典型用法代码示例。如果您正苦于以下问题:Python observers.Observer方法的具体用法?Python observers.Observer怎么用?Python observers.Observer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类watchdog.observers
的用法示例。
在下文中一共展示了observers.Observer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def __init__(self):
if Observer is not None and not judgeenv.no_watchdog:
if judgeenv.env.update_pings:
logger.info('Using thread to ping urls: %r', judgeenv.env.update_pings)
self._refresher = RefreshWorker(judgeenv.env.update_pings)
else:
self._refresher = None
self._handler = SendProblemsHandler(self._refresher)
self._monitor = Observer()
for dir in get_problem_watches():
self._monitor.schedule(self._handler, dir, recursive=True)
logger.info('Scheduled for monitoring: %s', dir)
else:
self._monitor = None
self._refresher = None
示例2: watch
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watch():
is_proj, root = get_project_root()
state = {"dirty": False}
if not is_proj:
click.echo("Run psync to generate .psync config file.")
else:
click.echo("Start watching {} ...".format(root))
event_handler = watcher.AnyEventHandler(state)
observer = Observer()
observer.schedule(event_handler, root, recursive=True)
observer.start()
try:
while True:
if state["dirty"]:
click.echo("Detect modification. Perform sync.")
perform_sync()
state["dirty"] = False
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
示例3: main
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def main(watch):
# Regenerate at least once.
regenerate()
if watch:
observer = Observer()
# Observe both the template directory and cookiecutter.json.
observer.schedule(RegenerateSugardoughHandler(), TEMPLATEDIR, recursive=True)
cookiecutter_json_handler = RegenerateSugardoughHandler(patterns=[
os.path.join(BASEDIR, 'cookiecutter.json')
])
observer.schedule(cookiecutter_json_handler, BASEDIR)
print('Watching for changes...')
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
示例4: start
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def start(cls, config):
"""
The starter method for watching files.
If invoked, it will start watching all files and see if documentation is needed
Parameters
----------
ConfigParser config: Config going to be used in DYC
"""
logging.basicConfig(level=logging.INFO)
observer = Observer()
event_handler = WatchEvent()
event_handler.config = config
observer.schedule(event_handler, '.', recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
print('Quitting..')
observer.join()
示例5: watchdir
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watchdir():
try:
global watchdog_handler
logger.debug('Initializing watchdog')
observer = Observer()
observer.schedule(watchdog_handler, path=cfg.watchdir_location, recursive=True)
observer.start()
logger.debug('Initializing watchdog complete')
if cfg.watchdir_walk_enabled:
scheduler.scheduler.add_job(walk_watchdir, 'interval', id='walk_watchdir', seconds=active_interval,
replace_existing=True, max_instances=1, coalesce=True)
else:
walk_watchdir()
except:
raise
# Flask
示例6: _bind_observers
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def _bind_observers(self):
"""Start the observers.
"""
for contrib in ('users', 'starters', 'connections', 'settings'):
callback = partial(self._update_contribs, contrib)
getattr(self, '_'+contrib).observe('contributions', callback)
def update():
"""Run the handler on the main thread to avoid GUI issues.
"""
deferred_call(self._refresh_profiles)
self._observer = Observer()
for folder in self._profiles_folders:
handler = SystematicFileUpdater(update)
self._observer.schedule(handler, folder, recursive=True)
self._observer.start()
示例7: wait_on_entry_calc
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def wait_on_entry_calc(self, key):
with self.lock:
self._reload_cache()
entry = self._get_cache()[key]
if not entry['being_calculated']:
return entry['value']
event_handler = _PickleCore.CacheChangeHandler(
filename=self._cache_fname(), core=self, key=key
)
observer = Observer()
event_handler.inject_observer(observer)
observer.schedule(
event_handler, path=self.expended_cache_dir, recursive=True
)
observer.start()
observer.join(timeout=1.0)
if observer.is_alive():
# print('Timedout waiting. Starting again...')
return self.wait_on_entry_calc(key)
# print("Returned value: {}".format(event_handler.value))
return event_handler.value
示例8: shell_command
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def shell_command(args):
"""
Subcommand to execute shell commands in response to file system events.
:param args:
Command line argument options.
"""
from watchdog.observers import Observer
from watchdog.tricks import ShellCommandTrick
if not args.command:
args.command = None
patterns, ignore_patterns = parse_patterns(args.patterns,
args.ignore_patterns)
handler = ShellCommandTrick(shell_command=args.command,
patterns=patterns,
ignore_patterns=ignore_patterns,
ignore_directories=args.ignore_directories,
wait_for_process=args.wait_for_process,
drop_during_process=args.drop_during_process)
observer = Observer(timeout=args.timeout)
observe_with(observer, handler, args.directories, args.recursive)
示例9: _watch
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def _watch(root='.', dest='_site', pattern='**/*.html', exclude='_*/**'):
try:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
except ImportError:
msg = "The build --watch feature requires watchdog. \n"\
+ "Please install it with 'easy_install watchdog'."
print(msg)
return None
class handler(FileSystemEventHandler):
def on_any_event(self, event):
exclude_path = os.path.join(os.getcwd(), exclude)
if not utils.matches_pattern(exclude_path, event.src_path):
build_files(root=root,
dest=dest,
pattern=pattern,
exclude=exclude)
observer = Observer()
observer.schedule(handler(), root, recursive=True)
observer.start()
print("Watching '{0}' ...".format(root))
return observer
示例10: watch
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watch():
from serapis import tasks
global tasks_map
tasks_map = {
"search": tasks.search,
"detect": tasks.detect,
"save": tasks.save
}
observer = Observer()
observer.schedule(TaskHandler(), config.local_s3, recursive=False)
observer.start()
print("Watching local bucket in '{}'...".format(config.local_s3))
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
示例11: main
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def main():
opts = docopt(__doc__, version=__version__)
environment = Environment.load(opts['ENVIRONMENT'] or '.')
env_path = environment.target
less_paths = [
path_join(env_path, 'ckan', 'ckan', 'public', 'base', 'less'),
path_join(env_path, 'ckan', 'ckan', 'public', 'base', 'vendor')
]
if not env_path or not all(exists(less_path) for less_path in less_paths):
print 'No source code to watch found'
return
observer = Observer()
event_handler = LessCompileEventHandler(environment)
for less_path in less_paths:
observer.schedule(event_handler, less_path, recursive=True)
observer.start()
# HACK: We make it so that the OS doesn't consult us and just kills us.
signal.signal(signal.SIGINT, signal.SIG_DFL)
observer.join()
示例12: watch_assets
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def watch_assets(options):
"""
Watch for changes to asset files, and regenerate js/css
"""
observer = Observer()
CoffeeScriptWatcher().register(observer)
SassWatcher().register(observer)
XModuleSassWatcher().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.")
示例13: run
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def run(self, args):
self.record_pid()
# workaround the issue that SIGINT cannot be received (fork a child to
# avoid blocking the main process in Thread.join()
child_pid = os.fork()
if child_pid == 0: # child
# observer handles event in a different thread
observer = Observer()
observer.schedule(self.event_handler, path=args['image_dir'])
observer.start()
self.server()
else: # parent
try:
os.wait()
except KeyboardInterrupt:
os.kill(child_pid, signal.SIGKILL)
self.erase_pid()
示例14: __init__
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def __init__(self, runner):
self.runner = runner
self.event_handler = PatternMatchingEventHandler(patterns=["*.fast5"],
ignore_patterns=[],
ignore_directories=True)
self.event_handler.on_created = self.on_created
self.event_handler.on_moved = self.on_moved
self.observer = Observer()
self.observedPaths = []
for path in self.runner.input:
if os.path.isdir(path):
self.observer.schedule(self.event_handler, path, recursive=True)
self.observedPaths.append(path)
log("Monitoring {} in real time. Press Ctrl+C to exit.".format(", ".join(self.observedPaths)))
示例15: Start
# 需要导入模块: from watchdog import observers [as 别名]
# 或者: from watchdog.observers import Observer [as 别名]
def Start(self):
self.Scan(continuous=True)
self.status.SetLabel("Real-time scanning is running now.")
if self.observer:
return
gisenv = gscript.gisenv()
mapsetPath = os.path.join(gisenv['GISDBASE'], gisenv['LOCATION_NAME'], gisenv['MAPSET'])
path1 = os.path.join(mapsetPath, 'fcell')
if not os.path.exists(path1):
os.mkdir(os.path.join(mapsetPath, 'fcell'))
path2 = os.path.join(mapsetPath, 'vector')
if not os.path.exists(path2):
os.mkdir(os.path.join(mapsetPath, 'vector'))
paths = [path1, path2]
handlers = [RasterChangeHandler(self.runImport, self.settings['tangible']['output']),
DrawingChangeHandler(self.runImportDrawing, self.settings['tangible']['drawing']['name'])]
self.observer = Observer()
for path, handler in zip(paths, handlers):
self.observer.schedule(handler, path)
self.observer.start()
self.timer.Start(1000)