recot 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +43 -0
- data/Gemfile +3 -0
- data/Guardfile +22 -0
- data/LICENSE +21 -0
- data/README.md +100 -0
- data/Rakefile +7 -0
- data/bin/recot +47 -0
- data/lib/recot.rb +44 -0
- data/lib/recot/cache/state_cache.rb +74 -0
- data/lib/recot/commands.rb +46 -0
- data/lib/recot/commands/current_clear.rb +32 -0
- data/lib/recot/commands/guard_server.rb +36 -0
- data/lib/recot/commands/interactive_ui.rb +67 -0
- data/lib/recot/commands/listener.rb +49 -0
- data/lib/recot/commands/observer.rb +24 -0
- data/lib/recot/commands/rack_server.rb +37 -0
- data/lib/recot/commands/recent_cancel.rb +44 -0
- data/lib/recot/commands/tree_generator.rb +20 -0
- data/lib/recot/config.rb +48 -0
- data/lib/recot/render/html_renderer.rb +50 -0
- data/lib/recot/tasks.rb +12 -0
- data/lib/recot/tasks/base_task.rb +55 -0
- data/lib/recot/tasks/indexdoc_task.rb +55 -0
- data/lib/recot/tasks/resdoc_task.rb +83 -0
- data/lib/recot/tasks/sync_task.rb +43 -0
- data/lib/recot/utils/recot_util.rb +72 -0
- data/lib/recot/version.rb +5 -0
- data/recot.gemspec +35 -0
- data/template/css/recot.css +87 -0
- data/template/css/theme/white.css +75 -0
- data/template/index.html.erb +36 -0
- data/template/resdoc.html.erb +44 -0
- metadata +217 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'guard/cli'
|
3
|
+
|
4
|
+
module Recot
|
5
|
+
module Commands
|
6
|
+
class GuardServer
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
path = File.expand_path('../../../../', __FILE__)
|
10
|
+
@guardfile = "#{path}/Guardfile"
|
11
|
+
# setup guard ui options
|
12
|
+
Guard::UI.options[:level] = :error
|
13
|
+
Guard::UI.options[:template] = "guard error!! > :message"
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
@thread = start_guard
|
18
|
+
Thread.new do
|
19
|
+
loop do
|
20
|
+
sleep 1
|
21
|
+
@thread.wakeup
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def start_guard
|
27
|
+
Thread.new do
|
28
|
+
Guard.start(
|
29
|
+
guardfile: @guardfile,
|
30
|
+
no_interactions: true)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'recot/utils/recot_util'
|
3
|
+
require 'recot/commands/recent_cancel'
|
4
|
+
require 'recot/commands/current_clear'
|
5
|
+
require 'recot/commands/tree_generator'
|
6
|
+
|
7
|
+
module Recot
|
8
|
+
module Commands
|
9
|
+
class InteractiveUi
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
print_banner()
|
16
|
+
|
17
|
+
count = 1
|
18
|
+
loop do
|
19
|
+
|
20
|
+
print "[#{count}](recot) > "
|
21
|
+
input_str = STDIN.gets.chomp
|
22
|
+
case input_str
|
23
|
+
when /[Ee]xit/
|
24
|
+
break
|
25
|
+
when /[Cc]ancel/
|
26
|
+
# Cancel recent evidence.
|
27
|
+
RecentCancel.cancel
|
28
|
+
when /[Cc]lear/
|
29
|
+
# Clear current test no.
|
30
|
+
CurrentClear.clear
|
31
|
+
when /\d{1,3}(-\d{1,3})?(-\d{1,3})?/
|
32
|
+
# Generate tree.
|
33
|
+
TreeGenerator.generate(input_str)
|
34
|
+
else
|
35
|
+
# Continue...
|
36
|
+
end
|
37
|
+
count += 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
loop do
|
43
|
+
print "Sure you want to delete all the files? [y/N] > "
|
44
|
+
input_str = STDIN.gets.chomp
|
45
|
+
case input_str
|
46
|
+
when /^y$/
|
47
|
+
Utils::RecotUtil.remove
|
48
|
+
puts "Removed all the files and cache."
|
49
|
+
else
|
50
|
+
end
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def print_banner
|
56
|
+
puts "Start recot ver #{Recot::VERSION}"
|
57
|
+
puts ""
|
58
|
+
puts ' ____ __'
|
59
|
+
puts ' / __ \___ _________ / /'
|
60
|
+
puts ' / /_/ / _ \/ ___/ __ \/ __/'
|
61
|
+
puts ' / _, _/ __/ /__/ /_/ / /'
|
62
|
+
puts '/_/ |_|\___/\___/\____/\__/'
|
63
|
+
puts ""
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'listen'
|
3
|
+
require 'recot/tasks'
|
4
|
+
|
5
|
+
module Recot
|
6
|
+
module Commands
|
7
|
+
class Listener
|
8
|
+
|
9
|
+
def initialize(ignore = nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
@listener = ::Listen.to(Recot.basket_dir) do |mod, add, del|
|
14
|
+
on_modifyed(mod)
|
15
|
+
on_added(add)
|
16
|
+
end
|
17
|
+
@listener.start
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_added(files)
|
21
|
+
notify(files)
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_modifyed(files)
|
25
|
+
notify(files)
|
26
|
+
end
|
27
|
+
|
28
|
+
def notify(files)
|
29
|
+
return if files.empty?
|
30
|
+
|
31
|
+
# Check test no.
|
32
|
+
unless Cache::StateCache.restore_no
|
33
|
+
puts "Please input test no. Press the Enter to continue."
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
# Run all tasks.
|
38
|
+
Recot::Tasks::ALL_TASKS.each do |t|
|
39
|
+
cls = Object.const_get("Recot::Tasks::#{t}")
|
40
|
+
cls.new.run(files)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def stop
|
45
|
+
@listener.stop
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Recot
|
4
|
+
module Commands
|
5
|
+
module Observer
|
6
|
+
|
7
|
+
def self.extended(base)
|
8
|
+
base.class_eval do
|
9
|
+
@tasks = []
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_task(task)
|
14
|
+
@tasks << task
|
15
|
+
end
|
16
|
+
|
17
|
+
def notify(args = nil)
|
18
|
+
@tasks.each do |t|
|
19
|
+
t.run(args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rack'
|
3
|
+
require 'rack/livereload'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module Recot
|
7
|
+
module Commands
|
8
|
+
class RackServer
|
9
|
+
|
10
|
+
DEF_PORT = 9292
|
11
|
+
|
12
|
+
def initialize(port = nil)
|
13
|
+
@port = port
|
14
|
+
@port ||= DEF_PORT
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
rack_app = Rack::Builder.new do
|
19
|
+
use Rack::LiveReload
|
20
|
+
run Rack::Directory.new('.')
|
21
|
+
end
|
22
|
+
|
23
|
+
# run rack server
|
24
|
+
Rack::Server.new(
|
25
|
+
app: rack_app,
|
26
|
+
Port: @port,
|
27
|
+
Logger: server_logger,
|
28
|
+
AccessLog: server_logger).start
|
29
|
+
end
|
30
|
+
|
31
|
+
def server_logger
|
32
|
+
Logger.new("#{Dir.pwd}/log/access.log")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'fileutils'
|
3
|
+
require 'recot/cache/state_cache'
|
4
|
+
require 'recot/tasks/indexdoc_task'
|
5
|
+
require 'recot/tasks/resdoc_task'
|
6
|
+
|
7
|
+
module Recot
|
8
|
+
module Commands
|
9
|
+
class RecentCancel
|
10
|
+
|
11
|
+
# Delete recent evidence resources.
|
12
|
+
#
|
13
|
+
# Set nil to cache after delete.
|
14
|
+
def self.cancel
|
15
|
+
# Get recent evidence from cache
|
16
|
+
evidences = Recot::Cache::StateCache.restore_recent_evidence
|
17
|
+
if evidences && !evidences.empty?
|
18
|
+
# Get directory path.
|
19
|
+
path = File.dirname(evidences.first)
|
20
|
+
|
21
|
+
# Remove files.
|
22
|
+
FileUtils.rm(evidences)
|
23
|
+
|
24
|
+
# Check directory files count.
|
25
|
+
if Dir.glob("#{path}/*").count == 0
|
26
|
+
# Delete resource html file.
|
27
|
+
no = Recot::Cache::StateCache.restore_no
|
28
|
+
resdoc_path = "#{Recot.resources_dir}/#{no}.html"
|
29
|
+
# Remove resource html file.
|
30
|
+
FileUtils.rm(resdoc_path) if File.exist?(resdoc_path)
|
31
|
+
# Update index html file.
|
32
|
+
Recot::Tasks::IndexdocTask.new.run
|
33
|
+
else
|
34
|
+
# Update resource doc.
|
35
|
+
Recot::Tasks::ResdocTask.new.run(evidences)
|
36
|
+
end
|
37
|
+
# Set nil at recent evidence.
|
38
|
+
Recot::Cache::StateCache.store_recent_evidence(nil)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'fileutils'
|
3
|
+
require 'recot/cache/state_cache'
|
4
|
+
|
5
|
+
module Recot
|
6
|
+
module Commands
|
7
|
+
class TreeGenerator
|
8
|
+
|
9
|
+
def self.generate(test_no)
|
10
|
+
# generate test no tree
|
11
|
+
path = "#{Recot.resources_dir}/#{test_no}"
|
12
|
+
unless File.exists?(path)
|
13
|
+
FileUtils.mkdir_p(path)
|
14
|
+
# cache current number
|
15
|
+
Recot::Cache::StateCache.store_no(test_no)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/recot/config.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module Recot
|
5
|
+
class Config
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
CONFIG_YML = 'config.yml'.freeze
|
9
|
+
|
10
|
+
KEY_THEME = 'theme'.freeze
|
11
|
+
KEY_PROJECT_NAME = 'project_name'.freeze
|
12
|
+
|
13
|
+
DEFAULT_THEME = 'white'.freeze
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
# read config.yml file
|
17
|
+
@config = nil
|
18
|
+
if File.exist?("#{Dir.pwd}/#{CONFIG_YML}")
|
19
|
+
@config = YAML.load_file("#{Dir.pwd}/#{CONFIG_YML}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get theme from config.yml.
|
24
|
+
#
|
25
|
+
# == Returns:
|
26
|
+
# A theme of html. If not set return 'white'.
|
27
|
+
def theme
|
28
|
+
th = DEFAULT_THEME
|
29
|
+
if @config && @config[KEY_THEME]
|
30
|
+
th = @config[KEY_THEME]
|
31
|
+
end
|
32
|
+
th
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get project_name from config.yml.
|
36
|
+
#
|
37
|
+
# == Returns:
|
38
|
+
# A project_name. If not set return empty.
|
39
|
+
def project_name
|
40
|
+
name = ''
|
41
|
+
if @config && @config[KEY_PROJECT_NAME]
|
42
|
+
name = @config[KEY_PROJECT_NAME]
|
43
|
+
end
|
44
|
+
name
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Recot
|
5
|
+
module Render
|
6
|
+
class HtmlRenderer
|
7
|
+
|
8
|
+
# Render html file.
|
9
|
+
#
|
10
|
+
# == Parameters:
|
11
|
+
# template::
|
12
|
+
# Template file path for render.
|
13
|
+
# output::
|
14
|
+
# Path of index html file.
|
15
|
+
# data::
|
16
|
+
# Hash object of binding data.
|
17
|
+
def render_doc(template, output, data)
|
18
|
+
unless data
|
19
|
+
$stderr.puts "binding args invalid : #{data}"
|
20
|
+
else
|
21
|
+
render(template, output, data)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Render html file.
|
28
|
+
#
|
29
|
+
# == Parameters:
|
30
|
+
# template::
|
31
|
+
# Path of template for render html.
|
32
|
+
# output::
|
33
|
+
# Path of resource html file.
|
34
|
+
# data::
|
35
|
+
# Hash object of binding data.
|
36
|
+
def render(template, output, data)
|
37
|
+
begin
|
38
|
+
erb = ERB.new(File.read(template), nil, '-')
|
39
|
+
ret = erb.result(binding)
|
40
|
+
File.open(output, "w:utf-8") do |f|
|
41
|
+
f.write(ret)
|
42
|
+
end
|
43
|
+
rescue => ex
|
44
|
+
$stderr.puts "render html exception #{ex}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/recot/tasks.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'recot/tasks/base_task'
|
3
|
+
require 'recot/tasks/sync_task'
|
4
|
+
require 'recot/tasks/resdoc_task'
|
5
|
+
require 'recot/tasks/indexdoc_task'
|
6
|
+
|
7
|
+
module Recot
|
8
|
+
module Tasks
|
9
|
+
# declare all task
|
10
|
+
ALL_TASKS = %w(SyncTask ResdocTask IndexdocTask)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Recot
|
4
|
+
module Tasks
|
5
|
+
|
6
|
+
class BaseTask
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@user_root = Dir.pwd
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(args = nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
# Get Current test no.
|
18
|
+
#
|
19
|
+
# == Returns:
|
20
|
+
# Number of test.
|
21
|
+
# If not cached test no return empty string.
|
22
|
+
def get_testno()
|
23
|
+
test_no = Recot::Cache::StateCache.restore_no
|
24
|
+
unless test_no
|
25
|
+
return "" # return empty string
|
26
|
+
end
|
27
|
+
test_no
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get current evidence path.
|
31
|
+
#
|
32
|
+
# == Returns:
|
33
|
+
# A string of evidence path.
|
34
|
+
def evidence_path()
|
35
|
+
"#{Recot.resources_dir}/#{get_testno}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get relative path from __output.
|
39
|
+
#
|
40
|
+
# == Returns:
|
41
|
+
# Relative path from __output.
|
42
|
+
def relative_path_from_output(path)
|
43
|
+
path.gsub("#{Dir.pwd}/__output/", '')
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get relative path from resource.
|
47
|
+
#
|
48
|
+
# == Returns:
|
49
|
+
# Relative path from resource.
|
50
|
+
def relative_path_from_resource(path)
|
51
|
+
path.gsub("#{Dir.pwd}/__output/resources/", '')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|