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
|
# File 'lib/srs/cli/reschedule.rb', line 6
def run!(arguments)
if not SRS::Workspace.initialised? then
puts "Current directory is not an SRS Workspace"
return 3
end
schedule_id = arguments.shift
score = arguments.shift.to_f
is_new = false;
schedulefile = "schedule/#{schedule_id}"
if not File.exists?(schedulefile) then
schedulefile = "schedule/pending/#{schedule_id}"
is_new = true
if not File.exists?(schedulefile) then
puts "No content with that ID exists"
return 4
end
end
= {}
File.open(schedulefile, "r") do |file|
while( line = file.gets() ) do
if line.strip.empty? then
break
end
key, *val = line.split(':').map{|e| e.strip}
[key] = val.join(':')
end
end
if not .has_key?("Scheduler") then
puts "Schedule #{schedule_id} has no scheduler!\n"
return 6
end
exercise = .delete("Exercise")
schedulername = .delete("Scheduler")
scheduler = getScheduler(schedulername)
= is_new ? scheduler.first_rep(score) : scheduler.rep(score, )
FileUtils.rm_rf( schedulefile )
fileOut = "schedule/#{schedule_id}"
File.open(fileOut, "w") do |file|
file.puts "Exercise: #{exercise}"
file.puts "Scheduler: #{schedulername}"
.each do |key, value|
file.puts "#{key}: #{value.to_s}"
end
end
puts "Exercise rescheduled for #{headersOut["Due"]}"
puts "Exercise failed; marked for repetition" if ["Repeat"]
return 0
end
|