codersdojo 1.5.06 → 1.5.07
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/codersdojo.rb +4 -2
- data/lib/{argument_parser.rb → commands/command_configuration.rb} +14 -18
- data/lib/commands/start_command.rb +3 -1
- data/lib/console_view.rb +1 -1
- data/lib/run/runner.rb +4 -16
- data/lib/run/scheduler.rb +11 -34
- data/lib/run/scheduler_interrupt_listener.rb +38 -0
- metadata +7 -6
data/lib/codersdojo.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'shellutils/argument_parser'
|
3
4
|
require 'console_view'
|
4
|
-
require '
|
5
|
+
require 'commands/command_configuration'
|
5
6
|
require 'scaffold/scaffolder'
|
6
7
|
|
7
8
|
class CodersDojo
|
@@ -18,7 +19,8 @@ class CodersDojo
|
|
18
19
|
view = ConsoleView.new scaffolder
|
19
20
|
|
20
21
|
begin
|
21
|
-
|
22
|
+
command_config = CommandConfiguration.new shell, view, scaffolder, @hostname
|
23
|
+
arg_parser = ArgumentParser.new command_config.commands
|
22
24
|
command = arg_parser.parse @params
|
23
25
|
rescue ShellArgumentException => e
|
24
26
|
view.show_unknwon_command_message e.command
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'record/session_id_generator'
|
2
|
+
require 'record/state_recorder'
|
2
3
|
require 'run/runner'
|
3
4
|
require 'state_reader'
|
4
5
|
require 'shellutils/shell_argument_exception'
|
@@ -15,11 +16,13 @@ require 'commands/upload_no_open_command'
|
|
15
16
|
require 'commands/upload_zipped_session_command'
|
16
17
|
require 'commands/start_command'
|
17
18
|
|
18
|
-
class
|
19
|
+
class CommandConfiguration
|
20
|
+
|
21
|
+
attr_reader :commands
|
19
22
|
|
20
23
|
def initialize shell, view, scaffolder, hostname
|
21
24
|
meta_config_file = MetaConfigFile.new shell
|
22
|
-
runner =
|
25
|
+
runner = create_runner shell, view, meta_config_file
|
23
26
|
@help_command = HelpCommand.new view
|
24
27
|
@xhelp_command = XHelpCommand.new view
|
25
28
|
@generate_command = GenerateCommand.new shell, view, scaffolder
|
@@ -35,22 +38,15 @@ class ArgumentParser
|
|
35
38
|
@upload_command, @upload_no_open_command, @upload_zipped_session_command]
|
36
39
|
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
if not command_executed and command_name == "spec"
|
49
|
-
# 'spec" is for testing purpose only: do nothing special
|
50
|
-
elsif not command_executed
|
51
|
-
raise ShellArgumentException.new command_name
|
52
|
-
end
|
41
|
+
private
|
42
|
+
|
43
|
+
def create_runner shell, view, meta_config_file
|
44
|
+
state_recorder = StateRecorder.new shell, SessionIdGenerator.new, meta_config_file
|
45
|
+
runner = Runner.new shell, view
|
46
|
+
runner.init_session_callback = Proc.new {state_recorder.init_session}
|
47
|
+
runner.execute_callback = Proc.new {|files, process| state_recorder.record_state files, process}
|
48
|
+
runner
|
53
49
|
end
|
54
|
-
|
50
|
+
|
55
51
|
end
|
56
52
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'meta_config_file'
|
2
2
|
require 'run/scheduler'
|
3
|
+
require 'run/scheduler_interrupt_listener'
|
3
4
|
|
4
5
|
class StartCommand
|
5
6
|
|
@@ -20,7 +21,8 @@ class StartCommand
|
|
20
21
|
@view.show_start_kata command, file, @meta_file.framework_property
|
21
22
|
@runner.source_files = @meta_file.source_files
|
22
23
|
@runner.run_command = command
|
23
|
-
scheduler = Scheduler.new @runner
|
24
|
+
scheduler = Scheduler.new @runner
|
25
|
+
scheduler.interrupt_listener = SchedulerInterruptListener.new @view, @eval_loop_commands
|
24
26
|
scheduler.start
|
25
27
|
end
|
26
28
|
|
data/lib/console_view.rb
CHANGED
@@ -28,6 +28,7 @@ Commands:
|
|
28
28
|
help <command> See the details of the command.
|
29
29
|
xhelp Print help text for advanced commands.
|
30
30
|
setup <framework> <kata_file> Setup the environment for running the kata.
|
31
|
+
upload-zip [<session_dir>] Upload session as a ZIP file (beta feature)
|
31
32
|
upload [<session_dir>] Upload the kata to http://www.codersdojo.org and open the kata in a browser.
|
32
33
|
upload-no-open [<session_dir>] Upload the kata to http://www.codersdojo.org
|
33
34
|
|
@@ -43,7 +44,6 @@ Commands:
|
|
43
44
|
init-session Create a new session dir within the .codersdojo dir.
|
44
45
|
capture-single-run <shell_command> <kata_file> Capture a single run.
|
45
46
|
start <shell_command> <kata_file> Start the continuous test loop.
|
46
|
-
upload-zip [<session_dir>] Upload session as a ZIP file (beta feature)
|
47
47
|
helptext
|
48
48
|
end
|
49
49
|
|
data/lib/run/runner.rb
CHANGED
@@ -1,31 +1,19 @@
|
|
1
|
-
require "info_property_file"
|
2
|
-
require "filename_formatter"
|
3
|
-
require "record/state_recorder"
|
4
|
-
|
5
1
|
class Runner
|
6
2
|
|
7
|
-
attr_accessor :source_files, :run_command
|
3
|
+
attr_accessor :source_files, :run_command, :init_session_callback, :execute_callback
|
8
4
|
|
9
5
|
WORKING_DIR = '.'
|
10
6
|
|
11
|
-
def initialize shell,
|
12
|
-
@filename_formatter = FilenameFormatter.new
|
7
|
+
def initialize shell, view
|
13
8
|
@shell = shell
|
14
|
-
@session_id_generator = session_id_generator
|
15
9
|
@view = view
|
16
|
-
@meta_config_file = meta_config_file
|
17
10
|
end
|
18
11
|
|
19
12
|
def start
|
20
|
-
|
21
|
-
init_session
|
13
|
+
if @init_session_callback then @init_session_callback.call end
|
22
14
|
execute
|
23
15
|
end
|
24
16
|
|
25
|
-
def init_session
|
26
|
-
@state_recorder.init_session
|
27
|
-
end
|
28
|
-
|
29
17
|
def execute
|
30
18
|
files = @shell.files_in_dir_tree WORKING_DIR, @source_files
|
31
19
|
newest_dir_entry = @shell.newest_dir_entry WORKING_DIR, files
|
@@ -42,7 +30,7 @@ class Runner
|
|
42
30
|
|
43
31
|
def execute_once files
|
44
32
|
process = @shell.execute @run_command
|
45
|
-
@
|
33
|
+
if @execute_callback then @execute_callback.call(files, process) end
|
46
34
|
end
|
47
35
|
|
48
36
|
def run_command= command
|
data/lib/run/scheduler.rb
CHANGED
@@ -1,54 +1,31 @@
|
|
1
1
|
class Scheduler
|
2
2
|
|
3
|
-
|
3
|
+
attr_accessor :interrupt_listener
|
4
|
+
|
5
|
+
def initialize runner
|
4
6
|
@runner = runner
|
5
|
-
@view = view
|
6
|
-
@last_action = ""
|
7
|
-
@commands = commands
|
8
|
-
@continue_after_command = false
|
9
7
|
end
|
10
8
|
|
11
9
|
def start
|
12
|
-
|
10
|
+
@continue = true
|
13
11
|
register_interrupt_listener
|
14
12
|
@runner.start
|
15
|
-
while continue
|
13
|
+
while @continue do
|
16
14
|
sleep 1
|
17
15
|
@runner.execute
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
19
|
+
private
|
20
|
+
|
21
21
|
def register_interrupt_listener
|
22
22
|
trap("INT") {
|
23
|
-
|
23
|
+
interrupt
|
24
24
|
}
|
25
25
|
end
|
26
|
-
|
27
|
-
def interrupt_kata
|
28
|
-
@continue_after_command = false
|
29
|
-
@view.show_kata_exit_message
|
30
|
-
@last_action = @view.read_user_input.downcase
|
31
|
-
@commands.each do |command|
|
32
|
-
if @last_action.start_with? command.command_key
|
33
|
-
command.execute
|
34
|
-
@continue_after_command = command.continue_test_loop?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
if last_action_was_exit? then
|
38
|
-
@view.show_kata_upload_hint
|
39
|
-
end
|
40
|
-
end
|
41
26
|
|
42
|
-
def
|
43
|
-
@
|
44
|
-
|
45
|
-
|
46
|
-
def last_action_was_resume?
|
47
|
-
@last_action.start_with? 'r'
|
48
|
-
end
|
49
|
-
|
50
|
-
def last_action_was_exit?
|
51
|
-
@last_action.start_with? 'e'
|
52
|
-
end
|
27
|
+
def interrupt
|
28
|
+
if @interrupt_listener then @continue = @interrupt_listener.interrupt end
|
29
|
+
end
|
53
30
|
|
54
31
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class SchedulerInterruptListener
|
2
|
+
|
3
|
+
def initialize view, commands
|
4
|
+
@view = view
|
5
|
+
@commands = commands
|
6
|
+
@continue_after_command = false
|
7
|
+
@last_action = ""
|
8
|
+
end
|
9
|
+
|
10
|
+
def interrupt
|
11
|
+
@continue_after_command = false
|
12
|
+
@view.show_kata_exit_message
|
13
|
+
@last_action = @view.read_user_input.downcase
|
14
|
+
@commands.each do |command|
|
15
|
+
if @last_action.start_with? command.command_key
|
16
|
+
command.execute
|
17
|
+
@continue_after_command = command.continue_test_loop?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
if last_action_was_exit? then
|
21
|
+
@view.show_kata_upload_hint
|
22
|
+
end
|
23
|
+
continue?
|
24
|
+
end
|
25
|
+
|
26
|
+
def continue?
|
27
|
+
@last_action == '' or last_action_was_resume? or @continue_after_command
|
28
|
+
end
|
29
|
+
|
30
|
+
def last_action_was_resume?
|
31
|
+
@last_action.start_with? 'r'
|
32
|
+
end
|
33
|
+
|
34
|
+
def last_action_was_exit?
|
35
|
+
@last_action.start_with? 'e'
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 1.5.
|
8
|
+
- 7
|
9
|
+
version: 1.5.07
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- CodersDojo-Team
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-10-01 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -69,8 +69,8 @@ dependencies:
|
|
69
69
|
segments:
|
70
70
|
- 0
|
71
71
|
- 0
|
72
|
-
-
|
73
|
-
version: 0.0.
|
72
|
+
- 9
|
73
|
+
version: 0.0.9
|
74
74
|
type: :runtime
|
75
75
|
version_requirements: *id004
|
76
76
|
description: Client executes tests in an endless loop and logs source code and test result for later uplaod.
|
@@ -82,9 +82,9 @@ extensions: []
|
|
82
82
|
extra_rdoc_files: []
|
83
83
|
|
84
84
|
files:
|
85
|
-
- lib/argument_parser.rb
|
86
85
|
- lib/codersdojo.rb
|
87
86
|
- lib/commands/capture_single_run_command.rb
|
87
|
+
- lib/commands/command_configuration.rb
|
88
88
|
- lib/commands/generate_command.rb
|
89
89
|
- lib/commands/help_command.rb
|
90
90
|
- lib/commands/init_session_command.rb
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/record/text_converter.rb
|
106
106
|
- lib/run/runner.rb
|
107
107
|
- lib/run/scheduler.rb
|
108
|
+
- lib/run/scheduler_interrupt_listener.rb
|
108
109
|
- lib/scaffold/scaffolder.rb
|
109
110
|
- lib/scaffold/text_template_machine.rb
|
110
111
|
- lib/state.rb
|