diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-11-16 15:17:10 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-11-16 15:17:10 (GMT) |
commit | 2cac32f92d73eb68d261dc01c0d34314401cf79f (patch) | |
tree | a60f963a8a56f9babe6f8b5b2c86e2a218d80a44 /devbot/autoinstall.py | |
parent | 267e9d4de8b5330025aaad788d676a09e17f49f4 (diff) |
Rework the autoinstall command
It now automatically listen on all the sugar trees
Diffstat (limited to 'devbot/autoinstall.py')
-rwxr-xr-x | devbot/autoinstall.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/devbot/autoinstall.py b/devbot/autoinstall.py new file mode 100755 index 0000000..ed94b1e --- /dev/null +++ b/devbot/autoinstall.py @@ -0,0 +1,52 @@ +#!/usr/bin/python + +from distutils.sysconfig import parse_makefile +import os +import shutil + +import common + +from gi.repository import Gio +from gi.repository import GLib + +from devbot import config + +monitors = [] + +def install(module, file): + print "Installing %s" % file.get_path() + + source_dir = config.get_module_source_dir(module) + build_dir = config.get_module_build_dir(module) + + dir = os.path.dirname(file.get_path()) + relative_path = os.path.relpath(dir, source_dir) + makefile_path = os.path.join(build_dir, relative_path, "Makefile") + makefile = parse_makefile(makefile_path) + + for variable in makefile: + if variable.endswith("_PYTHON"): + dir_variable = "%sdir" % variable.replace("_PYTHON", "") + install_dir = makefile[dir_variable] + shutil.copy(file.get_path(), install_dir) + +def changed_cb(monitor, file, other_file, event_flags, module): + if event_flags == Gio.FileMonitorEvent.CHANGED: + if file.get_path().endswith(".py"): + install(module, file) + +def observe(): + for module in config.load_modules(): + if module.get("autoinstall", False): + source_dir = config.get_module_source_dir(module) + for root, dirs, files in os.walk(source_dir): + for dir in dirs: + file = Gio.File.new_for_path(os.path.join(root, dir)) + monitor = file.monitor(Gio.FileMonitorFlags.NONE, None) + monitor.connect("changed", changed_cb, module) + + monitors.append(monitor) + + + main_loop = GLib.MainLoop() + main_loop.run() |