Commit e4fa54a6 authored by Benedikt Böhm's avatar Benedikt Böhm Committed by Carsten Leonhardt

Imported upstream version 0.2.3+git20120321

parent 4d00bbaa
......@@ -3,10 +3,10 @@ inosync
=======
:Author: `Benedikt Böhm <bb@xnull.de>`_
:Version: 0.2.1
:Web: http://bb.xnull.de/projects/inosync/
:Source: http://git.xnull.de/gitweb/?p=inosync.git (also on `github <http://github.com/hollow/inosync>`_)
:Download: http://bb.xnull.de/projects/inosync/dist/
:Version: 0.2.3
:Web: http://github.com/hollow/inosync
:Git: ``git clone https://github.com/hollow/inosync.git``
:Download: http://github.com/hollow/inosync/downloads
Rationale
=========
......@@ -65,6 +65,9 @@ except ``/var/www/localhost`` to 3 remote locations:
"c.mirror.com:" + rpath,
]
# extra, raw parameters to rsync
#extra = "--rsh=ssh -a"
# limit remote sync speed (in KB/s, 0 = no limit)
#rspeed = 0
......@@ -104,8 +107,8 @@ Requirements
To use this script you need the following software installed on your system:
- linux-2.6.13 or later
- Python-2.4 or later
- pyinotify-0.7.0 or later
- Python-2.5 or later
- pyinotify-0.8.7 or later
Related Software
......
......@@ -9,7 +9,7 @@ from pyinotify import *
__author__ = "Benedikt Böhm"
__copyright__ = "Copyright (c) 2007-2008 Benedikt Böhm <bb@xnull.de>"
__version__ = 0,2,1
__version__ = 0,2,3
OPTION_LIST = [
make_option(
......@@ -34,20 +34,6 @@ OPTION_LIST = [
help = "print debugging information"),
]
ALL_EVENTS = [
"IN_ACCESS",
"IN_ATTRIB",
"IN_CLOSE_WRITE",
"IN_CLOSE_NOWRITE",
"IN_CREATE",
"IN_DELETE",
"IN_DELETE_SELF",
"IN_MODIFY",
"IN_MOVED_FROM",
"IN_MOVED_TO",
"IN_OPEN"
]
DEFAULT_EVENTS = [
"IN_CLOSE_WRITE",
"IN_CREATE",
......@@ -58,21 +44,20 @@ DEFAULT_EVENTS = [
class RsyncEvent(ProcessEvent):
pretend = None
dirty = True
def __init__(self, pretend=False):
self.pretend = pretend
def sync(self):
if not self.dirty:
return
args = [config.rsync, "-ltrp", "--delete"]
if config.extra:
args.append(config.extra)
args.append("--bwlimit=%s" % config.rspeed)
if config.logfile:
args.append("--log-file=%s" % config.logfile)
if "excludes" in dir(config):
for exclude in config.excludes:
args.append("--exclude=%s" % exclude)
if "rexcludes" in dir(config):
for rexclude in config.rexcludes:
args.append("--exclude=%s" % rexclude)
args.append(config.wpath)
args.append("%s")
cmd = " ".join(args)
......@@ -84,16 +69,11 @@ class RsyncEvent(ProcessEvent):
proc = os.popen(cmd % node)
for line in proc:
syslog(LOG_DEBUG, "[rsync] %s" % line.strip())
self.dirty = False
def process_default(self, event):
syslog(LOG_DEBUG, "caught %s on %s" % \
(event.event_name, os.path.join(event.path, event.name)))
if not event.event_name in config.emask:
syslog(LOG_DEBUG, "ignoring %s on %s" % \
(event.event_name, os.path.join(event.path, event.name)))
return
self.dirty = True
(event.maskname, os.path.join(event.path, event.name)))
self.sync()
def daemonize():
try:
......@@ -154,17 +134,19 @@ def load_config(filename):
if not "emask" in dir(config):
config.emask = DEFAULT_EVENTS
for event in config.emask:
if not event in ALL_EVENTS:
if not event in EventsCodes.ALL_FLAGS.keys():
raise RuntimeError, "invalid inotify event: %s" % event
if not "edelay" in dir(config):
config.edelay = 10
if config.edelay < 1:
raise RuntimeError, "event delay needs to be greater than 1"
if config.edelay < 0:
raise RuntimeError, "event delay needs to be greater or equal to 0"
if not "logfile" in dir(config):
config.logfile = None
if not "extra" in dir(config):
config.extra = ""
if not "rsync" in dir(config):
config.rsync = "/usr/bin/rsync"
if not os.path.isabs(config.rsync):
......@@ -196,26 +178,16 @@ def main():
wm = WatchManager()
ev = RsyncEvent(options.pretend)
notifier = Notifier(wm, ev)
wds = wm.add_watch(config.wpath, EventsCodes.ALL_EVENTS,
rec = True, auto_add = True)
notifier = AsyncNotifier(wm, ev, read_freq=config.edelay)
mask = reduce(lambda x,y: x|y, [EventsCodes.ALL_FLAGS[e] for e in config.emask])
wds = wm.add_watch(config.wpath, mask, rec=True, auto_add=True)
syslog(LOG_DEBUG, "starting initial synchronization on %s" % config.wpath)
ev.sync()
syslog(LOG_DEBUG, "initial synchronization on %s done" % config.wpath)
syslog("resuming normal operations on %s" % config.wpath)
while True:
try:
notifier.process_events()
if notifier.check_events(0):
notifier.read_events()
ev.sync()
sleep(config.edelay)
except KeyboardInterrupt:
notifier.stop()
break
asyncore.loop()
sys.exit(0)
if __name__ == "__main__":
......
......@@ -16,6 +16,9 @@ rnodes = [
"c.mirror.com:" + rpath,
]
# extra, raw parameters to rsync
#extra = "--rsh=ssh -a"
# limit remote sync speed (in KB/s, 0 = no limit)
#rspeed = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment