diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-08-15 18:34:54 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-08-15 18:34:54 (GMT) |
commit | 365bbb54657d0b554794d185420c7ad21562bb9b (patch) | |
tree | 2da9e9cd65a8d7378e422af7433b0cae213aa2d6 | |
parent | a8e26a94023c27f6a25efa06cff2be363ccc71bf (diff) |
Add an auto-install command
-rw-r--r-- | README | 16 | ||||
-rwxr-xr-x | scripts/shell/auto-install | 44 |
2 files changed, 58 insertions, 2 deletions
@@ -65,8 +65,20 @@ make test Run UI tests == Shell commands reference == -start-sugar Start sugar. -send-patches Send local commits as patches for review. +* start-sugar + +Start sugar. + +* send-patches + +Send local commits as patches for review. + +* auto-install + +Automatically install python files when they are modified. Run it +inside a module directory, make changes to the code and have them +applied without needing to run make install (you still need to +restart sugar). Use --help for more informations about each command. diff --git a/scripts/shell/auto-install b/scripts/shell/auto-install new file mode 100755 index 0000000..327d46d --- /dev/null +++ b/scripts/shell/auto-install @@ -0,0 +1,44 @@ +#!/usr/bin/python + +from distutils.sysconfig import parse_makefile +import os +import shutil + +from gi.repository import Gio +from gi.repository import GLib + +shell_dir = os.path.abspath(os.path.dirname(__file__)) +scripts_dir = os.path.dirname(shell_dir) +root_dir = os.path.dirname(scripts_dir) +source_dir = os.path.join(root_dir, "source") +build_dir = os.path.join(root_dir, "build") + +monitors = [] + +def install(file): + 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): + if event_flags == Gio.FileMonitorEvent.CHANGED: + if file.get_path().endswith(".py"): + install(file) + +for root, dirs, files in os.walk(os.getcwd()): + 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) + + monitors.append(monitor) + +main_loop = GLib.MainLoop() +main_loop.run() |