diff options
author | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-11-25 23:04:31 (GMT) |
---|---|---|
committer | Daniel Narvaez <dwnarvaez@gmail.com> | 2012-11-25 23:04:31 (GMT) |
commit | 91ea798d316865135643a569799f96f98de68ef8 (patch) | |
tree | 0c22e6dee60cc9c72d7e35c3c153640f3f78c2eb /devbot/state.py | |
parent | a0b65ee79f9f5abdee931aa02a3018cb308f6c51 (diff) |
Split state out of build script so we can reuse it
Diffstat (limited to 'devbot/state.py')
-rw-r--r-- | devbot/state.py | 47 |
1 files changed, 47 insertions, 0 deletions
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 |