Skip to content

Commit

Permalink
Merge pull request #6 from vidiben/master
Browse files Browse the repository at this point in the history
dest_file for files located at the root of the watched directory
  • Loading branch information
gregghz committed Jan 28, 2013
2 parents e2d317a + 6d4e0c5 commit 6c7562e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,24 @@ def __init__(self, command, recursive, mask, parent, prefix, root):

def runCommand(self, event, ignore_cookie=True):
t = Template(self.command)

sub_regex = self.root

#build the dest_file
dfile = event.name
if self.prefix != "":
dfile = self.prefix + '/' + dfile
elif self.root != "":
dfile = re.sub('^'+re.escape(self.root+os.sep),'',event.path) + os.sep + dfile
if event.path != self.root:
sub_regex = self.root+os.sep
dfile = re.sub('^'+re.escape(sub_regex),'',event.path) + os.sep + dfile

#find the src_path if it exists
src_path = ''
src_rel_path = ''
if not ignore_cookie and hasattr(event, 'cookie') and event.cookie in self.move_map:
src_path = self.move_map[event.cookie]
if self.root != "":
src_rel_path = re.sub('^'+re.escape(sub_regex), '', src_path)
del self.move_map[event.cookie]

#run substitutions on the command
Expand All @@ -195,7 +201,8 @@ def runCommand(self, event, ignore_cookie=True):
'dest_file': dfile,
'tflags': event.maskname,
'nflags': event.mask,
'src_path': src_path
'src_path': src_path,
'src_rel_path': src_rel_path
})

#try the command
Expand Down

0 comments on commit 6c7562e

Please sign in to comment.