script_executor 1.7.2 → 1.7.3

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: 46d6695b3e0e7450b4fcec663a84a49b085cc90f
4
- data.tar.gz: b6fe05e4038b43b2e69778500b26a6eeb4935554
3
+ metadata.gz: e0a0de62f31cf6ee86a7d9ae383d1e28fa4edacd
4
+ data.tar.gz: 154c990b179af68c7dfd41697d2c8165a1e2df62
5
5
  SHA512:
6
- metadata.gz: 14c40167ea6d3f4830ad6034ac47c46c952c787aa57c0dfedec7880c6e62dbf6692f6d0d6d5872b4061aa3cc2f6468ea135d8fb4ec66ddaf1b706e3f66fac077
7
- data.tar.gz: bef48a0165ac5110a6a8032e1b477baf8b649dcf5a3385305035c6ab120c1a5b702c5f8df386e82fd5ce093ed6f59a8e3ee419f23bfabc3af9c57b40c1229911
6
+ metadata.gz: f362a894b9185ee0297885933e1db9aa5ede241635b717466fba2cf850228a2c07b006435f8ffe14aaf04a58b1bcb9d7cfd15f10db12c2ad7a5d67f10902ae64
7
+ data.tar.gz: 0e1a3bbfaceed66e2d7d2837deefd431ec40f2dce54449f96822f7c6cb4c68a6625cf26a0ac95f471ec7bdd03ed222a83307b760fdf6012ec59a2ca6a4ae8d29
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
109
+ == Version 1.7.1, 1.7.2,1.7.3
110
110
 
111
- * Bug fix.
111
+ * Bug fixes.
data/README.md CHANGED
@@ -95,11 +95,11 @@ require 'script_locator'
95
95
 
96
96
  include ScriptLocator
97
97
 
98
- puts scripts(__FILE__) # [command1, command2]
98
+ scripts = scripts(__FILE__) # [command1, command2]
99
99
 
100
100
  name = "john"
101
101
 
102
- result = evaluate_script_body(result['command1'], binding)
102
+ result = evaluate_script_body(scripts[:command1][:code], binding)
103
103
 
104
104
  puts result # john
105
105
  __END__
@@ -113,7 +113,69 @@ echo "<%= name %>"
113
113
  echo "test2"
114
114
  ```
115
115
 
116
+ ## Using BaseProvision
117
+
118
+ - Create project configuration file:
119
+
120
+ ```json
121
+ # base.conf.json
122
+ {
123
+ "node": {
124
+ "domain": "22.22.22.22", // remote host, see "config.vm.synced_folder"
125
+ "port": "22", // default ssh port
126
+ "user": "vagrant", // vagrant user name
127
+ "password": "vagrant", // vagrant user password
128
+ "home": "/home/vagrant",
129
+ "remote": true
130
+ },
131
+
132
+ "project": {
133
+ "home": "#{node.home}/acceptance_demo",
134
+ "ruby_version": "2.2.3",
135
+ "gemset": "acceptance_demo"
136
+ }
137
+ }
138
+ ```
139
+
140
+ - Create file with shell commands:
141
+
142
+ ```
143
+ # script.sh
144
+
145
+
146
+ [echo]
147
+
148
+ echo "Hello world!"
149
+
150
+
151
+ [ubuntu_update]
116
152
 
153
+ sudo apt-get update
154
+ ```
155
+
156
+ - Create provision based on thor and use it:
157
+
158
+ ```
159
+ # install.thor
160
+
161
+ class MyProvision < Thor
162
+ @provision = BaseProvision.new self, 'base.conf.json', ['script.sh']
163
+ @provision.create_thor_methods(self)
164
+
165
+ desc "local_command", "local_command"
166
+ def local_command
167
+ invoke :echo
168
+ invoke :ubuntu_update
169
+ end
170
+ end
171
+
172
+ my_provision = MyProvision.new
173
+
174
+ thor my_provision:echo
175
+ thor my_provision:ubuntu_update
176
+
177
+ thor my_provision:local_command
178
+ ```
117
179
 
118
180
  ## Contributing
119
181
 
@@ -10,7 +10,8 @@ class BaseProvision
10
10
 
11
11
  attr_reader :interpolator, :env, :script_list, :server_info
12
12
 
13
- def initialize parent_class, config_file_name, scripts_file_names
13
+ def initialize config_file_name, scripts_file_names
14
+ @terminal = HighLine.new
14
15
  @interpolator = TextInterpolator.new
15
16
 
16
17
  @env = read_config(config_file_name)
@@ -21,18 +22,14 @@ class BaseProvision
21
22
  @script_list.merge!(scripts(name))
22
23
  end
23
24
 
24
- create_script_methods
25
-
26
- create_thor_methods(parent_class) if parent_class.ancestors.collect(&:to_s).include?('Thor')
27
-
28
25
  @server_info = env[:node] ? env[:node] : {}
29
26
 
30
- @terminal ||= HighLine.new
27
+ create_script_methods
31
28
  end
32
29
 
33
30
  def run script_name, params={}, type=:string
34
- execute(server_info) do
35
- evaluate_script_body(script_list[script_name.to_sym][:codeLines].join("\n"), params, type)
31
+ execute(server_info) do
32
+ evaluate_script_body(script_list[script_name.to_sym][:code], params, type)
36
33
  end
37
34
  end
38
35
 
@@ -59,17 +56,19 @@ class BaseProvision
59
56
  end
60
57
 
61
58
  def create_thor_methods parent_class
62
- provision = self
59
+ if parent_class.ancestors.collect(&:to_s).include?('Thor')
60
+ provision = self
63
61
 
64
- provision.script_list.each do |name, value|
65
- title = value[:comment]
62
+ provision.script_list.each do |name, value|
63
+ title = value[:comment]
66
64
 
67
- title = title.nil? ? name : title
65
+ title = title.nil? ? name : title
68
66
 
69
- parent_class.send(:desc, name, title) if parent_class.respond_to?(:desc)
67
+ parent_class.send(:desc, name, title) if parent_class.respond_to?(:desc)
70
68
 
71
- parent_class.send(:define_method, name.to_sym) do
72
- provision.send "#{name}".to_sym
69
+ parent_class.send(:define_method, name.to_sym) do
70
+ provision.send "#{name}".to_sym
71
+ end
73
72
  end
74
73
  end
75
74
  end
@@ -13,6 +13,8 @@ module ScriptLocator
13
13
  end
14
14
 
15
15
  def evaluate_script_body content, env, type=:erb
16
+ content = content.join("\n") if content.kind_of? Array
17
+
16
18
  case type
17
19
  when :erb
18
20
  template = ERB.new content
@@ -12,11 +12,11 @@ class ScriptsParser < Parslet::Parser
12
12
  rule(:ignored) { comment.repeat }
13
13
  rule(:scripts) { script.repeat }
14
14
 
15
- rule(:script) { emptyLines >> (name >> comment.maybe >> codeLines).as(:script) }
15
+ rule(:script) { emptyLines >> (name >> comment.maybe >> code).as(:script) }
16
16
  rule(:comment) { emptyLines >> spaces >> (str('#') >> spaces >> (newline.absent? >> any).repeat.as(:comment)) >> newline }
17
17
  rule(:name) { spaces >> str('[') >> spaces >> spaces >> nameChars.as(:name) >> spaces >> str(']') >> spaces >> newline }
18
18
 
19
- rule(:codeLines) { (emptyLines >> codeLine.repeat.maybe >> emptyLines).as(:codeLines) }
19
+ rule(:code) { (emptyLines >> codeLine.repeat.maybe >> emptyLines).as(:code) }
20
20
  rule(:codeLine) { emptyLines >> codeChars.as(:codeLine) >> newline }
21
21
 
22
22
  rule(:nameChars) { match['\w\d_'].repeat(1) }
@@ -9,13 +9,13 @@ class ScriptsTransformer < Parslet::Transform
9
9
  language[:scripts].each do |script|
10
10
  name = script[:script][:name].to_sym
11
11
  comment = script[:script][:comment].to_s
12
- code_lines = script[:script][:codeLines]
12
+ code = script[:script][:code]
13
13
 
14
- code_lines.each_with_index do |codeLine, index|
15
- code_lines[index] = codeLine[:codeLine].to_s
14
+ code.each_with_index do |codeLine, index|
15
+ code[index] = codeLine[:codeLine].to_s
16
16
  end
17
17
 
18
- new_scripts[name] = {comment: comment, codeLines: code_lines}
18
+ new_scripts[name] = {comment: comment, code: code}
19
19
  end
20
20
 
21
21
  language[:scripts] = new_scripts
@@ -1,3 +1,3 @@
1
1
  class ScriptExecutor
2
- VERSION = "1.7.2"
2
+ VERSION = "1.7.3"
3
3
  end
@@ -3,14 +3,10 @@ require 'spec_helper'
3
3
  require 'thor'
4
4
  require 'script_executor/base_provision'
5
5
 
6
- class ThorClass < Thor
7
-
8
- end
6
+ class ThorClass < Thor; end
9
7
 
10
8
  describe BaseProvision do
11
- subject {
12
- BaseProvision.new ThorClass, 'spec/support/base.conf.json', ['spec/support/big_script.sh']
13
- }
9
+ subject { BaseProvision.new 'spec/support/base.conf.json', ['spec/support/script1.sh'] }
14
10
 
15
11
  describe "#initialize" do
16
12
  it "parses content from file" do
@@ -16,7 +16,7 @@ describe ScriptLocator do
16
16
  end
17
17
 
18
18
  it "reads from file completely if it does not have __END__ tag" do
19
- file = File.expand_path('support/test.conf', File.dirname(__FILE__))
19
+ file = File.expand_path('support/script4.sh', File.dirname(__FILE__))
20
20
 
21
21
  scripts = subject.scripts(file)
22
22
 
@@ -30,23 +30,23 @@ describe ScriptLocator do
30
30
 
31
31
  name = "alisa"
32
32
 
33
- result = subject.evaluate_script_body(scripts[:test1][:codeLines], binding)
33
+ result = subject.evaluate_script_body(scripts[:test1][:code], binding)
34
34
 
35
- expect(result.first).to match /#{name}/
35
+ expect(result).to match /#{name}/
36
36
 
37
37
  expect(scripts[:test1][:comment]).to eq "Some description"
38
38
  end
39
39
 
40
40
  it "locates script inside external file and evaluates it as string" do
41
- file = File.expand_path('support/test.conf', File.dirname(__FILE__))
41
+ file = File.expand_path('support/script4.sh', File.dirname(__FILE__))
42
42
 
43
43
  scripts = subject.scripts(file)
44
44
 
45
45
  env = {:name => "alisa"}
46
46
 
47
- result = subject.evaluate_script_body(scripts[:test1][:codeLines], env, :string)
47
+ result = subject.evaluate_script_body(scripts[:test1][:code], env, :string)
48
48
 
49
- expect(result.first).to match /#{env[:name]}/
49
+ expect(result).to match /#{env[:name]}/
50
50
  end
51
51
  end
52
52
 
@@ -5,9 +5,40 @@ require 'script_executor/scripts_transformer'
5
5
 
6
6
  describe ScriptsParser do
7
7
  describe "#parse" do
8
- it "parses content from file" do
9
- content = File.read('spec/support/big_script2.sh')
10
- #content = File.read('spec/support/test.conf')
8
+ it "parses content from file 1" do
9
+ content = File.read('spec/support/script1.sh')
10
+
11
+ parsed_content = subject.parse(content)
12
+
13
+ ap parsed_content
14
+ end
15
+
16
+ it "parses content from file 2" do
17
+ content = File.read('spec/support/script2.sh')
18
+
19
+ parsed_content = subject.parse(content)
20
+
21
+ ap parsed_content
22
+ end
23
+
24
+ it "parses content from file 3" do
25
+ content = File.read('spec/support/script3.sh')
26
+
27
+ parsed_content = subject.parse(content)
28
+
29
+ ap parsed_content
30
+ end
31
+
32
+ it "parses content from file 4" do
33
+ content = File.read('spec/support/script4.sh')
34
+
35
+ parsed_content = subject.parse(content)
36
+
37
+ ap parsed_content
38
+ end
39
+
40
+ it "parses content from file 5" do
41
+ content = File.read('spec/support/script5.sh')
11
42
 
12
43
  parsed_content = subject.parse(content)
13
44
 
@@ -13,4 +13,4 @@
13
13
  "ruby_version": "2.2.3",
14
14
  "gemset": "acceptance_demo"
15
15
  }
16
- }
16
+ }
File without changes
File without changes
@@ -0,0 +1,24 @@
1
+
2
+ [gen_key]
3
+
4
+ echo "Generating ssh key..."
5
+
6
+ cd ~/.ssh
7
+ ssh-keygen
8
+
9
+ [cp_key1]
10
+
11
+ echo "Copying public key to remote server..."
12
+
13
+ echo <%= user %>
14
+ echo <%= host %>
15
+
16
+ scp ~/.ssh/id_rsa.pub <%= user %>@<%= host %>:~/pubkey.txt
17
+
18
+ [cp_key2]
19
+
20
+ mkdir -p ~/.ssh
21
+ chmod 700 .ssh
22
+ cat pubkey.txt >> ~/.ssh/authorized_keys
23
+ rm ~/pubkey.txt
24
+ chmod 600 ~/.ssh/*
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script_executor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
@@ -172,10 +172,11 @@ files:
172
172
  - spec/scripts_parser_spec.rb
173
173
  - spec/spec_helper.rb
174
174
  - spec/support/base.conf.json
175
- - spec/support/big_script.sh
176
- - spec/support/big_script2.sh
177
- - spec/support/test.conf
178
- - spec/support/test2.conf
175
+ - spec/support/script1.sh
176
+ - spec/support/script2.sh
177
+ - spec/support/script3.sh
178
+ - spec/support/script4.sh
179
+ - spec/support/script5.sh
179
180
  homepage: http://github.com/shvets/script_executor
180
181
  licenses:
181
182
  - MIT
@@ -207,7 +208,8 @@ test_files:
207
208
  - spec/scripts_parser_spec.rb
208
209
  - spec/spec_helper.rb
209
210
  - spec/support/base.conf.json
210
- - spec/support/big_script.sh
211
- - spec/support/big_script2.sh
212
- - spec/support/test.conf
213
- - spec/support/test2.conf
211
+ - spec/support/script1.sh
212
+ - spec/support/script2.sh
213
+ - spec/support/script3.sh
214
+ - spec/support/script4.sh
215
+ - spec/support/script5.sh