-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdater.lua
More file actions
92 lines (66 loc) · 1.39 KB
/
updater.lua
File metadata and controls
92 lines (66 loc) · 1.39 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
updater={
update_mods={},
next_lookup=0,
S=nil,
proc=nil,
get_stream=function(self)
return self.S
end,
-- is an update run required?
required=function(self, now)
if #self.update_mods == 0 then return false end
--if self.S exists, then a process is already running
if self.S ~= nil then return false end
if now > self.next_lookup then return true end
return false
end,
-- add a module to be updated
add_mod=function(self, mod)
table.insert(self.update_mods, mod)
end,
process_input=function(self)
local line, toks, key, value
if self.S ~= nil
then
line=self.S:readln()
if line == nil
then
poll_streams:delete(self.S)
self.S:close()
self.S=nil
self.proc=nil
return false
end
toks=strutil.TOKENIZER(strutil.trim(line), "=")
key=toks:next()
value=toks:remaining()
if key ~= nil then display_values[key]=value end
end
return true
end,
--do an actual update run, querying data from modules
run=function(self)
local i, mod
for i,mod in ipairs(self.update_mods)
do
mod:lookup()
end
end,
--launch a new update process
launch=function(self)
if self.S == nil
then
self.proc=process.PROCESS("", "stderr2null")
if self.proc == nil
then
self:run()
os.exit()
else
self.next_lookup=time.secs() + settings.updater_run
self.S=self.proc:get_stream()
if self.S ~= nil then poll_streams:add(self.S) end
end
end
return self.S
end
}