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
|
# File 'lib/srs/cli/queue.rb', line 6
def run!(arguments)
if not SRS::Workspace.initialised? then
puts "Current directory is not an SRS Workspace"
return 3
end
queued = {}
repeat = []
Dir["schedule/*"].each do |filename|
next if File.directory?(filename)
schedule = {}
File.open(filename, "r") do |file|
while( line = file.gets() ) do
if line.strip.empty? then
break
end
key, *val = line.split(':').map{|e| e.strip}
schedule[key] = val.join(':')
end
if( schedule["Repeat"] == "true" ) then
repeat << filename
else
due = DateTime.parse(schedule["Due"])
if( due < DateTime.now ) then
queued[filename] = due
end
end
end
end
ws = SRS::Workspace.new
File.open("#{ws.dotsrs}/QUEUED", "w") do |queued_file|
queued.sort_by{ |key, value| value }
queued.each do |filename, due|
queued_file.puts filename
end
end
File.open("#{ws.dotsrs}/REPEAT", "w") do |repeat_file|
repeat.each do |filename|
repeat_file.puts filename
end
end
return 0
end
|