From 9c6636a761d2bc627e744e6b0efc45cc7672c485 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Mon, 26 Nov 2012 00:22:01 +0000 Subject: On run check the system only if something changed --- (limited to 'devbot') diff --git a/devbot/build.py b/devbot/build.py index 74ff7bf..6705274 100644 --- a/devbot/build.py +++ b/devbot/build.py @@ -10,16 +10,6 @@ from devbot import config from devbot import environ from devbot import state -def get_module_commit_id(module): - orig_cwd = os.getcwd() - os.chdir(module.get_source_dir()) - - commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"]) - - os.chdir(orig_cwd) - - return commit_id.strip() - def unlink_libtool_files(): def func(arg, dirname, fnames): for fname in fnmatch.filter(fnames, "*.la"): @@ -90,13 +80,13 @@ def build_module(module): print "Unknown build system" sys.exit(1) - state.add_built_module(module.name, get_module_commit_id(module)) + state.touch_built_commit_id(module) def clear_built_modules(modules, index): if index < len(modules) - 1: for module in modules[index + 1:]: - if state.get_built_module(module.name) is not None: - state.remove_built_module(module.name) + if state.get_built_commit_id(module) is not None: + state.remove_built_commit_id(module) def rmtree(dir): print "Deleting %s" % dir @@ -113,8 +103,8 @@ def build(): try: pull_source(module) - old_commit_id = state.get_built_module(module.name) - new_commit_id = get_module_commit_id(module) + old_commit_id = state.get_built_commit_id(module) + new_commit_id = module.get_commit_id() if old_commit_id is None or old_commit_id != new_commit_id: clear_built_modules(modules, i) diff --git a/devbot/config.py b/devbot/config.py index df037d6..123958a 100644 --- a/devbot/config.py +++ b/devbot/config.py @@ -3,6 +3,7 @@ import os import tempfile from devbot import distro +from devbot import utils config_dir = None logs_dir = None @@ -41,10 +42,20 @@ class Module: def get_build_dir(self): return os.path.join(get_build_dir(), self.name) + def get_commit_id(self): + return utils.get_commit_id(get_source_dir()) + def _ensure_dir(dir): if not os.path.exists(dir): os.mkdir(dir) +def get_commit_id(): + commit_id = utils.get_commit_id(config_dir) + if commit_id is None: + commit_id = "snapshot" + + return commit_id + def set_config_dir(dir): global config_dir config_dir = dir diff --git a/devbot/state.py b/devbot/state.py index bc17761..1eaf3ac 100644 --- a/devbot/state.py +++ b/devbot/state.py @@ -25,16 +25,23 @@ def _get_state(): def _state_changed(): json.dump(_state, open(_get_state_path(), "w+")) -def add_built_module(name, commit_id): - _get_state()["built_modules"][name] = commit_id +def touch_built_commit_id(module): + _get_state()["built_modules"][module.name] = module.get_commit_id() _state_changed() -def remove_built_module(name): - del _get_state()["built_modules"][name] +def remove_built_commit_id(module): + del _get_state()["built_modules"][module.name] _state_changed() -def get_built_module(name): - return _get_state()["built_modules"].get(name, None) +def get_built_commit_id(module): + return _get_state()["built_modules"].get(module.name, None) + +def get_last_system_check(): + return _get_state().get("last_system_check", None) + +def touch_last_system_check(): + _get_state()["last_system_check"] = config.get_commit_id() + _state_changed() def clean(): _state = None diff --git a/devbot/system.py b/devbot/system.py index 2a8d189..57e223c 100644 --- a/devbot/system.py +++ b/devbot/system.py @@ -6,8 +6,9 @@ import sys from devbot import config from devbot import distro from devbot import command +from devbot import state +from devbot import utils -devnull = open("/dev/null", "w") xvfb_display = ":100" libdirs = ["lib", @@ -17,7 +18,7 @@ libdirs = ["lib", def check_binary(check): return subprocess.call(["which", check], - stdout=devnull, + stdout=utils.devnull, stderr=subprocess.STDOUT) def check_pkgconfig(check): @@ -25,7 +26,8 @@ def check_pkgconfig(check): def check_python(check): return subprocess.call(["python", "-c", check], - stdout=devnull, stderr=subprocess.STDOUT) == 1 + stdout=utils.devnull, + stderr=subprocess.STDOUT) == 1 def check_gtkmodule(check): # Not sure we can do better than this, the gtkmodule stuff is private @@ -109,7 +111,7 @@ def run_checks(package_manager, checks, packages): def start_xvfb(): xvfb_proc = subprocess.Popen(args=["Xvfb", xvfb_display], - stdout=devnull, + stdout=utils.devnull, stderr=subprocess.STDOUT) orig_display = os.environ.get("DISPLAY", None) os.environ["DISPLAY"] = xvfb_display @@ -163,7 +165,12 @@ def remove_packages(package_manager, packages): if to_remove: package_manager.remove_packages(to_remove) -def check(remove=False, update=False, test=False, interactive=True): +def check(remove=False, update=False, test=False, interactive=True, + skip_if_unchanged=False): + if skip_if_unchanged: + if config.get_commit_id() == state.get_last_system_check(): + return + print "Checking the system" package_manager = \ @@ -188,4 +195,6 @@ def check(remove=False, update=False, test=False, interactive=True): package_manager.update() if remove: - remove_packages(package_manager, packages) + remove_packages(package_manager, packages) + + state.touch_last_system_check() diff --git a/devbot/utils.py b/devbot/utils.py new file mode 100644 index 0000000..2864948 --- /dev/null +++ b/devbot/utils.py @@ -0,0 +1,18 @@ +import os +import subprocess + +devnull = open("/dev/null", "w") + +def get_commit_id(dir): + orig_cwd = os.getcwd() + os.chdir(dir) + + try: + commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"], + stderr=devnull).strip() + except subprocess.CalledProcessError: + commit_id = None + + os.chdir(orig_cwd) + + return commit_id -- cgit v0.9.1