Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/devbot
diff options
context:
space:
mode:
authorDaniel Narvaez <dwnarvaez@gmail.com>2012-12-25 01:07:06 (GMT)
committer Daniel Narvaez <dwnarvaez@gmail.com>2012-12-25 01:07:06 (GMT)
commit5a97aac1de8b120747fc79b20dfbe4db81116515 (patch)
tree3f1a5ae6572b14bc8aea3055b40b86d0921a8973 /devbot
parentaf22628659337690ff19a7ff8458eeef5ffc6e7e (diff)
Separate build and check states
Diffstat (limited to 'devbot')
-rw-r--r--devbot/state.py63
1 files changed, 36 insertions, 27 deletions
diff --git a/devbot/state.py b/devbot/state.py
index 258c594..649b115 100644
--- a/devbot/state.py
+++ b/devbot/state.py
@@ -3,48 +3,56 @@ import json
from devbot import config
-_state = None
+_BUILT_MODULES = "builtmodules"
+_SYSTEM_CHECK = "syscheck"
-def _get_state_path():
- return os.path.join(config.build_state_dir, "state.json")
+def _get_state_path(name):
+ return os.path.join(config.build_state_dir, "%s.json" % name)
-def _get_state():
- global _state
+def _load_state(name, default=None):
+ state = default
- 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": {} }
+ try:
+ with open(_get_state_path(name)) as f:
+ state = json.load(f)
+ except IOError:
+ pass
- return _state
+ return state
-def _state_changed():
- json.dump(_state, open(_get_state_path(), "w+"))
+def _save_state(name, state):
+ with open(_get_state_path(name), "w+") as f:
+ json.dump(state, f, indent=4)
+ f.write('\n')
def touch_built_commit_id(module):
- _get_state()["built_modules"][module.name] = module.get_commit_id()
- _state_changed()
+ built_modules = _load_state(_BUILT_MODULES, {})
+
+ built_modules[module.name] = module.get_commit_id()
+
+ _save_state(_BUILT_MODULES, built_modules)
def remove_built_commit_id(module):
- state = _get_state()
+ built_modules = _load_state(_BUILT_MODULES)
- if module.name in state["built_modules"]:
- del state["built_modules"][module.name]
- _state_changed()
+ if built_modules and module.name in built_modules:
+ del built_modules[module.name]
+ _save_state(_BUILT_MODULES, built_modules)
def get_built_commit_id(module):
- return _get_state()["built_modules"].get(module.name, None)
+ built_modules = _load_state(_BUILT_MODULES, {})
+ return built_modules.get(module.name, None)
def get_last_system_check():
- return _get_state().get("last_system_check", None)
+ system_check = _load_state(_SYSTEM_CHECK, {})
+ return system_check.get("commit", None)
def touch_last_system_check():
- _get_state()["last_system_check"] = config.get_commit_id()
- _state_changed()
+ system_check = _load_state(_SYSTEM_CHECK, {})
+
+ system_check["commit"] = config.get_commit_id()
+
+ _save_state(_SYSTEM_CHECK, system_check)
def clean():
_state = None
@@ -52,6 +60,7 @@ def clean():
print "Deleting state"
try:
- os.unlink(_get_state_path())
+ for name in _BUILT_MODULES, _SYSTEM_CHECK:
+ os.unlink(_get_state_path(name))
except OSError:
pass