ztk 1.4.4 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/README.md +1 -1
  2. data/Rakefile +1 -1
  3. data/lib/ztk.rb +3 -23
  4. data/lib/ztk/ansi.rb +94 -33
  5. data/lib/ztk/background.rb +4 -23
  6. data/lib/ztk/base.rb +5 -24
  7. data/lib/ztk/benchmark.rb +4 -23
  8. data/lib/ztk/command.rb +49 -40
  9. data/lib/ztk/config.rb +3 -22
  10. data/lib/ztk/dsl.rb +3 -22
  11. data/lib/ztk/dsl/base.rb +14 -22
  12. data/lib/ztk/dsl/core.rb +4 -24
  13. data/lib/ztk/dsl/core/actions.rb +1 -21
  14. data/lib/ztk/dsl/core/actions/find.rb +2 -22
  15. data/lib/ztk/dsl/core/actions/timestamps.rb +2 -22
  16. data/lib/ztk/dsl/core/attributes.rb +2 -22
  17. data/lib/ztk/dsl/core/dataset.rb +2 -22
  18. data/lib/ztk/dsl/core/io.rb +2 -22
  19. data/lib/ztk/dsl/core/relations.rb +2 -22
  20. data/lib/ztk/dsl/core/relations/belongs_to.rb +2 -22
  21. data/lib/ztk/dsl/core/relations/has_many.rb +2 -22
  22. data/lib/ztk/locator.rb +3 -22
  23. data/lib/ztk/logger.rb +2 -21
  24. data/lib/ztk/parallel.rb +4 -23
  25. data/lib/ztk/pty.rb +8 -23
  26. data/lib/ztk/report.rb +4 -23
  27. data/lib/ztk/rescue_retry.rb +4 -24
  28. data/lib/ztk/spinner.rb +6 -25
  29. data/lib/ztk/ssh.rb +20 -27
  30. data/lib/ztk/ssh/bootstrap.rb +17 -19
  31. data/lib/ztk/ssh/command.rb +1 -19
  32. data/lib/ztk/ssh/download.rb +1 -19
  33. data/lib/ztk/ssh/exec.rb +14 -24
  34. data/lib/ztk/ssh/file.rb +1 -19
  35. data/lib/ztk/ssh/upload.rb +5 -22
  36. data/lib/ztk/tcp_socket_check.rb +3 -22
  37. data/lib/ztk/template.rb +4 -23
  38. data/lib/ztk/ui.rb +5 -25
  39. data/lib/ztk/version.rb +1 -21
  40. data/spec/spec_helper.rb +1 -1
  41. data/spec/ztk/background_spec.rb +1 -1
  42. data/spec/ztk/base_spec.rb +1 -1
  43. data/spec/ztk/benchmark_spec.rb +1 -1
  44. data/spec/ztk/command_spec.rb +1 -1
  45. data/spec/ztk/config_spec.rb +1 -1
  46. data/spec/ztk/dsl_spec.rb +1 -1
  47. data/spec/ztk/locator_spec.rb +1 -1
  48. data/spec/ztk/logger_spec.rb +1 -1
  49. data/spec/ztk/parallel_spec.rb +1 -1
  50. data/spec/ztk/pty_spec.rb +1 -1
  51. data/spec/ztk/rescue_retry_spec.rb +1 -1
  52. data/spec/ztk/spinner_spec.rb +1 -1
  53. data/spec/ztk/ssh_spec.rb +1 -1
  54. data/spec/ztk/tcp_socket_check_spec.rb +1 -1
  55. data/spec/ztk/template_spec.rb +1 -1
  56. data/spec/ztk/ui_spec.rb +1 -1
  57. data/spec/ztk/version_spec.rb +1 -1
  58. data/ztk.gemspec +2 -2
  59. metadata +4 -4
@@ -1,26 +1,6 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
-
21
1
  module ZTK::DSL::Core::Relations
22
2
 
23
- # @author Zachary Patten <zachary@jovelabs.net>
3
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
24
4
  # @api private
25
5
  module HasMany
26
6
 
@@ -57,7 +37,7 @@ module ZTK::DSL::Core::Relations
57
37
  end
58
38
  end
59
39
 
60
- # @author Zachary Patten <zachary@jovelabs.net>
40
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
61
41
  module ClassMethods
62
42
 
63
43
  def has_many(key, options={})
data/lib/ztk/locator.rb CHANGED
@@ -1,30 +1,11 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
1
  module ZTK
21
2
 
22
- # ZTK::Locator Error Class
3
+ # Locator Error Class
23
4
  #
24
- # @author Zachary Patten <zachary@jovelabs.net>
5
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
25
6
  class LocatorError < Error; end
26
7
 
27
- # @author Zachary Patten <zachary@jovelabs.net>
8
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
28
9
  class Locator
29
10
 
30
11
  class << self
data/lib/ztk/logger.rb CHANGED
@@ -1,23 +1,4 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
- require "logger"
1
+ require 'logger'
21
2
 
22
3
  module ZTK
23
4
 
@@ -41,7 +22,7 @@ module ZTK
41
22
  # $logger.error { "This is a error message!" }
42
23
  # $logger.fatal { "This is a fatal message!" }
43
24
  #
44
- # @author Zachary Patten <zachary@jovelabs.net>
25
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
45
26
  class Logger < ::Logger
46
27
 
47
28
  # Log Levels
data/lib/ztk/parallel.rb CHANGED
@@ -1,29 +1,10 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, VersIOn 2.0
6
- #
7
- # Licensed under the Apache License, VersIOn 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissIOns and
17
- # limitatIOns under the License.
18
- #
19
- ################################################################################
20
- require "base64"
1
+ require 'base64'
21
2
 
22
3
  module ZTK
23
4
 
24
- # ZTK::Parallel Error Class
5
+ # Parallel Error Class
25
6
  #
26
- # @author Zachary Patten <zachary@jovelabs.net>
7
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
27
8
  class ParallelError < Error; end
28
9
 
29
10
  # Parallel Processing Class
@@ -112,7 +93,7 @@ module ZTK
112
93
  # [0, 1, 2]
113
94
  # => nil
114
95
  #
115
- # @author Zachary Patten <zachary@jovelabs.net>
96
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
116
97
  class Parallel < ZTK::Base
117
98
 
118
99
  # Default Maximum Number of Forks
data/lib/ztk/pty.rb CHANGED
@@ -1,37 +1,22 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
1
  require 'pty'
21
2
 
22
3
  module ZTK
23
4
 
24
- # ZTK::PTY Error Class
25
- # @author Zachary Patten <zachary@jovelabs.net>
5
+ # PTY Error Class
6
+ #
7
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
26
8
  class PTYError < Error; end
27
9
 
28
10
  # Ruby PTY Class Wrapper
29
- # @author Zachary Patten <zachary@jovelabs.net>
11
+ #
12
+ # Wraps the Ruby PTY class, providing better functionality.
13
+ #
14
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
30
15
  class PTY
31
16
 
32
17
  class << self
33
18
 
34
- # Wraps the Ruby PTY class, providing better functionality.
19
+ # Spawns a ruby-based PTY.
35
20
  #
36
21
  # @param [Array] args An argument splat to be passed to PTY::spawn
37
22
  #
data/lib/ztk/report.rb CHANGED
@@ -1,33 +1,14 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
1
  require 'socket'
21
2
  require 'timeout'
22
3
 
23
4
  module ZTK
24
5
 
25
- # ZTK::Report Error Class
6
+ # Report Error Class
26
7
  #
27
- # @author Zachary Patten <zachary@jovelabs.net>
8
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
28
9
  class ReportError < Error; end
29
10
 
30
- # ZTK Report Class
11
+ # Report Class
31
12
  #
32
13
  # This class contains tools for generating spreadsheet or key-value list
33
14
  # styled output. Report methods are currently meant to be interchangeable;
@@ -36,7 +17,7 @@ module ZTK
36
17
  #
37
18
  # The idea here is that everything is auto-sized and simply displayed.
38
19
  #
39
- # @author Zachary Patten <zachary@jovelabs.net>
20
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
40
21
  class Report < ZTK::Base
41
22
 
42
23
  # @param [Hash] configuration Configuration options hash.
@@ -1,31 +1,11 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
-
21
1
  module ZTK
22
2
 
23
- # ZTK::RescueRetry Error Class
3
+ # RescueRetry Error Class
24
4
  #
25
- # @author Zachary Patten <zachary@jovelabs.net>
5
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
26
6
  class RescueRetryError < Error; end
27
7
 
28
- # ZTK RescueRetry Class
8
+ # RescueRetry Class
29
9
  #
30
10
  # This class contains an exception handling tool, which will allowing retry
31
11
  # of all or specific *Exceptions* based on a set number of attempts to make.
@@ -94,7 +74,7 @@ module ZTK
94
74
  # 1
95
75
  # => nil
96
76
  #
97
- # @author Zachary Patten <zachary@jovelabs.net>
77
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
98
78
  class RescueRetry
99
79
 
100
80
  class << self
data/lib/ztk/spinner.rb CHANGED
@@ -1,38 +1,19 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
- require "ostruct"
1
+ require 'ostruct'
21
2
 
22
3
  module ZTK
23
4
 
24
- # ZTK::Spinner Error Class
5
+ # Spinner Error Class
25
6
  #
26
- # @author Zachary Patten <zachary@jovelabs.net>
7
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
27
8
  class SpinnerError < Error; end
28
9
 
29
- # ZTK Spinner Class
10
+ # Spinner Class
30
11
  #
31
12
  # This class can be used to display an "activity indicator" to a user while
32
13
  # a task is executed in the supplied block. This indicator takes the form
33
14
  # of a spinner.
34
15
  #
35
- # @author Zachary Patten <zachary@jovelabs.net>
16
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
36
17
  class Spinner
37
18
 
38
19
  class << self
@@ -54,7 +35,7 @@ module ZTK
54
35
  # taking place "behind the scenes".
55
36
  # @return [Object] The return value of the block.
56
37
  #
57
- # @author Zachary Patten <zachary@jovelabs.net>
38
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
58
39
  # @author Stephen Nelson-Smith <stephen@atalanta-systems.com>
59
40
  def spin(options={}, &block)
60
41
  options = Base.build_config({
data/lib/ztk/ssh.rb CHANGED
@@ -1,32 +1,13 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
- require "ostruct"
21
- require "net/ssh"
22
- require "net/ssh/proxy/command"
23
- require "net/sftp"
1
+ require 'ostruct'
2
+ require 'net/ssh'
3
+ require 'net/ssh/proxy/command'
4
+ require 'net/sftp'
24
5
 
25
6
  module ZTK
26
7
 
27
- # ZTK::SSH Error Class
8
+ # SSH Error Class
28
9
  #
29
- # @author Zachary Patten <zachary@jovelabs.net>
10
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
30
11
  class SSHError < Error; end
31
12
 
32
13
  # SSH Multi-function Class
@@ -82,7 +63,7 @@ module ZTK
82
63
  # config.host_key_verify = true
83
64
  # end
84
65
  #
85
- # @author Zachary Patten <zachary@jovelabs.net>
66
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
86
67
  class SSH < ZTK::Base
87
68
  # Exit Signal Mappings
88
69
  EXIT_SIGNALS = {
@@ -153,6 +134,16 @@ module ZTK
153
134
  # enable SSH agent forwarding.
154
135
  # @option configuration [String, Array<String>] :proxy_keys A single or
155
136
  # series of identity files to use for authentication with the proxy.
137
+ # @option options [Boolean] :ignore_exit_status (false) Whether or not
138
+ # we should ignore the exit status of the the process we spawn. By
139
+ # default we do not ignore the exit status and throw an exception if it is
140
+ # non-zero.
141
+ # @option options [Integer] :exit_code (0) The exit code we expect the
142
+ # process to return. This is ignore if *ignore_exit_status* is true.
143
+ # @option options [Boolean] :silence (false) Whether or not we should
144
+ # squelch the output of the process. The output will always go to the
145
+ # logging device supplied in the ZTK::UI object. The output is always
146
+ # available in the return value from the method additionally.
156
147
  def initialize(configuration={})
157
148
  super({
158
149
  :forward_agent => true,
@@ -160,7 +151,9 @@ module ZTK
160
151
  :user_known_hosts_file => '/dev/null',
161
152
  :timeout => 60,
162
153
  :ignore_exit_status => false,
163
- :request_pty => true
154
+ :request_pty => true,
155
+ :exit_code => 0,
156
+ :silence => false
164
157
  }.merge(configuration))
165
158
  config.ui.logger.debug { "config=#{config.send(:table).inspect}" }
166
159
  end
@@ -1,28 +1,26 @@
1
- ################################################################################
2
- #
3
- # Author: Zachary Patten <zachary@jovelabs.net>
4
- # Copyright: Copyright (c) Zachary Patten
5
- # License: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- ################################################################################
20
1
  module ZTK
21
2
  class SSH
22
3
 
4
+ # SSH Bootstrap Functionality
23
5
  module Bootstrap
24
6
  require 'tempfile'
25
7
 
8
+ # SSH Bootstrap
9
+ #
10
+ # Renders the *content* string into a file on the remote host and proceeds
11
+ # to execute it via */bin/bash*. Sudo is prefixed by default, but can be
12
+ # disabled.
13
+ #
14
+ # @example Sample Bootstrap, assuming the @ssh variable is an instance of ZTK::SSH connected to a host.
15
+ # @ssh.bootstrap(IO.read("bootstrap.sh"))
16
+ #
17
+ # @example
18
+ # @ssh.bootstrap("apt-get -y upgrade")
19
+ #
20
+ # @param [String] content What to render out to the bootstrap file we will
21
+ # execute.
22
+ # @param [Boolean] use_sudo Whether or not we should prefix *sudo*
23
+ # on our command.
26
24
  def bootstrap(content, use_sudo=true)
27
25
  tempfile = Tempfile.new("bootstrap")
28
26