diff options
-rwxr-xr-x | commands/clean | 6 | ||||
-rw-r--r-- | devbot/build.py | 41 | ||||
-rw-r--r-- | devbot/config.py | 6 | ||||
-rw-r--r-- | devbot/environ.py | 14 | ||||
-rw-r--r-- | devbot/state.py | 47 |
5 files changed, 76 insertions, 38 deletions
diff --git a/commands/clean b/commands/clean index 5fdee2f..fcfe193 100755 --- a/commands/clean +++ b/commands/clean @@ -7,9 +7,15 @@ import common from devbot import build from devbot import config +from devbot import environ +from devbot import state +from devbot import config common.setup() build.clean() +environ.clean() +state.clean() +config.clean() os.chdir(config.logs_dir) diff --git a/devbot/build.py b/devbot/build.py index f117667..74ff7bf 100644 --- a/devbot/build.py +++ b/devbot/build.py @@ -1,8 +1,4 @@ -#!/usr/bin/python -u - -from distutils import sysconfig import fnmatch -import json import os import multiprocessing import shutil @@ -12,31 +8,7 @@ import subprocess from devbot import command from devbot import config from devbot import environ - -state = { "built_modules": {} } - -def get_state_path(): - return os.path.join(config.home_dir, "state.json") - -def load_state(): - global state - - state_path = get_state_path() - if os.path.exists(state_path): - state = json.load(open(state_path)) - -def save_state(): - json.dump(state, open(get_state_path(), "w+")) - -def add_path(name, path): - if name not in os.environ: - os.environ[name] = path - return - - splitted = os.environ[name].split(":") - splitted.append(path) - - os.environ[name] = ":".join(splitted) +from devbot import state def get_module_commit_id(module): orig_cwd = os.getcwd() @@ -118,15 +90,13 @@ def build_module(module): print "Unknown build system" sys.exit(1) - state["built_modules"][module.name] = get_module_commit_id(module) - save_state() + state.add_built_module(module.name, get_module_commit_id(module)) def clear_built_modules(modules, index): if index < len(modules) - 1: for module in modules[index + 1:]: - name = module.name - if name in state["built_modules"]: - del state["built_modules"][name] + if state.get_built_module(module.name) is not None: + state.remove_built_module(module.name) def rmtree(dir): print "Deleting %s" % dir @@ -134,7 +104,6 @@ def rmtree(dir): def build(): environ.setup() - load_state() modules = config.load_modules() @@ -144,7 +113,7 @@ def build(): try: pull_source(module) - old_commit_id = state["built_modules"].get(module.name, None) + old_commit_id = state.get_built_module(module.name) new_commit_id = get_module_commit_id(module) if old_commit_id is None or old_commit_id != new_commit_id: diff --git a/devbot/config.py b/devbot/config.py index 437bfe7..63140e8 100644 --- a/devbot/config.py +++ b/devbot/config.py @@ -201,3 +201,9 @@ def load_modules(): modules.append(Module(info)) return modules + +def clean(): + try: + os.rmdir(home_dir) + except OSError: + pass diff --git a/devbot/environ.py b/devbot/environ.py index c8b6343..ccdfd3f 100644 --- a/devbot/environ.py +++ b/devbot/environ.py @@ -17,10 +17,14 @@ def _add_path(name, path): os.environ[name] = ":".join(splitted) +def _get_gst_registry_path(): + return os.path.join(config.home_dir, "gstreamer.registry") + def _setup_variables(): _add_path("LD_LIBRARY_PATH", config.lib_dir) _add_path("PATH", config.bin_dir) _add_path("PATH", config.commands_dir) + _add_path("GST_REGISTRY", _get_gst_registry_path()) _add_path("XCURSOR_PATH", os.path.join(config.share_dir, "icons")) @@ -34,8 +38,6 @@ def _setup_variables(): os.path.join(config.lib_dir, "pkgconfig")) _add_path("GST_PLUGIN_PATH", os.path.join(config.lib_dir , "gstreamer-1.0")) - _add_path("GST_REGISTRY", - os.path.join(config.home_dir, "gstreamer.registry")) _add_path("PYTHONPATH", sysconfig.get_python_lib(prefix=config.prefix_dir)) _add_path("PYTHONPATH", @@ -75,3 +77,11 @@ def _setup_gconf(): os.environ["GCONF_SCHEMA_INSTALL_SOURCE"] = \ "xml:merged:" + os.path.join(gconf_dir, "gconf.xml.defaults") + +def clean(): + print "Deleting registry" + + try: + os.unlink(_get_gst_registry_path()) + except OSError: + pass diff --git a/devbot/state.py b/devbot/state.py new file mode 100644 index 0000000..bc17761 --- /dev/null +++ b/devbot/state.py @@ -0,0 +1,47 @@ +import os +import json + +from devbot import config + +_state = None + +def _get_state_path(): + return os.path.join(config.home_dir, "state.json") + +def _get_state(): + global _state + + if _state is not None: + return _state + + state_path = _get_state_path() + if os.path.exists(state_path): + _state = json.load(open(state_path)) + else: + _state = { "built_modules": {} } + + return _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 + _state_changed() + +def remove_built_module(name): + del _get_state()["built_modules"][name] + _state_changed() + +def get_built_module(name): + return _get_state()["built_modules"].get(name, None) + +def clean(): + _state = None + + print "Deleting state" + + try: + os.unlink(_get_state_path()) + except OSError: + pass |