itamae 1.1.0 → 1.1.1

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: cf3ca04345f9e1c2f82343f422c6017c8ccdd982
4
- data.tar.gz: ded46e740f4c6c1845df1dce58ca0f6fff546513
3
+ metadata.gz: 44eee9b5132dfd112bce4aab19c8c2eb682f0594
4
+ data.tar.gz: 6b734f3066592d75c6010e84c7fb8d7a04bce474
5
5
  SHA512:
6
- metadata.gz: db3709e61d480faa823f4ddce0d29f18f988f2f949dc2bd1272b5b0f2160a53070d9e8fd3f14f55a46acbfaa4ec1c70baef4a2958401396fd02fa2db9633b55f
7
- data.tar.gz: c1244f6570776c26d621c6d4053a100a8f44452937240be45502e9af3412b170f91af127ee283fd5237ba56d14c9815340b7f8dd0d90d8047af4d95a3fd0db3d
6
+ metadata.gz: 7dea2c537c25ee9df8969bae5028ad0820e9e32517cf0d1b4455b2c52dd326b22a77d9131cf894aeaa02a42a469bd93ccbf5ee6cb6558f093be0dba2049a4ff6
7
+ data.tar.gz: 118451e0e59cbbb5e679a1aa8344fda380ed251ac4121937a0b72f1935dc1b64a98b3ce9dca649b71cea7fa80d18b0af3730f5a94706bc1a386d7a658a6e3dff
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
+ ## v1.1.1
2
+
3
+ Features
4
+
5
+ - New resource `remote_directory` which transfers a directory from local to remote like `remote_file` resource. (Thanks to @k0kubun)
6
+ - https://github.com/ryotarai/itamae/pull/66
7
+
1
8
  ## v1.1.0
2
9
 
3
10
  Incompatible changes
4
11
 
5
- - `uid` and `gid` attributes of `user` resource accepts only Integer. (https://github.com/ryotarai/itamae/pull/65)
12
+ - `uid` and `gid` attributes of `user` resource accept only Integer. (https://github.com/ryotarai/itamae/pull/65)
6
13
 
@@ -113,5 +113,9 @@ module Itamae
113
113
  def send_file(*args)
114
114
  Specinfra::Runner.send_file(*args)
115
115
  end
116
+
117
+ def send_directory(*args)
118
+ Specinfra::Runner.send_directory(*args)
119
+ end
116
120
  end
117
121
  end
@@ -2,6 +2,7 @@ require 'itamae'
2
2
  require 'itamae/resource/base'
3
3
  require 'itamae/resource/file'
4
4
  require 'itamae/resource/package'
5
+ require 'itamae/resource/remote_directory'
5
6
  require 'itamae/resource/remote_file'
6
7
  require 'itamae/resource/directory'
7
8
  require 'itamae/resource/template'
@@ -236,6 +236,17 @@ module Itamae
236
236
  backend.send_file(src, dst)
237
237
  end
238
238
 
239
+ def send_directory(src, dst)
240
+ Logger.debug "Sending a directory from '#{src}' to '#{dst}'..."
241
+ unless ::File.directory?(src)
242
+ raise Error, "'#{src}' is not directory."
243
+ end
244
+ unless ::File.exist?(src)
245
+ raise Error, "The directory '#{src}' doesn't exist."
246
+ end
247
+ backend.send_directory(src, dst)
248
+ end
249
+
239
250
  def do_not_run_because_of_only_if?
240
251
  @only_if_command &&
241
252
  run_command(@only_if_command, error: false).exit_status != 0
@@ -0,0 +1,84 @@
1
+ require 'itamae'
2
+
3
+ module Itamae
4
+ module Resource
5
+ class RemoteDirectory < Base
6
+ define_attribute :action, default: :create
7
+ define_attribute :path, type: String, default_name: true
8
+ define_attribute :source, type: String, required: true
9
+ define_attribute :mode, type: String
10
+ define_attribute :owner, type: String
11
+ define_attribute :group, type: String
12
+
13
+ def pre_action
14
+ directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path))
15
+ src = ::File.expand_path(directory, ::File.dirname(@recipe.path))
16
+
17
+ @temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
18
+ send_directory(src, @temppath)
19
+
20
+ case @current_action
21
+ when :create
22
+ attributes.exist = true
23
+ end
24
+ end
25
+
26
+ def set_current_attributes
27
+ current.exist = run_specinfra(:check_file_is_directory, attributes.path)
28
+
29
+ if current.exist
30
+ current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
31
+ current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
32
+ current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
33
+ else
34
+ current.mode = nil
35
+ current.owner = nil
36
+ current.group = nil
37
+ end
38
+ end
39
+
40
+ def show_differences
41
+ super
42
+
43
+ if current.exist
44
+ diff = run_command(["diff", "-u", attributes.path, @temppath], error: false)
45
+ if diff.exit_status == 0
46
+ # no change
47
+ Logger.debug "directory content will not change"
48
+ else
49
+ Logger.info "diff:"
50
+ diff.stdout.each_line do |line|
51
+ Logger.info "#{line.strip}"
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def action_create(options)
58
+ if attributes.mode
59
+ run_specinfra(:change_file_mode, @temppath, attributes.mode)
60
+ end
61
+ if attributes.owner || attributes.group
62
+ run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group)
63
+ end
64
+
65
+ if run_specinfra(:check_file_is_file, attributes.path)
66
+ unless check_command(["diff", "-q", @temppath, attributes.path])
67
+ updated!
68
+ end
69
+ else
70
+ updated!
71
+ end
72
+
73
+ run_specinfra(:remove_file, attributes.path)
74
+ run_specinfra(:move_file, @temppath, attributes.path)
75
+ end
76
+
77
+ def action_delete(options)
78
+ if run_specinfra(:check_file_is_directory, attributes.path)
79
+ run_specinfra(:remove_file, attributes.path)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-22 00:00:00.000000000 Z
11
+ date: 2014-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -173,6 +173,7 @@ files:
173
173
  - lib/itamae/resource/link.rb
174
174
  - lib/itamae/resource/local_ruby_block.rb
175
175
  - lib/itamae/resource/package.rb
176
+ - lib/itamae/resource/remote_directory.rb
176
177
  - lib/itamae/resource/remote_file.rb
177
178
  - lib/itamae/resource/service.rb
178
179
  - lib/itamae/resource/template.rb