vop 0.3.1 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile +2 -1
  4. data/Gemfile.lock +34 -33
  5. data/README.md +184 -2
  6. data/bin/console +17 -0
  7. data/bin/setup +8 -0
  8. data/bin/vop.sh +6 -2
  9. data/exe/vop +3 -25
  10. data/lib/boot.rb +3 -0
  11. data/lib/core/meta/commands/new_command.rb +1 -0
  12. data/lib/core/meta/commands/new_plugin.rb +47 -0
  13. data/lib/core/meta/commands/search_gems_for_plugins.rb +38 -0
  14. data/lib/core/meta/commands/search_path.rb +6 -0
  15. data/lib/core/meta/commands/set.rb +12 -0
  16. data/lib/core/meta/commands/show.rb +6 -0
  17. data/lib/core/meta/commands/show_config.rb +9 -0
  18. data/lib/core/meta/commands/who_provides.rb +6 -0
  19. data/lib/core/meta/meta.plugin +1 -0
  20. data/lib/core/shell/commands/change_loglevel.rb +6 -0
  21. data/lib/{vop/plugins/core → core/shell}/commands/clear_context.rb +0 -0
  22. data/lib/core/shell/commands/edit.rb +12 -0
  23. data/lib/core/shell/commands/help.rb +49 -0
  24. data/lib/core/shell/commands/reset.rb +4 -0
  25. data/lib/{vop/plugins/core → core/shell}/commands/show_context.rb +0 -0
  26. data/lib/core/shell/commands/source.rb +21 -0
  27. data/lib/{vop/plugins/core/helpers/plugin_loader/plugin_syntax.rb → core/shell/shell.plugin} +0 -0
  28. data/lib/core/structure/commands/collect_contributions.rb +46 -0
  29. data/lib/core/structure/commands/disable_contributor.rb +16 -0
  30. data/lib/core/structure/commands/generate_entity_commands.rb +52 -0
  31. data/lib/core/structure/commands/generate_invalidation_commands.rb +26 -0
  32. data/lib/core/structure/commands/list_commands.rb +11 -0
  33. data/lib/core/structure/commands/list_contributors.rb +10 -0
  34. data/lib/core/structure/commands/list_entities.rb +3 -0
  35. data/lib/core/structure/commands/list_plugins.rb +3 -0
  36. data/lib/core/structure/commands/register_contributor.rb +14 -0
  37. data/lib/core/structure/structure.plugin +4 -0
  38. data/lib/vop/objects/chain.rb +25 -0
  39. data/lib/vop/objects/command.rb +86 -0
  40. data/lib/vop/objects/command_param.rb +39 -0
  41. data/lib/vop/objects/entities.rb +21 -0
  42. data/lib/vop/objects/entity.rb +75 -0
  43. data/lib/vop/objects/entity_definition.rb +33 -0
  44. data/lib/vop/objects/filter.rb +48 -0
  45. data/lib/vop/objects/plugin.rb +208 -0
  46. data/lib/vop/objects/request.rb +73 -0
  47. data/lib/vop/objects/response.rb +17 -0
  48. data/lib/vop/objects/thing_with_params.rb +17 -0
  49. data/lib/vop/{command_loader.rb → parts/command_loader.rb} +8 -12
  50. data/lib/vop/parts/dependency_resolver.rb +56 -0
  51. data/lib/vop/parts/entity_loader.rb +46 -0
  52. data/lib/vop/parts/executor.rb +155 -0
  53. data/lib/vop/parts/filter_loader.rb +41 -0
  54. data/lib/vop/parts/plugin_finder.rb +46 -0
  55. data/lib/vop/parts/plugin_loader.rb +72 -0
  56. data/lib/vop/shell/shell.rb +221 -0
  57. data/lib/vop/shell/shell_formatter.rb +110 -0
  58. data/lib/vop/shell/shell_input.rb +14 -0
  59. data/lib/vop/shell/shell_input_readline.rb +20 -0
  60. data/lib/vop/shell/shell_input_testable.rb +27 -0
  61. data/lib/vop/syntax/command_syntax.rb +90 -0
  62. data/lib/vop/syntax/entity_syntax.rb +35 -0
  63. data/lib/vop/syntax/filter_syntax.rb +11 -0
  64. data/lib/vop/syntax/plugin_syntax.rb +55 -0
  65. data/lib/vop/util/errors.rb +45 -0
  66. data/lib/vop/util/pluralizer.rb +26 -0
  67. data/lib/vop/util/worker.rb +24 -0
  68. data/lib/vop/version.rb +1 -1
  69. data/lib/vop/vop.rb +216 -0
  70. data/lib/vop.rb +16 -229
  71. data/vop.gemspec +18 -15
  72. metadata +95 -63
  73. data/bin/vop.rb +0 -28
  74. data/lib/vop/command.rb +0 -168
  75. data/lib/vop/entity.rb +0 -61
  76. data/lib/vop/loader.rb +0 -35
  77. data/lib/vop/plugin.rb +0 -141
  78. data/lib/vop/plugin_loader.rb +0 -88
  79. data/lib/vop/plugins/core/commands/collect_contributions.rb +0 -31
  80. data/lib/vop/plugins/core/commands/edit.rb +0 -12
  81. data/lib/vop/plugins/core/commands/help.rb +0 -38
  82. data/lib/vop/plugins/core/commands/identity.rb +0 -4
  83. data/lib/vop/plugins/core/commands/list_contributors.rb +0 -8
  84. data/lib/vop/plugins/core/commands/list_entities.rb +0 -3
  85. data/lib/vop/plugins/core/commands/pry.rb +0 -9
  86. data/lib/vop/plugins/core/commands/reset.rb +0 -5
  87. data/lib/vop/plugins/core/commands/source.rb +0 -5
  88. data/lib/vop/plugins/core/commands/system_call.rb +0 -5
  89. data/lib/vop/plugins/core/core.plugin +0 -4
  90. data/lib/vop/plugins/core/helpers/command_loader/command_syntax.rb +0 -45
  91. data/lib/vop/plugins/core/helpers/command_loader/contributions.rb +0 -28
  92. data/lib/vop/plugins/core/helpers/command_loader/entities.rb +0 -57
  93. data/lib/vop/plugins/core/helpers/helper.rb +0 -3
  94. data/lib/vop/plugins/meta/commands/add_search_path.rb +0 -6
  95. data/lib/vop/plugins/meta/commands/delete_plugin.rb +0 -13
  96. data/lib/vop/plugins/meta/commands/list_commands.rb +0 -17
  97. data/lib/vop/plugins/meta/commands/list_plugins.rb +0 -8
  98. data/lib/vop/plugins/meta/commands/new_command.rb +0 -14
  99. data/lib/vop/plugins/meta/commands/new_plugin.rb +0 -25
  100. data/lib/vop/plugins/meta/commands/show_search_path.rb +0 -3
  101. data/lib/vop/plugins/meta/commands/who_provides.rb +0 -5
  102. data/lib/vop/plugins/meta/meta.plugin +0 -1
  103. data/lib/vop/plugins/ssh/commands/scp.rb +0 -11
  104. data/lib/vop/plugins/ssh/commands/ssh.rb +0 -19
  105. data/lib/vop/plugins/ssh/ssh.plugin +0 -1
  106. data/lib/vop/shell/backend.rb +0 -28
  107. data/lib/vop/shell/base_shell.rb +0 -112
  108. data/lib/vop/shell/formatter.rb +0 -46
  109. data/lib/vop/shell/vop_shell_backend.rb +0 -257
  110. data/lib/vop/shell.rb +0 -52
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp T.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: terminal-table
14
+ name: net-ssh
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: net-ssh
28
+ name: net-scp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: net-scp
42
+ name: redis
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: docopt
56
+ name: sidekiq
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: activesupport
70
+ name: terminal-table
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: xml-simple
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -100,30 +100,44 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.10'
103
+ version: '1.15'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.10'
110
+ version: '1.15'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '10.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '10.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - ">="
@@ -136,11 +150,10 @@ dependencies:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
- description: 'Automated processes fail more consistently, that''s why I wrote a tool
140
- to make scripts that will do things that we won''t have to do ourselves then. (see
141
- xkcd #1629)'
153
+ description: Automation framework with a plugin/command architecture, entities, contributions,
154
+ filters and asynchronous workers. Shell included, web interface in a separate project.
142
155
  email:
143
- - philipp@virtualop.org
156
+ - philipp@hitchhackers.net
144
157
  executables:
145
158
  - vop
146
159
  extensions: []
@@ -151,54 +164,73 @@ files:
151
164
  - Gemfile.lock
152
165
  - README.md
153
166
  - Rakefile
154
- - bin/vop.rb
167
+ - bin/console
168
+ - bin/setup
155
169
  - bin/vop.sh
156
170
  - exe/vop
171
+ - lib/boot.rb
172
+ - lib/core/meta/commands/new_command.rb
173
+ - lib/core/meta/commands/new_plugin.rb
174
+ - lib/core/meta/commands/search_gems_for_plugins.rb
175
+ - lib/core/meta/commands/search_path.rb
176
+ - lib/core/meta/commands/set.rb
177
+ - lib/core/meta/commands/show.rb
178
+ - lib/core/meta/commands/show_config.rb
179
+ - lib/core/meta/commands/who_provides.rb
180
+ - lib/core/meta/meta.plugin
181
+ - lib/core/shell/commands/change_loglevel.rb
182
+ - lib/core/shell/commands/clear_context.rb
183
+ - lib/core/shell/commands/edit.rb
184
+ - lib/core/shell/commands/help.rb
185
+ - lib/core/shell/commands/reset.rb
186
+ - lib/core/shell/commands/show_context.rb
187
+ - lib/core/shell/commands/source.rb
188
+ - lib/core/shell/shell.plugin
189
+ - lib/core/structure/commands/collect_contributions.rb
190
+ - lib/core/structure/commands/disable_contributor.rb
191
+ - lib/core/structure/commands/generate_entity_commands.rb
192
+ - lib/core/structure/commands/generate_invalidation_commands.rb
193
+ - lib/core/structure/commands/list_commands.rb
194
+ - lib/core/structure/commands/list_contributors.rb
195
+ - lib/core/structure/commands/list_entities.rb
196
+ - lib/core/structure/commands/list_plugins.rb
197
+ - lib/core/structure/commands/register_contributor.rb
198
+ - lib/core/structure/structure.plugin
157
199
  - lib/vop.rb
158
- - lib/vop/command.rb
159
- - lib/vop/command_loader.rb
160
- - lib/vop/entity.rb
161
- - lib/vop/loader.rb
162
- - lib/vop/plugin.rb
163
- - lib/vop/plugin_loader.rb
164
- - lib/vop/plugins/core/commands/clear_context.rb
165
- - lib/vop/plugins/core/commands/collect_contributions.rb
166
- - lib/vop/plugins/core/commands/edit.rb
167
- - lib/vop/plugins/core/commands/help.rb
168
- - lib/vop/plugins/core/commands/identity.rb
169
- - lib/vop/plugins/core/commands/list_contributors.rb
170
- - lib/vop/plugins/core/commands/list_entities.rb
171
- - lib/vop/plugins/core/commands/pry.rb
172
- - lib/vop/plugins/core/commands/reset.rb
173
- - lib/vop/plugins/core/commands/show_context.rb
174
- - lib/vop/plugins/core/commands/source.rb
175
- - lib/vop/plugins/core/commands/system_call.rb
176
- - lib/vop/plugins/core/core.plugin
177
- - lib/vop/plugins/core/helpers/command_loader/command_syntax.rb
178
- - lib/vop/plugins/core/helpers/command_loader/contributions.rb
179
- - lib/vop/plugins/core/helpers/command_loader/entities.rb
180
- - lib/vop/plugins/core/helpers/helper.rb
181
- - lib/vop/plugins/core/helpers/plugin_loader/plugin_syntax.rb
182
- - lib/vop/plugins/meta/commands/add_search_path.rb
183
- - lib/vop/plugins/meta/commands/delete_plugin.rb
184
- - lib/vop/plugins/meta/commands/list_commands.rb
185
- - lib/vop/plugins/meta/commands/list_plugins.rb
186
- - lib/vop/plugins/meta/commands/new_command.rb
187
- - lib/vop/plugins/meta/commands/new_plugin.rb
188
- - lib/vop/plugins/meta/commands/show_search_path.rb
189
- - lib/vop/plugins/meta/commands/who_provides.rb
190
- - lib/vop/plugins/meta/meta.plugin
191
- - lib/vop/plugins/ssh/commands/scp.rb
192
- - lib/vop/plugins/ssh/commands/ssh.rb
193
- - lib/vop/plugins/ssh/ssh.plugin
194
- - lib/vop/shell.rb
195
- - lib/vop/shell/backend.rb
196
- - lib/vop/shell/base_shell.rb
197
- - lib/vop/shell/formatter.rb
198
- - lib/vop/shell/vop_shell_backend.rb
200
+ - lib/vop/objects/chain.rb
201
+ - lib/vop/objects/command.rb
202
+ - lib/vop/objects/command_param.rb
203
+ - lib/vop/objects/entities.rb
204
+ - lib/vop/objects/entity.rb
205
+ - lib/vop/objects/entity_definition.rb
206
+ - lib/vop/objects/filter.rb
207
+ - lib/vop/objects/plugin.rb
208
+ - lib/vop/objects/request.rb
209
+ - lib/vop/objects/response.rb
210
+ - lib/vop/objects/thing_with_params.rb
211
+ - lib/vop/parts/command_loader.rb
212
+ - lib/vop/parts/dependency_resolver.rb
213
+ - lib/vop/parts/entity_loader.rb
214
+ - lib/vop/parts/executor.rb
215
+ - lib/vop/parts/filter_loader.rb
216
+ - lib/vop/parts/plugin_finder.rb
217
+ - lib/vop/parts/plugin_loader.rb
218
+ - lib/vop/shell/shell.rb
219
+ - lib/vop/shell/shell_formatter.rb
220
+ - lib/vop/shell/shell_input.rb
221
+ - lib/vop/shell/shell_input_readline.rb
222
+ - lib/vop/shell/shell_input_testable.rb
223
+ - lib/vop/syntax/command_syntax.rb
224
+ - lib/vop/syntax/entity_syntax.rb
225
+ - lib/vop/syntax/filter_syntax.rb
226
+ - lib/vop/syntax/plugin_syntax.rb
227
+ - lib/vop/util/errors.rb
228
+ - lib/vop/util/pluralizer.rb
229
+ - lib/vop/util/worker.rb
199
230
  - lib/vop/version.rb
231
+ - lib/vop/vop.rb
200
232
  - vop.gemspec
201
- homepage: http://www.virtualop.org
233
+ homepage: http://virtualop.org
202
234
  licenses: []
203
235
  metadata: {}
204
236
  post_install_message:
@@ -217,8 +249,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
249
  version: '0'
218
250
  requirements: []
219
251
  rubyforge_project:
220
- rubygems_version: 2.5.1
252
+ rubygems_version: 2.5.2.1
221
253
  signing_key:
222
254
  specification_version: 4
223
- summary: The virtualop is a tool for automating things.
255
+ summary: The vop is a scripting framework.
224
256
  test_files: []
data/bin/vop.rb DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pathname'
4
-
5
- $: << File.join(Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath, 'lib')
6
-
7
- require 'vop/shell'
8
- require 'docopt'
9
- require 'pp'
10
-
11
- begin
12
- shell = Vop::Shell::setup()
13
- if shell.options["--execute"]
14
- last_response = shell.execute(shell.options["--execute"])
15
- else
16
- last_response = shell.run_cli
17
- end
18
-
19
- # TODO exit_status = last_response && last_response.status == Vop.Status::OK ? 0 : 1
20
- exit 0
21
- rescue => detail
22
- if detail.is_a? Docopt::Exit
23
- puts detail.message
24
- else
25
- $stderr.puts "error : #{detail.message}\n#{detail.backtrace[0..9].join("\n")}"
26
- exit 42
27
- end
28
- end
data/lib/vop/command.rb DELETED
@@ -1,168 +0,0 @@
1
- module Vop
2
-
3
- class Command
4
-
5
- attr_reader :name
6
- attr_reader :plugin
7
-
8
- attr_accessor :block
9
- attr_accessor :description
10
- attr_accessor :show_options
11
-
12
- attr_reader :params
13
-
14
- def initialize(plugin, name)
15
- @plugin = plugin
16
- @name = name
17
- @block = lambda { |params| $logger.warn "#{name} not yet implemented!" }
18
- @params = []
19
- @show_options = {}
20
- end
21
-
22
- def inspect
23
- "Vop::Command #{@name}"
24
- end
25
-
26
- def source
27
- @plugin.command_source(name)
28
- end
29
-
30
- def short_name
31
- name.split(".").last
32
- end
33
-
34
- def param(name)
35
- params.select { |param| param[:name] == name }.first || nil
36
- end
37
-
38
- # the default param is the one used when a command is called with a single "scalar" param only, like
39
- # @op.foo("zaphod")
40
- # if a parameter is marked as default, it will be assigned the value "zaphod" in this case.
41
- # if there's only a single param, it's the default param by default (ha!)
42
- def default_param
43
- if params.size == 1
44
- params.first
45
- else
46
- params.select { |param| param[:default_param] == true }.first || nil
47
- end
48
- end
49
-
50
- def mandatory_params
51
- params.select do |p|
52
- p[:mandatory]
53
- end
54
- end
55
-
56
- def lookup(param_name, params)
57
- p = param(param_name)
58
- raise "no such param : #{param_name} in command #{name}" unless p
59
-
60
- if p.has_key? :lookup
61
- p[:lookup].call(params)
62
- else
63
- $logger.debug "no lookups for #{param_name}"
64
- []
65
- end
66
- end
67
-
68
- # accepts arguments as handed in by :define_method and prepares them
69
- # into the +params+ structure expected by command blocks
70
- def prepare_params(ruby_args, extra = {})
71
- result = {}
72
- if ruby_args
73
- if ruby_args.is_a? Hash
74
- result = ruby_args
75
- ruby_args.each do |k,v|
76
- p = param(k)
77
- if p
78
- # values are auto-boxed into an array if the param expects multiple values
79
- if p[:multi] && ! v.is_a?(Array) then
80
- $logger.debug("autoboxing for #{p[:name]}")
81
- v = [ v ]
82
- # array values are auto-unboxed if the param doesn't want multi
83
- elsif ! p[:multi] && v.is_a?(Array) && v.length == 1
84
- $logger.debug("autounboxing for #{p[:name]}")
85
- v = v.first
86
- end
87
- end
88
- result[k] = v
89
- end
90
- else
91
- # if there's a default param, it can be passed as "scalar" param
92
- # (as opposed to the usual hash) to execute, but will be converted
93
- # into a "normal" named param
94
- dp = default_param
95
- if dp
96
- result = {dp[:name] => ruby_args}
97
- end
98
- end
99
- end
100
-
101
- if extra.keys.size > 0
102
- result.merge! extra
103
- end
104
-
105
- # add in defaults (for all params that have not been specified)
106
- params.each do |p|
107
- unless result.has_key? p[:name]
108
- if p[:default]
109
- result[p[:name]] = p[:default]
110
- end
111
- end
112
- end
113
-
114
- result
115
- end
116
-
117
- def execute(param_values, extra = {})
118
- prepared = prepare_params(param_values, extra)
119
-
120
- block_param_names = self.block.parameters.map { |x| x.last }
121
-
122
- #puts "executing #{self.name} : prepared : #{prepared.inspect}"
123
-
124
- payload = []
125
- context = {} # TODO should this be initialized?
126
-
127
- block_param_names.each do |name|
128
- param = nil
129
-
130
- case name.to_s
131
- when 'params'
132
- param = prepared
133
- when 'plugin'
134
- param = self.plugin
135
- when 'context'
136
- param = context
137
- when 'shell'
138
- raise "shell not supported" unless extra.has_key? 'shell'
139
- param = extra['shell']
140
- else
141
- if prepared.has_key? name.to_s
142
- param = prepared[name.to_s]
143
- elsif prepared.has_key? name
144
- param = prepared[name]
145
- else
146
- raise "unknown block param name : >>#{name}<<"
147
- end
148
- end
149
-
150
- # from the black magick department: block parameters with the
151
- # same name as an entity get auto-inflated
152
- if param
153
- entity_names = @plugin.op.core.state[:entities].map { |entity| entity[:name] }
154
- if entity_names.include? name.to_s
155
- resolved = @plugin.op.send(name, param)
156
- param = resolved
157
- end
158
- payload << param
159
- end
160
- end
161
-
162
- result = self.block.call(*payload)
163
- [result, context]
164
- end
165
-
166
- end
167
-
168
- end
data/lib/vop/entity.rb DELETED
@@ -1,61 +0,0 @@
1
- module Vop
2
-
3
- # An entity is something that is identifiable through a key, e.g. a name.
4
- # Also, it groups commands that accept the same parameter: When a command
5
- # is called on an entity, the parameter with the same name is filled, so
6
- # @op.machine("localhost").processes()
7
- # is equivalent to
8
- # @op.processes(machine: "localhost")
9
- class Entity
10
-
11
- def initialize(op, name, key, hash)
12
- @op = op
13
- @name = name
14
- @key = key
15
- @data = {}
16
- hash.each do |k,v|
17
- @data[k.to_s] = v
18
- end
19
-
20
- make_methods_for_hash_keys
21
- make_methods_for_commands
22
- end
23
-
24
- def inspect
25
- "Vop::Entity #{@name} (#{@command_count} commands)"
26
- end
27
-
28
- def make_methods_for_hash_keys
29
- @data.keys.each do |key|
30
- #next if ['name', 'key'].include? key.to_s
31
- next if ['key'].include? key.to_s
32
- self.class.send(:define_method, key) do |*args|
33
- ruby_args = args.length > 0 ? args[0] : {}
34
- @data[key]
35
- end
36
- end
37
- end
38
-
39
- def entity_commands
40
- result = @op.commands.values.select do |command|
41
- command.params.select do |param|
42
- param[:name] == @name
43
- end.count > 0
44
- end
45
- @command_count = result.count
46
- result
47
- end
48
-
49
- def make_methods_for_commands
50
- entity_commands.each do |command|
51
- value = @data[@key]
52
- self.class.send(:define_method, command.short_name) do |*args|
53
- ruby_args = args.length > 0 ? args[0] : {}
54
- @op.execute(command.short_name, ruby_args, { @name => value })
55
- end
56
- end
57
- end
58
-
59
- end
60
-
61
- end
data/lib/vop/loader.rb DELETED
@@ -1,35 +0,0 @@
1
- class Loader
2
-
3
- attr_reader :loaded
4
-
5
- def initialize(op, plugin)
6
- @op = op
7
- @plugin = plugin
8
- @loaded = []
9
-
10
- # TODO plugin.load_helper_classes(self) unless plugin == nil
11
- end
12
-
13
- def from_scratch(name)
14
- fresh = { "name" => name }
15
- @loaded << fresh
16
- end
17
-
18
- def self.read(op, plugin, name, source, file_name = nil)
19
- loader = new(op, plugin)
20
-
21
- loader.from_scratch(name)
22
- begin
23
- if file_name
24
- loader.instance_eval source, file_name
25
- else
26
- loader.instance_eval source
27
- end
28
- rescue => detail
29
- raise "could not read '#{name}' : #{detail.message}\n#{detail.backtrace[0..9].join("\n")}"
30
- end
31
-
32
- loader
33
- end
34
-
35
- end
data/lib/vop/plugin.rb DELETED
@@ -1,141 +0,0 @@
1
- require 'vop/command_loader'
2
-
3
- module Vop
4
-
5
- class Plugin
6
-
7
- attr_reader :op
8
- attr_reader :name
9
- attr_reader :path
10
-
11
- attr_reader :commands
12
- attr_reader :config
13
- attr_reader :dependencies
14
-
15
- attr_reader :state
16
-
17
- def initialize(op, plugin_name, plugin_path)
18
- @op = op
19
- @name = plugin_name
20
- @path = plugin_path
21
- @config = {}
22
- @dependencies = []
23
-
24
- # all plugins depend on 'core' (unless they are core or some murky dummy)
25
- independents = %w|core __root__|
26
- @dependencies << 'core' unless independents.include? plugin_name
27
-
28
- @state = {}
29
- @hooks = {}
30
-
31
- @sources = Hash.new { |h, k| h[k] = {} }
32
- end
33
-
34
- def inspect
35
- "Vop::Plugin #{@name}"
36
- end
37
-
38
- def hook(name, &block)
39
- @hooks[name.to_sym] = block
40
- end
41
-
42
- def call_hook(name, *args)
43
- if @hooks.has_key? name
44
- $logger.debug "plugin #{self.name} calling hook #{name}"
45
- @hooks[name].call(self, *args)
46
- end
47
- end
48
-
49
- def init
50
- $logger.debug "plugin init #{@name}"
51
- call_hook :preload
52
- load_helpers
53
- load_config
54
- # TODO we might want to activate/register only plugins with enough config
55
- call_hook :init
56
- load_commands
57
- call_hook :activate
58
- end
59
-
60
- def plugin_dir(name)
61
- @path + '/' + name.to_s
62
- end
63
-
64
- def load_code_from_dir(type_name)
65
- dir = plugin_dir type_name
66
- if File.exists?(dir)
67
- Dir.glob(File.join(dir, '*.rb')).each do |file_name|
68
- name_from_file = /#{dir}\/(.+).rb$/.match(file_name).captures.first
69
- full_name = @name + '.' + name_from_file
70
- $logger.debug(" #{type_name} << #{full_name}")
71
-
72
- code = File.read(file_name)
73
- @sources[type_name][full_name] = {
74
- :file_name => file_name,
75
- :code => code
76
- }
77
- end
78
- else
79
- #$logger.debug "no #{type_name} dir found - checked for #{dir}"
80
- end
81
- end
82
-
83
- def load_helpers
84
- load_code_from_dir 'helpers'
85
- load_code_from_dir 'helpers/command_loader'
86
- load_code_from_dir 'helpers/plugin_loader'
87
- end
88
-
89
- def helper_sources(type_name = 'helpers')
90
- @sources[type_name].map do |name, source|
91
- source[:code]
92
- end
93
- end
94
-
95
- def command_source(command_name)
96
- @sources[:commands][command_name]
97
- end
98
-
99
- def inject_helpers(target, sub_type_name = nil)
100
- type_name = 'helpers'
101
- if sub_type_name
102
- type_name += '/' + sub_type_name
103
- end
104
-
105
- plugins_to_load_helpers_from = [ self ]
106
-
107
- self.dependencies.each do |name|
108
- other = @op.plugins[name]
109
- raise "can not resolve plugin dependency #{name}" unless other
110
- plugins_to_load_helpers_from << other
111
- end
112
-
113
- plugins_to_load_helpers_from.each do |other_plugin|
114
- next if other_plugin.helper_sources(type_name).size == 0
115
- #$logger.debug "loading helper from #{other_plugin.name} into #{target} : #{other_plugin.helper_sources.size}"
116
-
117
- helper_module = Module.new()
118
- other_plugin.helper_sources(type_name).each do |source|
119
- helper_module.class_eval source
120
- end
121
- target.extend helper_module
122
- end
123
- end
124
-
125
- def load_commands
126
- load_code_from_dir :commands
127
-
128
- loader = CommandLoader.new(self)
129
- @commands = loader.read_sources @sources[:commands]
130
- @commands.each do |name, command|
131
- # TODO might want to warn/debug about overrides here
132
- @op.eat(command)
133
- end
134
- end
135
-
136
- def load_config
137
- end
138
-
139
- end
140
-
141
- end