mdt-simple 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4e78e6ddc552236caaff39e45a695acaee2ad682ba422a380104494865f9c67
4
+ data.tar.gz: 5f61316be089655e08c25353a03314547f94a718baf058d6c63763d2c093c0c3
5
+ SHA512:
6
+ metadata.gz: cd13c303849453679616a4c24b65857c217e92cba17ff79e9caf429478ed47d0adb07b5707d5398fb1d5d17379ff894d21ac9babd7d61d97995a0b7557ec594f
7
+ data.tar.gz: 796baf435a671a735cdd8e13d15c0113ad765e4ba2b4a4c2427b089cbc2e86ee40280d1bdc45477bdde7eb0586b1dcfb56fe9d5b24fdecdcc38aa5b374e1b080
@@ -0,0 +1,90 @@
1
+ # MDT - Simple module
2
+
3
+ A module with simple implementations for MDT.
4
+
5
+ ## Requirements
6
+
7
+ * [mdt-core](https://github.com/Phitherek/mdt-core "mdt-core") >= 0.0.1
8
+ * Ruby (tested with 2.5.0, earlier versions down to 2.0 may also work)
9
+ * RubyGems
10
+
11
+ ## Installation
12
+
13
+ `gem install mdt-dummy`
14
+
15
+ ## Usage
16
+
17
+ The module is automatically loaded by `mdt`. All you need to do is to use appropriate keys in your `mdt-deploy.yml`.
18
+
19
+ ## Objects defined by module
20
+
21
+ ### Command modifiers
22
+
23
+ * `simple.env` - prepends an environment variable to the command.
24
+ Options:
25
+ * `name` - name of the variable
26
+ * `value` - value of the variable
27
+ * `simple.sudo` - prepends sudo to the command.
28
+ Options:
29
+ * `args` - arguments with options for sudo (optional)
30
+ * `simple.generic` - prepends given string to the command.
31
+ Options:
32
+ * `modifier_str` - string to prepend to the command
33
+ ### Commands
34
+
35
+ * `simple.shell` - runs a command in a shell applying the command modifiers. Options:
36
+ * `shell` - the shell executable (optional, default: `/bin/bash`)
37
+ * `args` - arguments with options for the shell (optional)
38
+ * `command` - command to execute in the shell
39
+ * `simple.system` - runs a command applying the command modifiers. Options:
40
+ * `command_string` - command to execute
41
+ * `simple.mkdir` - creates a directory. Options:
42
+ * `path` - a path of a directory to be created
43
+ * `parents` - truthy if non-exising parents of the directory should be created too, falsey otherwise (empty also means falsey)
44
+ * `simple.cd` - changes the working directory. Options:
45
+ * `path` - a path of the new working directory
46
+ * `simple.cp` - copies files and directories from source to destination. Options:
47
+ * `source_path` - a path specifying the elements to be copied
48
+ * `destination_path` - a path specifying where the elements should be copied
49
+ * `recursive` - truthy if directories should be copied recursively, falsey otherwise (empty also means falsey)
50
+ * `simple.mv` - moves files and directories from source to destination. Options:
51
+ * `source_path` - a path specifying the elements to be moved
52
+ * `destination_path` - a path specifying where the elements should be moved
53
+ * `simple.rm` - removes files and directories. Options:
54
+ * `path` - a path specifying the elements to be removed
55
+ * `recursive` - truthy if directories should be removed recursively, falsey otherwise (empty also means falsey)
56
+ * `force` - truthy if the removal should be forced, falsey otherwise (empty also means falsey)
57
+ * `simple.ln` - creates links. Options:
58
+ * `destination_path` - a path specifying what should be the destination of the link
59
+ * `link_name` - a path being the name of the link
60
+ * `symbolic` - truthy if the link should be symbolic, falsey otherwise (empty also means falsey)
61
+ * `force` - truthy if creation of the link should be forced, falsey otherwise (empty also means falsey)
62
+ * `simple.chmod` - changes mode of files and directories. Options:
63
+ * `mode` - a mode to set
64
+ * `destination_path` - a path specifying where the mode should be changed
65
+ * `recursive` - truthy if the mode should be changed recursively, falsey otherwise (empty also means falsey)
66
+ * `simple.chown` - changes owner of files and directories. Options:
67
+ * `user` - the user which should be the owner
68
+ * `group` - the group which should be the owner
69
+ * `destination_path` - a path specifying where the owner should be changed
70
+ * `recursive` - truthy if the owner should be changed recursively, falsey otherwise (empty also means falsey)
71
+ * `simple.touch` - creates a file or updates its modification date. Options:
72
+ * `path` - a path specifying the file that should be touched
73
+
74
+ ### Directory choosers
75
+
76
+ * `simple.directory` - uses a simple directory path. Creates and changes to the directory. Does not remove the directory on failure. Options:
77
+ * `path` - a path to the deploy directory
78
+
79
+ ### Fetchers
80
+
81
+ * `simple.directory` - uses a local directory. Options:
82
+ * `path` - a path to the source directory
83
+
84
+ ## Contributing
85
+
86
+ You can contribute to the development of this MDT module by submitting an issue or pull request.
87
+
88
+ ## Documentation
89
+
90
+ Generated RDoc documentation can be found [here](https://rubydoc.info/github/Phitherek/mdt-simple "here").
@@ -0,0 +1,5 @@
1
+ require_relative 'mdt/version'
2
+ require_relative 'mdt/directory_choosers'
3
+ require_relative 'mdt/fetchers'
4
+ require_relative 'mdt/command_modifiers'
5
+ require_relative 'mdt/commands'
@@ -0,0 +1 @@
1
+ require_relative 'command_modifiers/simple'
@@ -0,0 +1,50 @@
1
+ require 'mdt-core'
2
+ module MDT
3
+ # A module containing all command modifiers
4
+ module CommandModifiers
5
+ # A class that implements simple command modifiers
6
+ class Simple < MDT::CommandModifiers::Base
7
+ # A method that defines a key for command modifiers class.
8
+ # Returns:
9
+ # * "simple"
10
+ def self.key
11
+ 'simple'
12
+ end
13
+
14
+ # A method that defines keys for available command modifiers.
15
+ # Returns:
16
+ # * +["env", "sudo", "generic"]+
17
+ def self.subkeys
18
+ ['env', 'sudo', 'generic']
19
+ end
20
+
21
+ # A method that defines how to prepend command modifiers to commands.
22
+ # Arguments:
23
+ # * +key+ - a key identifier of a particular command modifier
24
+ # * +command+ - a command to apply command modifier on
25
+ # * +options+ - options for modifier as a Hash
26
+ # Returns:
27
+ # * A value of +command+ modified with +key+ command modifier
28
+ # More information:
29
+ # * See README.md for detailed description of command modifiers
30
+ def prepend(key, command, options = {})
31
+ case key
32
+ when 'env'
33
+ if options['name'] && options['value']
34
+ "#{options['name']}=#{options['value']} #{command}"
35
+ else
36
+ command
37
+ end
38
+ when 'sudo'
39
+ "sudo #{options['args']} #{command}"
40
+ when 'generic'
41
+ if options['modifier_str']
42
+ "#{options['modifier_str']} #{command}"
43
+ else
44
+ command
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1 @@
1
+ require_relative 'commands/simple'
@@ -0,0 +1,230 @@
1
+ require 'mdt-core'
2
+ require 'fileutils'
3
+ require 'open3'
4
+ module MDT
5
+ # A module containing all commands
6
+ module Commands
7
+ # A class that implements simple commands
8
+ class Simple < MDT::Commands::Base
9
+ # A method that defines a key for commands class.
10
+ # Returns:
11
+ # * "simple"
12
+ def self.key
13
+ 'simple'
14
+ end
15
+
16
+ # A method that defines keys for available commands.
17
+ # Returns:
18
+ # * +["shell", "system", "mkdir", "cd", "cp", "mv", "rm", "ln", "chmod", "chown", "touch"]+
19
+ def self.subkeys
20
+ ['shell', 'system', 'mkdir', 'cd', 'cp', 'mv', 'rm', 'ln', 'chmod', 'chown', 'touch']
21
+ end
22
+
23
+ # A method that defines how to execute a command and how to apply command modifiers.
24
+ # Arguments:
25
+ # * +key+ - a key identifier of a particular command
26
+ # * +modifiers+ - an array of command modifier configurations - each configuration is a Hash that includes modifier type and modifier options
27
+ # * +options+ - options for command as a Hash
28
+ # Returns:
29
+ # * Exit code of command +key+
30
+ # More information:
31
+ # * See README.md for detailed description of commands
32
+ def execute(key, modifiers = [], options = {})
33
+ case key
34
+ when 'shell'
35
+ if options['command']
36
+ options['shell'] ||= '/bin/bash'
37
+ cmd = MDT::Helpers::Command.apply_command_modifiers(options['command'], modifiers)
38
+ puts "Running shell command: #{options['shell']} #{options['args']} -c \"#{cmd}\""
39
+ (cmd_stdout, cmd_stderr, status) = Open3.popen3("#{options['shell']} #{options['args']} -c \"#{cmd}\"") do |stdin, stdout, stderr, wait_thr|
40
+ exit_status = wait_thr.value
41
+ cmd_stdout = stdout.read
42
+ cmd_stderr = stderr.read
43
+ [cmd_stdout, cmd_stderr, exit_status]
44
+ end
45
+ puts
46
+ puts 'STDOUT:'
47
+ puts cmd_stdout
48
+ puts
49
+ puts 'STDERR:'
50
+ puts cmd_stderr
51
+ puts
52
+ status.exitstatus
53
+ else
54
+ 1
55
+ end
56
+ when 'system'
57
+ if options['command_string']
58
+ cmd = MDT::Helpers::Command.apply_command_modifiers(options['command_string'], modifiers)
59
+ puts "Running command: #{cmd}"
60
+ (cmd_stdout, cmd_stderr, status) = Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
61
+ exit_status = wait_thr.value
62
+ cmd_stdout = stdout.read
63
+ cmd_stderr = stderr.read
64
+ [cmd_stdout, cmd_stderr, exit_status]
65
+ end
66
+ puts
67
+ puts 'STDOUT:'
68
+ puts cmd_stdout
69
+ puts
70
+ puts 'STDERR:'
71
+ puts cmd_stderr
72
+ puts
73
+ status.exitstatus
74
+ else
75
+ 1
76
+ end
77
+ when 'mkdir'
78
+ if options['path']
79
+ begin
80
+ if options['parents']
81
+ puts "Creating directory with parents: #{options['path']}"
82
+ FileUtils.mkdir_p(Dir[options['path']].first)
83
+ else
84
+ puts "Creating directory: #{options['path']}"
85
+ FileUtils.mkdir(Dir[options['path']].first)
86
+ end
87
+ 0
88
+ rescue
89
+ 1
90
+ end
91
+ else
92
+ 1
93
+ end
94
+ when 'cd'
95
+ if options['path']
96
+ begin
97
+ puts "Changing working directory to: #{options['path']}"
98
+ FileUtils.cd(Dir[options['path']].first)
99
+ 0
100
+ rescue
101
+ 1
102
+ end
103
+ else
104
+ 1
105
+ end
106
+ when 'cp'
107
+ if options['source_path'] && options['destination_path']
108
+ begin
109
+ if options['recursive']
110
+ puts "Copying recursively from: #{options['source_path']} to: #{options['destination_path']}"
111
+ FileUtils.cp_r(Dir[options['source_path']], Dir[options['destination_path']].first)
112
+ else
113
+ puts "Copying from: #{options['source_path']} to: #{options['destination_path']}"
114
+ FileUtils.cp(Dir[options['source_path']], Dir[options['destination_path']].first)
115
+ end
116
+ 0
117
+ rescue
118
+ 1
119
+ end
120
+ else
121
+ 1
122
+ end
123
+ when 'mv'
124
+ if options['source_path'] && options['destination_path']
125
+ begin
126
+ puts "Moving from: #{options['source_path']} to: #{options['destination_path']}"
127
+ FileUtils.mv(Dir[options['source_path']], Dir[options['destination_path']].first)
128
+ rescue
129
+ 1
130
+ end
131
+ else
132
+ 1
133
+ end
134
+ when 'rm'
135
+ if options['path']
136
+ begin
137
+ if options['recursive'] && options['force']
138
+ puts "Removing recursively with force: #{options['path']}"
139
+ FileUtils.rm_rf(Dir[options['path']])
140
+ elsif options['recursive']
141
+ puts "Removing recursively: #{options['path']}"
142
+ FileUtils.rm_r(Dir[options['path']])
143
+ elsif options['force']
144
+ puts "Removing with force: #{options['path']}"
145
+ FileUtils.rm_f(Dir[options['path']])
146
+ else
147
+ puts "Removing: #{options['path']}"
148
+ FileUtils.rm(Dir[options['path']])
149
+ end
150
+ 0
151
+ rescue
152
+ 1
153
+ end
154
+ else
155
+ 1
156
+ end
157
+ when 'ln'
158
+ if options['destination_path'] && options['link_name']
159
+ begin
160
+ if options['symbolic'] && options['force']
161
+ puts "Creating a symbolic link with force to: #{options['destination_path']} named: #{options['link_name']}"
162
+ FileUtils.ln_sf(Dir[options['destination_path']].first, Dir[options['link_name']].first)
163
+ elsif options['symbolic']
164
+ puts "Creating a symbolic link to: #{options['destination_path']} named: #{options['link_name']}"
165
+ FileUtils.ln_s(Dir[options['destination_path']].first, Dir[options['link_name']].first)
166
+ elsif options['force']
167
+ puts "Creating a link with force to: #{options['destination_path']} named: #{options['link_name']}"
168
+ FileUtils.ln_f(Dir[options['destination_path']].first, Dir[options['link_name']].first)
169
+ else
170
+ puts "Creating a link to: #{options['destination_path']} named: #{options['link_name']}"
171
+ FileUtils.ln(Dir[options['destination_path']].first, Dir[options['link_name']].first)
172
+ end
173
+ 0
174
+ rescue
175
+ 1
176
+ end
177
+ else
178
+ 1
179
+ end
180
+ when 'chmod'
181
+ if options['mode'] && options['destination_path']
182
+ begin
183
+ if options['recursive']
184
+ puts "Changing mode recursively to: #{options['mode']} of: #{options['destination_path']}"
185
+ FileUtils.chmod_R(options['mode'], Dir[options['destination_path']])
186
+ else
187
+ puts "Changing mode to: #{options['mode']} of: #{options['destination_path']}"
188
+ FileUtils.chmod(options['mode'], Dir[options['destination_path']])
189
+ end
190
+ rescue
191
+ 1
192
+ end
193
+ 0
194
+ else
195
+ 1
196
+ end
197
+ when 'chown'
198
+ if options['user'] && options['group'] && options['destination_path']
199
+ begin
200
+ if options['recursive']
201
+ puts "Changing owner recursively to: #{options['user']}:#{options['group']} of: #{options['destination_path']}"
202
+ FileUtils.chown_R(options['user'], options['group'], Dir[options['destination_path']])
203
+ else
204
+ puts "Changing owner to: #{options['user']}:#{options['group']} of: #{options['destination_path']}"
205
+ FileUtils.chown(options['user'], options['group'], Dir[options['destination_path']])
206
+ end
207
+ 0
208
+ rescue
209
+ 1
210
+ end
211
+ else
212
+ 1
213
+ end
214
+ when 'touch'
215
+ if options['path']
216
+ begin
217
+ puts "Touching: #{options['path']}"
218
+ FileUtils.touch(Dir[options['path']])
219
+ 0
220
+ rescue
221
+ 1
222
+ end
223
+ else
224
+ 1
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
230
+ end
@@ -0,0 +1 @@
1
+ require_relative 'directory_choosers/simple'
@@ -0,0 +1,88 @@
1
+ require 'mdt-core'
2
+ require 'fileutils'
3
+ module MDT
4
+ # A module containing all directory choosers
5
+ module DirectoryChoosers
6
+ # A class that implements simple directory choosers
7
+ class Simple < MDT::DirectoryChoosers::Base
8
+ # A method that defines a key for directory choosers class.
9
+ # Returns:
10
+ # * "simple"
11
+ def self.key
12
+ 'simple'
13
+ end
14
+
15
+ # A method that defines keys for available directory choosers.
16
+ # Returns:
17
+ # * +["directory"]+
18
+ def self.subkeys
19
+ ['directory']
20
+ end
21
+
22
+ # A method that defines how to create a deploy directory with directory choosers.
23
+ # Arguments:
24
+ # * +key+ - a key identifier of a particular directory chooser
25
+ # * +options+ - options for directory chooser as a Hash
26
+ # Returns:
27
+ # * Exit code for directory chooser +key+
28
+ # More information:
29
+ # * See README.md for detailed description of directory choosers
30
+ def mkdir(key, options = {})
31
+ case key
32
+ when 'directory'
33
+ if options['path']
34
+ begin
35
+ puts "Creating directory: #{options['path']}"
36
+ FileUtils.mkdir_p(Dir[options['path']].first)
37
+ 0
38
+ rescue
39
+ 1
40
+ end
41
+ else
42
+ 1
43
+ end
44
+ end
45
+ end
46
+
47
+ # A method that defines how to change working directory to a deploy directory with directory choosers.
48
+ # Arguments:
49
+ # * +key+ - a key identifier of a particular directory chooser
50
+ # * +options+ - options for directory chooser as a Hash
51
+ # Returns:
52
+ # * Exit code for directory chooser +key+
53
+ # More information:
54
+ # * See README.md for detailed description of directory choosers
55
+ def cd(key, options = {})
56
+ case key
57
+ when 'directory'
58
+ if options['path']
59
+ begin
60
+ puts "Changing working directory to: #{options['path']}"
61
+ FileUtils.cd(Dir[options['path']].first)
62
+ 0
63
+ rescue
64
+ 1
65
+ end
66
+ else
67
+ 1
68
+ end
69
+ end
70
+ end
71
+
72
+ # A method that defines how to remove a deploy directory with directory choosers.
73
+ # Arguments:
74
+ # * +key+ - a key identifier of a particular directory chooser
75
+ # * +options+ - options for directory chooser as a Hash
76
+ # Returns:
77
+ # * Exit code for directory chooser +key+
78
+ # More information:
79
+ # * See README.md for detailed description of directory choosers
80
+ def rm(key, options = {})
81
+ case key
82
+ when 'directory'
83
+ 0
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1 @@
1
+ require_relative 'fetchers/simple'
@@ -0,0 +1,48 @@
1
+ require 'mdt-core'
2
+ require 'fileutils'
3
+ module MDT
4
+ # A module containing all fetchers
5
+ module Fetchers
6
+ # A class that implements dummy fetchers
7
+ class Simple < MDT::Fetchers::Base
8
+ # A method that defines a key for fetchers class.
9
+ # Returns:
10
+ # * "simple"
11
+ def self.key
12
+ 'simple'
13
+ end
14
+
15
+ # A method that defines keys for available fetchers.
16
+ # Returns:
17
+ # * +["directory"]+
18
+ def self.subkeys
19
+ ['directory']
20
+ end
21
+
22
+ # A method that defines how to fetch project contents to a deploy directory with fetchers.
23
+ # Arguments:
24
+ # * +key+ - a key identifier of a particular fetcher
25
+ # * +options+ - options for fetchers as a Hash
26
+ # Returns:
27
+ # * Exit code for fetcher +key+
28
+ # More information:
29
+ # * See README.md for detailed description of fetchers
30
+ def fetch(key, options = {})
31
+ case key
32
+ when 'directory'
33
+ if options['path']
34
+ begin
35
+ puts "Fetching project data from directory: #{options['path']}"
36
+ FileUtils.cp_r(Dir[options['path'] + '/*'], Dir['.'].first)
37
+ 0
38
+ rescue
39
+ 1
40
+ end
41
+ else
42
+ 1
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ # Global MDT module
2
+ module MDT
3
+ # A module referring specifically to mdt-simple
4
+ module Simple
5
+ # mdt-simple gem version
6
+ VERSION = '0.0.1'
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdt-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Phitherek_
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mdt-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.7'
41
+ description: A module with simple implementations for MDT
42
+ email:
43
+ - phitherek@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ files:
49
+ - README.md
50
+ - lib/mdt-simple.rb
51
+ - lib/mdt/command_modifiers.rb
52
+ - lib/mdt/command_modifiers/simple.rb
53
+ - lib/mdt/commands.rb
54
+ - lib/mdt/commands/simple.rb
55
+ - lib/mdt/directory_choosers.rb
56
+ - lib/mdt/directory_choosers/simple.rb
57
+ - lib/mdt/fetchers.rb
58
+ - lib/mdt/fetchers/simple.rb
59
+ - lib/mdt/version.rb
60
+ homepage: https://github.com/Phitherek/mdt-simple
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ documentation_uri: http://www.rubydoc.info/github/Phitherek/mdt-simple
65
+ source_code_uri: https://github.com/Phitherek/mdt-simple
66
+ post_install_message:
67
+ rdoc_options:
68
+ - "--title"
69
+ - MDT Simple module
70
+ - "--main"
71
+ - README.md
72
+ - "--line-numbers"
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.7.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: MDT Simple module
91
+ test_files: []