blob: 0133cb67f755952034a3937f8650c78e4f254d31 [file] [log] [blame]
#!/usr/bin/python
import os
class rsync:
command = '/usr/bin/rsync -rltvz'
def __init__(self, prefix, target, excludes = []):
if not os.path.isdir(target):
os.makedirs(target)
self.prefix = prefix
self.target = target
# Have to use a tmpfile rather than a pipe, else we could
# trigger from a file that's still only partially mirrored
self.tmpfile = '/tmp/mirror.%d' % os.getpid()
if os.path.exists(self.tmpfile):
os.remove(self.tmpfile)
self.exclude = ' '.join(['--exclude ' + x for x in excludes])
def __del__(self):
os.remove(self.tmpfile)
def sync(self, src, dest):
os.chdir(self.target)
if not os.path.isdir(dest):
os.makedirs(dest)
src = os.path.join(self.prefix, src)
cmd = self.command + ' %s "%s" "%s"' % (self.exclude, src, dest)
# print cmd + ' >> %s 2>&1' % self.tmpfile
if os.system(cmd + ' >> %s 2>&1' % self.tmpfile):
raise 'rsync command failed'