blob: 9bca7d24f48ed2095613a8a8c1982dbd0fc1da08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
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 touch_built_commit_id(module):
_get_state()["built_modules"][module.name] = module.get_commit_id()
_state_changed()
def remove_built_commit_id(module):
state = _get_state()
if module.name in state["built_modules"]:
del state["built_modules"][module.name]
_state_changed()
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
print "Deleting state"
try:
os.unlink(_get_state_path())
except OSError:
pass
|