Skip to content

Commit

Permalink
Create pull request for adding --no-parallel as coded by @BernieSumption
Browse files Browse the repository at this point in the history
  • Loading branch information
cro committed Mar 28, 2014
1 parent 3a0f0ec commit 060e59a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/watchdog/tricks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,20 @@ class ShellCommandTrick(Trick):
"""Execeutes shell commands in response to matched events."""

def __init__(self, shell_command=None, patterns=None, ignore_patterns=None,
ignore_directories=False, wait_for_process=False):
ignore_directories=False, wait_for_process=False,
no_parallel_processes=False):
super(ShellCommandTrick, self).__init__(patterns, ignore_patterns,
ignore_directories)
self.shell_command = shell_command
self.wait_for_process = wait_for_process
self.no_parallel_processes = no_parallel_processes
self.process = None

def on_any_event(self, event):
from string import Template

if self.no_parallel_processes and self.process and self.process.poll() is None:
return

if event.is_directory:
object_type = 'directory'
Expand All @@ -111,9 +117,9 @@ def on_any_event(self, event):
command = self.shell_command

command = Template(command).safe_substitute(**context)
process = subprocess.Popen(command, shell=True)
self.process = subprocess.Popen(command, shell=True)
if self.wait_for_process:
process.wait()
self.process.wait()


class AutoRestartTrick(Trick):
Expand Down
8 changes: 7 additions & 1 deletion src/watchdog/watchmedo.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ def log(args):
action='store_true',
default=False,
help="wait for process to finish to avoid multiple simultaneous instances")
@arg('-n', '--no-parallel',
dest='no_parallel_processes',
action='store_true',
default=False,
help="Ignore events that happen while the previous process is still running")
def shell_command(args):
"""
Subcommand to execute shell commands in response to file system events.
Expand All @@ -435,7 +440,8 @@ def shell_command(args):
patterns=patterns,
ignore_patterns=ignore_patterns,
ignore_directories=args.ignore_directories,
wait_for_process=args.wait_for_process)
wait_for_process=args.wait_for_process,
no_parallel_processes=args.no_parallel_processes)
observer = Observer(timeout=args.timeout)
observe_with(observer, handler, args.directories, args.recursive)

Expand Down

0 comments on commit 060e59a

Please sign in to comment.