inprovise 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2I3MjliY2U3MTAzZDM4NzA2ZTRmZmVmOGQ0ZmUxZTNkMzA5NmYyOA==
4
+ MjA2NmY3ZWEzYjMzZWZhN2NiZTQ1MTkzODNlMjFhZmMyZDA5MzYzMQ==
5
5
  data.tar.gz: !binary |-
6
- ODQyNTljNDc5YzVhMDFlNDdhYWU1YWMyYzdiNjVlZDY3M2NiMTMyMA==
6
+ YzMxY2Q2NzNiMmYyZjg4YjRlOTFhNDBlNmM0YTZiNzM5OTg5ZDNhNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2UyMGU2ZmY0ZjQzNTkwZmNkMjhjNTY1YTI4ZmI2OGFhNzkyNTQ4MjEwMWQy
10
- YWU0YjNhOTliMjE4YzU0Y2ViNTE4MWUyNjFkNzE0MGQyMWUzNDQxNDJmMjQ1
11
- NGNiYzJjZjg1NjE0NmI5YmM4ZjY3ZGFjMjBhYTc4ZDUyOWRhNzU=
9
+ ZDk2Nzc2ZDZlYjhjNjFiMmM0NzdiMDFiOWNmNjIyYWNlOTdjMDViOTQxOGRi
10
+ ZjQwMGUwYWZmYzU0YjBmZTI0MjZmZjE2NjAyZjQwMGEzNmMyODk5ZjRjOWQ4
11
+ MDgwNjBiNzZlYTBiNTQxYjUyNDUzMWViODQwNGI0Y2QzMTZjZTE=
12
12
  data.tar.gz: !binary |-
13
- NjM3YjZlYmYxY2JjZTYwZDRjN2JmY2I4Y2QwYTNkZDcwZTRjYmMzZTQyMjFi
14
- NzJhNGZkNjc2NzE3ZTcxZWRjZTE5ZWM3ODVjMjU4Mzg3MDAzNDU2ODZlOTgy
15
- ZDZlZTgzMzRhNTU5MjQ1YTc0ZmRhMGJiMTg1NGUyMjkyZjhlZjE=
13
+ YjA0ZWY1YmJmODJjMjhlZTIzYmJhYzE0OTMzNTMyMmE4NjkwN2E2OGUyMjcy
14
+ MzdkZDQxODMwZDNiOTNhOTlkYTcyMGQ2NGQ3ZGIzNDc5MmFiNWI5ZDFhNGZm
15
+ Y2ZhYWYwYzEwZDRhZWE0NzAwODUzNDYzMDYyMTk3Y2I5ZjI0ZTI=
@@ -119,6 +119,10 @@ module Inprovise::CmdHelper
119
119
  nil
120
120
  end
121
121
 
122
+ def move(from, to)
123
+ nil
124
+ end
125
+
122
126
  def delete(path)
123
127
  nil
124
128
  end
@@ -183,8 +183,12 @@ class Inprovise::ExecutionContext
183
183
  @node.copy(from, to)
184
184
  end
185
185
 
186
+ def move(from, to)
187
+ @node.move(from, to)
188
+ end
189
+
186
190
  def local(path)
187
- Inprovise::LocalFile.new(path)
191
+ Inprovise::LocalFile.new(self, path)
188
192
  end
189
193
 
190
194
  def remote(path)
@@ -61,7 +61,7 @@ class Inprovise::Infrastructure::Group < Inprovise::Infrastructure::Target
61
61
  end
62
62
 
63
63
  def self.json_create(o)
64
- data = o[:data]
65
- new(data[:name], data[:config], data[:targets])
64
+ data = o['data']
65
+ new(data['name'], Inprovise::Infrastructure.symbolize_keys(data['config']), data['targets'])
66
66
  end
67
67
  end
@@ -41,6 +41,8 @@ Inprovise::CmdHelper.define('linux') do
41
41
  def sudo
42
42
  return self if @exec == :sudo_run
43
43
  @sudo ||= self.class.new(@channel, true)
44
+ @sudo.set_cwd(@cwd)
45
+ @sudo
44
46
  end
45
47
 
46
48
  # file management
@@ -83,7 +85,7 @@ Inprovise::CmdHelper.define('linux') do
83
85
  begin
84
86
  @channel.exists?(path)
85
87
  rescue
86
- exec(%{if [ -f #{path} ]; then echo "true"; else echo "false"; fi}).strip == 'true'
88
+ exec(%{if [ -f #{path} ]; then echo true; else echo false; fi}).strip == 'true'
87
89
  end
88
90
  end
89
91
 
@@ -109,6 +111,10 @@ Inprovise::CmdHelper.define('linux') do
109
111
  exec("cp #{real_path(from)} #{real_path(to)}")
110
112
  end
111
113
 
114
+ def move(from, to)
115
+ exec("mv #{real_path(from)} #{real_path(to)}")
116
+ end
117
+
112
118
  def delete(path)
113
119
  path = real_path(path)
114
120
  begin
@@ -175,7 +181,7 @@ Inprovise::CmdHelper.define('linux') do
175
181
  end
176
182
 
177
183
  def sudo_run(cmd, forcelog=false)
178
- @channel.run("sudo #{cmd}", forcelog)
184
+ @channel.run(%{sudo sh -c "#{cmd}"}, forcelog)
179
185
  end
180
186
 
181
187
  end
@@ -74,6 +74,10 @@ Inprovise::CmdHelper.define('windows') do
74
74
  run("copy #{from} #{to}")
75
75
  end
76
76
 
77
+ def move(from, to)
78
+ run("rename #{from} #{to}")
79
+ end
80
+
77
81
  def delete(path)
78
82
  begin
79
83
  @channel.delete(path)
@@ -9,8 +9,12 @@ require 'monitor'
9
9
  module Inprovise::Infrastructure
10
10
 
11
11
  # setup JSON parameters
12
- JSON.load_default_options[:symbolize_names] = true
13
- JSON.create_id = :json_class
12
+ JSON.create_id = 'json_class'
13
+
14
+ def self.symbolize_keys(hsh)
15
+ return hsh unless Hash === hsh
16
+ hsh.reduce({}) {|h, (k,v)| h[k.to_sym] = symbolize_keys(v); h }
17
+ end
14
18
 
15
19
  class << self
16
20
  def targets
@@ -10,7 +10,8 @@ require 'etc'
10
10
  class Inprovise::LocalFile
11
11
  attr_reader :path
12
12
 
13
- def initialize(path)
13
+ def initialize(context, path)
14
+ @context = context
14
15
  @path = resolve(path)
15
16
  end
16
17
 
@@ -50,19 +51,31 @@ class Inprovise::LocalFile
50
51
  end
51
52
 
52
53
  def copy_to(destination)
54
+ destination = self.class.new(destination) if String === destination
53
55
  if destination.is_local?
54
56
  duplicate(destination)
55
57
  else
56
58
  upload(destination)
57
59
  end
60
+ end
61
+
62
+ def move_to(destination)
63
+ destination = self.class.new(destination) if String === destination
64
+ if destination.is_local?
65
+ FileUtils.mv(path, destination.path)
66
+ else
67
+ upload(destination)
68
+ end
58
69
  destination
59
70
  end
60
71
 
61
72
  def copy_from(source)
73
+ source = self.class.new(source) if String === source
62
74
  source.copy_to(self)
63
75
  end
64
76
 
65
77
  def duplicate(destination)
78
+ destination = self.class.new(destination) if String === destination
66
79
  FileUtils.cp(path, destination.path)
67
80
  destination
68
81
  end
@@ -70,7 +83,7 @@ class Inprovise::LocalFile
70
83
  def upload(destination)
71
84
  destination = @context.remote(destination) if String === destination
72
85
  if destination.is_local?
73
- FileUtils.cp(path, destination.path)
86
+ duplicate(destination)
74
87
  else
75
88
  destination.upload(self)
76
89
  end
@@ -126,6 +126,11 @@ class Inprovise::Infrastructure::Node < Inprovise::Infrastructure::Target
126
126
  helper.copy(from, to)
127
127
  end
128
128
 
129
+ def move(from, to)
130
+ log.execute("MOVE: #{from} #{to}") if Inprovise.verbosity > 0
131
+ helper.move(from, to)
132
+ end
133
+
129
134
  def delete(path)
130
135
  log.execute("DELETE: #{path}") if Inprovise.verbosity > 0
131
136
  helper.delete(path)
@@ -228,8 +233,8 @@ class Inprovise::Infrastructure::Node < Inprovise::Infrastructure::Target
228
233
  end
229
234
 
230
235
  def self.json_create(o)
231
- data = o[:data]
232
- new(data[:name], data[:config])
236
+ data = o['data']
237
+ new(data['name'], Inprovise::Infrastructure.symbolize_keys(data['config']))
233
238
  end
234
239
 
235
240
  private
@@ -45,35 +45,49 @@ class Inprovise::RemoteFile
45
45
  end
46
46
 
47
47
  def copy_to(destination)
48
+ destination = @context.remote(destination) if String === destination
48
49
  if destination.is_local?
49
50
  download(destination)
50
51
  else
51
52
  duplicate(destination)
52
53
  end
54
+ end
55
+
56
+ def move_to(destination)
57
+ destination = @context.remote(destination) if String === destination
58
+ if destination.is_local?
59
+ download(destination)
60
+ else
61
+ @context.move(path, destination.path)
62
+ end
53
63
  destination
54
64
  end
55
65
 
56
- def copy_from(destination)
57
- destination.copy_to(self)
66
+ def copy_from(source)
67
+ source = @context.remote(source) if String === source
68
+ source.copy_to(self)
58
69
  end
59
70
 
60
71
  def duplicate(destination)
72
+ destination = @context.remote(destination) if String === destination
61
73
  @context.copy(path, destination.path)
62
74
  destination
63
75
  end
64
76
 
65
77
  def download(destination)
66
- if String === destination || destination.is_local?
67
- @context.download(path, String === destination ? destination : destination.path)
78
+ destination = @context.local(destination) if String === destination
79
+ if destination.is_local?
80
+ @context.download(path, destination.path)
68
81
  else
69
82
  @context.copy(path, destination.path)
70
83
  end
71
- String === destination ? @context.local(destination) : destination
84
+ destination
72
85
  end
73
86
 
74
87
  def upload(source)
75
- if String === source || source.is_local?
76
- @context.upload(String === source ? source : source.path, path)
88
+ source = @context.local(source) if String === source
89
+ if source.is_local?
90
+ @context.upload(source.path, path)
77
91
  else
78
92
  @context.copy(source.path, path)
79
93
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Inprovise
7
7
 
8
- VERSION = '0.2.3'
8
+ VERSION = '0.2.4'
9
9
 
10
10
  end
@@ -7,8 +7,15 @@ require_relative 'test_helper'
7
7
 
8
8
  describe Inprovise::LocalFile do
9
9
  before :each do
10
+ @node = Inprovise::Infrastructure::Node.new('Node1', {host: 'host.address.net', channel: 'test', helper: 'test'})
11
+ @log = Inprovise::Logger.new(@node, 'remote_file_test')
12
+ @context = Inprovise::ExecutionContext.new(@node, @log, Inprovise::ScriptIndex.default)
10
13
  @local_file_path = File.join(File.dirname(__FILE__), 'fixtures', 'example.txt')
11
- @local_file = Inprovise::LocalFile.new(@local_file_path)
14
+ @local_file = Inprovise::LocalFile.new(@context, @local_file_path)
15
+ end
16
+
17
+ after :each do
18
+ reset_infrastructure!
12
19
  end
13
20
 
14
21
  describe 'path' do
@@ -36,7 +43,7 @@ describe Inprovise::LocalFile do
36
43
  end
37
44
 
38
45
  describe 'copy_to' do
39
- before(:each) { @destination = Inprovise::LocalFile.new("/tmp/example-#{Time.now.to_i}.txt") }
46
+ before(:each) { @destination = Inprovise::LocalFile.new(@context, "/tmp/example-#{Time.now.to_i}.txt") }
40
47
  after(:each) { @destination.delete! }
41
48
 
42
49
  it 'copies a file to another local location' do
@@ -10,9 +10,9 @@ describe Inprovise::RemoteFile do
10
10
  @node = Inprovise::Infrastructure::Node.new('Node1', {host: 'host.address.net', channel: 'test', helper: 'test'})
11
11
  @log = Inprovise::Logger.new(@node, 'remote_file_test')
12
12
  @local_file_path = File.join(File.dirname(__FILE__), 'fixtures', 'example.txt')
13
- @local_file = Inprovise::LocalFile.new(@local_file_path)
14
13
  @remote_file_path = '/tmp/example.txt'
15
14
  @context = Inprovise::ExecutionContext.new(@node, @log, Inprovise::ScriptIndex.default)
15
+ @local_file = Inprovise::LocalFile.new(@context, @local_file_path)
16
16
  @remote_file = Inprovise::RemoteFile.new(@context, @remote_file_path)
17
17
  end
18
18
 
@@ -67,7 +67,7 @@ describe Inprovise::RemoteFile do
67
67
  end
68
68
 
69
69
  it 'copies a file to local location by downlaoding it' do
70
- @local_destination = Inprovise::LocalFile.new("/tmp/example-#{Time.now.to_i}.txt")
70
+ @local_destination = Inprovise::LocalFile.new(@context, "/tmp/example-#{Time.now.to_i}.txt")
71
71
  @node.helper.expects(:download)
72
72
  .with(@remote_file.path, @local_destination.path)
73
73
  .returns(nil)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inprovise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino