Skip to content

Commit

Permalink
Merge pull request gregghz#13 from Brunus-V/master
Browse files Browse the repository at this point in the history
Bug fixes and feature add : Event date and time in jobs commands
  • Loading branch information
gregghz committed Sep 13, 2013
2 parents b51beb1 + 5f803b9 commit 6b6f74d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ job1:
# directories.
# $src_path is only used in move_to and is the corresponding path from move_from
# $src_rel_path [needs doc]
# $datetime output date and time of the event, format is : Y-m-d H:M:S
# command: cp -r $filename /home/user/Documents/$dest_file # $src_path
command: echo $filename # $src_path
command: echo $datetime $filename $tflags # $src_path
8 changes: 5 additions & 3 deletions watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def runCommand(self, event, ignore_cookie=True):
'tflags': event.maskname,
'nflags': event.mask,
'src_path': src_path,
'src_rel_path': src_rel_path
'src_rel_path': src_rel_path,
'datetime': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
})

#try the command
Expand All @@ -214,11 +215,13 @@ def runCommand(self, event, ignore_cookie=True):

#handle recursive watching of directories
if self.recursive and os.path.isdir(event.pathname):

prefix = event.name
if self.prefix != "":
prefix = self.prefix + '/' + prefix
self.parent.addWatch(self.mask,
event.pathname,
self.exclude,
True,
self.command,
prefix)
Expand Down Expand Up @@ -300,7 +303,7 @@ def run(self):

def addWatch(self, mask, folder, exclude, recursive, command, prefix=""):
wm = pyinotify.WatchManager()
handler = EventHandler(command, recursive, mask, self, prefix, folder, exclude)
handler = EventHandler(command, recursive, exclude, mask, self, prefix, folder)

# adding exclusion list
excl_lst = exclude
Expand All @@ -312,7 +315,6 @@ def addWatch(self, mask, folder, exclude, recursive, command, prefix=""):
# this means that each job has its own thread as well (I think)
n = pyinotify.ThreadedNotifier(wm, handler)
self.notifiers.append(pyinotify.ThreadedNotifier(wm, handler))

n.start()

def _loadWatcherDirectory(self):
Expand Down

0 comments on commit 6b6f74d

Please sign in to comment.