script_executor 1.7.3 → 1.7.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0a0de62f31cf6ee86a7d9ae383d1e28fa4edacd
4
- data.tar.gz: 154c990b179af68c7dfd41697d2c8165a1e2df62
3
+ metadata.gz: 73c1c08d24e34a3c848c5514f9468ac6da34a109
4
+ data.tar.gz: 21361a7deed4aa7961730300d9e8a774c52223d4
5
5
  SHA512:
6
- metadata.gz: f362a894b9185ee0297885933e1db9aa5ede241635b717466fba2cf850228a2c07b006435f8ffe14aaf04a58b1bcb9d7cfd15f10db12c2ad7a5d67f10902ae64
7
- data.tar.gz: 0e1a3bbfaceed66e2d7d2837deefd431ec40f2dce54449f96822f7c6cb4c68a6625cf26a0ac95f471ec7bdd03ed222a83307b760fdf6012ec59a2ca6a4ae8d29
6
+ metadata.gz: 3a49c7dcae66dcb6ac84fe3f37d7317c55a25a8807e4bb46f788a010e4dd3936a926316bceb2a1f013debac9711e48cc0b086678924bfb98e28244c8c178fc7a
7
+ data.tar.gz: 38543fcc57931bfdfe4a52c988fd581e59ba4ecd5bfc9baefd050f57562500fc3972bb4d6c955322104827e9d0c008e6e793a9b26752847bceba6e7ea0a1d777
data/CHANGES CHANGED
@@ -106,6 +106,6 @@
106
106
 
107
107
  * Replace simple parsing with parslet-based parsing.
108
108
 
109
- == Version 1.7.1, 1.7.2,1.7.3
109
+ == Version 1.7.1 - 1.7.4
110
110
 
111
111
  * Bug fixes.
@@ -1,15 +1,23 @@
1
1
  require 'erb'
2
2
  require 'text_interpolator'
3
+
3
4
  require 'script_executor/scripts_parser'
5
+ require 'script_executor/scripts_transform'
4
6
 
5
7
  module ScriptLocator
6
8
 
7
9
  def scripts file
8
10
  data = extract_data file
9
11
 
10
- scripts_parser = ScriptsParser.new
12
+ begin
13
+ scripts_parser = ScriptsParser.new
14
+ parsed_content = scripts_parser.parse data
11
15
 
12
- scripts_parser.parse data
16
+ transformer = ScriptsTransform.new
17
+ transformer.transform(parsed_content)
18
+ rescue Parslet::ParseFailed => failure
19
+ puts failure.cause.ascii_tree
20
+ end
13
21
  end
14
22
 
15
23
  def evaluate_script_body content, env, type=:erb
@@ -1,42 +1,27 @@
1
1
  require 'parslet'
2
2
 
3
- require 'script_executor/scripts_transformer'
4
-
5
3
  class ScriptsParser < Parslet::Parser
6
4
  root :language
7
5
 
8
- # language
9
- rule(:language) { (shebang.as(:shebang).maybe >> ignored.as(:ignored).maybe >> scripts.as(:scripts)).as(:language) }
10
-
11
- rule(:shebang) { str('#') >> str('!') >> match['\w\d_/\s'].repeat(1) }
12
- rule(:ignored) { comment.repeat }
13
- rule(:scripts) { script.repeat }
14
-
15
- rule(:script) { emptyLines >> (name >> comment.maybe >> code).as(:script) }
16
- rule(:comment) { emptyLines >> spaces >> (str('#') >> spaces >> (newline.absent? >> any).repeat.as(:comment)) >> newline }
17
- rule(:name) { spaces >> str('[') >> spaces >> spaces >> nameChars.as(:name) >> spaces >> str(']') >> spaces >> newline }
18
-
19
- rule(:code) { (emptyLines >> codeLine.repeat.maybe >> emptyLines).as(:code) }
20
- rule(:codeLine) { emptyLines >> codeChars.as(:codeLine) >> newline }
6
+ rule(:language) { (shebang.as(:shebang).maybe >> empty_lines >> comment.repeat(0).as(:ignored) >> empty_lines >> scripts).as(:language) }
21
7
 
22
- rule(:nameChars) { match['\w\d_'].repeat(1) }
23
- rule(:codeChars) { match['(.*)\w\d $_#"<>{}\'\/\.%=!\-+/\*|:~@'].repeat(1) }
8
+ rule(:shebang) { str('#') >> str('!') >> match['\w\d_/\s'].repeat(1) }
24
9
 
25
- rule(:emptyLines) { emptyLine.repeat }
26
- rule(:emptyLine) { spaces >> newline }
27
- rule(:newline) { str("\n") >> str("\r").maybe }
10
+ rule(:comment) { (str(';') | str('#')) >> spaces >> (newline.absent? >> any).repeat(0).as(:comment) >> eol }
28
11
 
29
- rule(:spaces) { str(' ').repeat }
12
+ rule(:scripts) { script.repeat(0).as(:scripts) }
30
13
 
31
- def parse content
32
- begin
33
- parsed_content = super content + "\n"
14
+ rule(:name) { spaces >> str('[') >> spaces >> name_chars.as(:name) >> str(']') >> eol }
15
+ rule(:name_chars) { match['\w\d_'].repeat(1) }
34
16
 
35
- transformer = ScriptsTransformer.new
17
+ rule(:script) { (name >> empty_lines >> (name.absent? >> (comment | code_line)).repeat(0)).as(:script) }
18
+ rule(:code_line) { (newline.absent? >> code_chars).repeat(1).as(:code_line) >> eol }
19
+ rule(:code_chars) { any }
36
20
 
37
- transformer.apply(parsed_content)[:scripts]
38
- rescue Parslet::ParseFailed => failure
39
- puts failure.cause.ascii_tree
40
- end
41
- end
21
+ rule(:empty_lines) { empty_line.repeat(0) }
22
+ rule(:empty_line) { spaces >> newline }
23
+ rule(:newline) { str("\n") >> match("\r").maybe }
24
+ rule(:spaces) { match["\s\t "].repeat(0) }
25
+ rule(:eol) { (newline.repeat(0) | eof) }
26
+ rule(:eof) { any.absent? }
42
27
  end
@@ -0,0 +1,50 @@
1
+ require 'parslet'
2
+
3
+ class ScriptsTransform < Parslet::Transform
4
+
5
+ rule(:language => subtree(:language)) do
6
+ language.delete(:ignored)
7
+
8
+ new_scripts = {}
9
+
10
+ language[:scripts].each do |el|
11
+ script = el[:script]
12
+
13
+ name = script[0][:name].to_sym
14
+
15
+ has_main_comment = script[1][:comment] != nil
16
+
17
+ main_comment = has_main_comment ? script[1][:comment].to_s : ''
18
+
19
+ start_index = has_main_comment ? 2 : 1
20
+
21
+ code = []
22
+
23
+ (start_index..script.size-1).each do |index|
24
+ script_node = script[index]
25
+
26
+ comment = script_node[:comment]
27
+
28
+ if comment && comment.to_s !~ /^[\s;#]+$/
29
+ code << '# ' + comment.to_s
30
+ end
31
+
32
+ code_line = script_node[:code_line]
33
+
34
+ if code_line
35
+ code << code_line.to_s
36
+ end
37
+ end
38
+
39
+ new_scripts[name] = {comment: main_comment, code: code}
40
+ end
41
+
42
+ language[:scripts] = new_scripts
43
+
44
+ language
45
+ end
46
+
47
+ def transform content
48
+ apply(content)[:scripts]
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  class ScriptExecutor
2
- VERSION = "1.7.3"
2
+ VERSION = "1.7.4"
3
3
  end
@@ -10,7 +10,7 @@ describe BaseProvision do
10
10
 
11
11
  describe "#initialize" do
12
12
  it "parses content from file" do
13
- expect(subject.script_list.size).to equal(10)
13
+ expect(subject.script_list.size).to equal(9)
14
14
  end
15
15
  end
16
16
 
@@ -1,16 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  require 'script_executor/scripts_parser'
4
- require 'script_executor/scripts_transformer'
4
+ require 'script_executor/scripts_transform'
5
5
 
6
6
  describe ScriptsParser do
7
+
7
8
  describe "#parse" do
8
9
  it "parses content from file 1" do
9
10
  content = File.read('spec/support/script1.sh')
10
11
 
11
12
  parsed_content = subject.parse(content)
12
13
 
13
- ap parsed_content
14
+ #ap parsed_content
15
+
16
+ ap transform parsed_content
14
17
  end
15
18
 
16
19
  it "parses content from file 2" do
@@ -18,7 +21,9 @@ describe ScriptsParser do
18
21
 
19
22
  parsed_content = subject.parse(content)
20
23
 
21
- ap parsed_content
24
+ #ap parsed_content
25
+
26
+ ap transform parsed_content
22
27
  end
23
28
 
24
29
  it "parses content from file 3" do
@@ -26,7 +31,9 @@ describe ScriptsParser do
26
31
 
27
32
  parsed_content = subject.parse(content)
28
33
 
29
- ap parsed_content
34
+ #ap parsed_content
35
+
36
+ ap transform parsed_content
30
37
  end
31
38
 
32
39
  it "parses content from file 4" do
@@ -34,7 +41,9 @@ describe ScriptsParser do
34
41
 
35
42
  parsed_content = subject.parse(content)
36
43
 
37
- ap parsed_content
44
+ #ap parsed_content
45
+
46
+ ap transform parsed_content
38
47
  end
39
48
 
40
49
  it "parses content from file 5" do
@@ -42,7 +51,32 @@ describe ScriptsParser do
42
51
 
43
52
  parsed_content = subject.parse(content)
44
53
 
45
- ap parsed_content
54
+ #ap parsed_content
55
+
56
+ ap transform parsed_content
46
57
  end
58
+
59
+ # it "test" do
60
+ # content = <<-DATA
61
+ # #!/usr/bin/env bash
62
+ #
63
+ # # Some description
64
+ # [name]
65
+ #
66
+ # # some comment
67
+ # aaa
68
+ # bbb
69
+ # DATA
70
+ #
71
+ # parsed_content = subject.parse(content)
72
+ #
73
+ # ap parsed_content
74
+ # end
75
+ end
76
+
77
+ def transform content
78
+ script_transform = ScriptsTransform.new
79
+
80
+ script_transform.transform content
47
81
  end
48
82
  end
@@ -76,7 +76,7 @@ sudo apt-get install -y node
76
76
 
77
77
 
78
78
  #######################################
79
- [rbenv]
79
+ [rbenv ]
80
80
  # Installs node
81
81
 
82
82
  sudo apt-get install -y rbenv
@@ -93,4 +93,4 @@ sudo apt-get install -y libqt4-dev
93
93
  sudo apt-get install -y libqtwebkit-dev
94
94
 
95
95
  # to support headless
96
- sudo apt-get install -y xvfb
96
+ sudo apt-get install -y xvfb
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script_executor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.3
4
+ version: 1.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -161,7 +161,7 @@ files:
161
161
  - lib/script_executor/script_executor.rb
162
162
  - lib/script_executor/script_locator.rb
163
163
  - lib/script_executor/scripts_parser.rb
164
- - lib/script_executor/scripts_transformer.rb
164
+ - lib/script_executor/scripts_transform.rb
165
165
  - lib/script_executor/version.rb
166
166
  - lib/script_locator.rb
167
167
  - script_executor.gemspec
@@ -1,25 +0,0 @@
1
- require 'parslet'
2
-
3
- class ScriptsTransformer < Parslet::Transform
4
- rule(:language => subtree(:language)) do
5
- language.delete(:ignored)
6
-
7
- new_scripts = {}
8
-
9
- language[:scripts].each do |script|
10
- name = script[:script][:name].to_sym
11
- comment = script[:script][:comment].to_s
12
- code = script[:script][:code]
13
-
14
- code.each_with_index do |codeLine, index|
15
- code[index] = codeLine[:codeLine].to_s
16
- end
17
-
18
- new_scripts[name] = {comment: comment, code: code}
19
- end
20
-
21
- language[:scripts] = new_scripts
22
-
23
- language
24
- end
25
- end