deplomat 0.2.14 → 0.2.19

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb0da56b82a705d6aff60ad4b01fd47941634521c963c08ae946b51167b26d6b
4
- data.tar.gz: 57ae983297c8fdc9e4e13cb6a7265b6b81a334a8aef551feb88ce9227b48451f
3
+ metadata.gz: a5a59554a67370399c1549d1efaa1900ff11f5dfffff2da0279c8faf0df56ce5
4
+ data.tar.gz: 2a4194a7208c310ec6ec5c365ce27bf71d577bfca25934e97e6544e19db501d7
5
5
  SHA512:
6
- metadata.gz: 2599a82810507c798ec4f739707cf3390c0ae15d068d4638cd6f50aab8ebed90affb0f5285f4b14102c308bf5727481dec068459b22ac010fa71347201b86346
7
- data.tar.gz: 3ef9941798ebc7328780d6b48bad5280ac4603d9f0eb198919a232e416e4ab706ee4cd79e6a9ec5c79e6c4618bbcb87855d3a4ef2d95b90d9ecb362756ba91d5
6
+ metadata.gz: e6ebf8007e6bd9e4e22a969e91246d267b7e01df0d68899300b24654f257e0e3bad60c1af7515bcd2e76f656076b8f0da3171aa64156ae0b2ff3d935d0899ba5
7
+ data.tar.gz: ce1470376799e1572739dde2ea14df4d62a4374afac0a658c632d1e2f447e46bd7db61d6e3c6ac01b9eefb4d2eef16dda085ce52368dd0080c7812b5983b0eae
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Deplomat (0.2.13)
4
+ deplomat (0.2.19)
5
5
  colorize
6
6
  sys-proctable
7
7
 
@@ -10,7 +10,7 @@ GEM
10
10
  specs:
11
11
  colorize (0.8.1)
12
12
  diff-lcs (1.3)
13
- ffi (1.12.2)
13
+ ffi (1.14.1)
14
14
  rspec (3.8.0)
15
15
  rspec-core (~> 3.8.0)
16
16
  rspec-expectations (~> 3.8.0)
@@ -24,16 +24,16 @@ GEM
24
24
  diff-lcs (>= 1.2.0, < 2.0)
25
25
  rspec-support (~> 3.8.0)
26
26
  rspec-support (3.8.2)
27
- sys-proctable (1.2.2)
27
+ sys-proctable (1.2.6)
28
28
  ffi
29
29
 
30
30
  PLATFORMS
31
31
  ruby
32
32
 
33
33
  DEPENDENCIES
34
- Deplomat!
35
34
  bundler (~> 2.0)
35
+ deplomat!
36
36
  rspec
37
37
 
38
38
  BUNDLED WITH
39
- 2.0.2
39
+ 2.1.4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.14
1
+ 0.2.19
@@ -1,6 +1,7 @@
1
1
  $partials = {}
2
2
  $deplomat_tasks = []
3
3
  $deplomat_tasks_callbacks = {}
4
+ $log_tasks_status = true
4
5
 
5
6
  def execute_in(env:)
6
7
  yield if $env == env
@@ -26,26 +27,39 @@ def print_to_terminal(message, color: nil, newline: true)
26
27
  $stdout.print message
27
28
  end
28
29
 
30
+ def print_task_status(name, status)
31
+ print_to_terminal("\n--- #{name} task #{status.upcase}", color: :light_blue, newline: true)
32
+ end
33
+
29
34
  # This wrapper allows us to insert external before/after
30
35
  # tasks into every method executed by deplomat.
31
36
  # Very useful for the one-time-tasks implementation.
32
37
  def add_task(*tasks)
38
+ tasks.each do |t|
39
+ init_task_callbacks(t)
40
+ $deplomat_tasks_callbacks[t][:before] << lambda { print_task_status(t, "started") }
41
+ $deplomat_tasks_callbacks[t][:after] << lambda { print_task_status(t, "finished") }
42
+ end if $log_tasks_status
33
43
  $deplomat_tasks += tasks
34
44
  end
35
45
  alias :add_tasks :add_task
36
46
 
37
47
  def before_task(task_name, requisite_number, &block)
38
- $deplomat_tasks_callbacks[task_name] ||= {}
39
- $deplomat_tasks_callbacks[task_name][:before] ||= []
48
+ init_task_callbacks(task_name)
40
49
  $deplomat_tasks_callbacks[task_name][:before] << lambda { block.call; update_requisite_number!(requisite_number) }
41
50
  end
42
51
 
43
52
  def after_task(task_name, requisite_number, &block)
44
- $deplomat_tasks_callbacks[task_name] ||= {}
45
- $deplomat_tasks_callbacks[task_name][:after] ||= []
53
+ init_task_callbacks(task_name)
46
54
  $deplomat_tasks_callbacks[task_name][:after] << lambda { block.call; update_requisite_number!(requisite_number) }
47
55
  end
48
56
 
57
+ def init_task_callbacks(task_name)
58
+ $deplomat_tasks_callbacks[task_name] ||= {}
59
+ $deplomat_tasks_callbacks[task_name][:before] ||= []
60
+ $deplomat_tasks_callbacks[task_name][:after] ||= []
61
+ end
62
+
49
63
  def execute_tasks!
50
64
  $deplomat_tasks.each do |t|
51
65
  $deplomat_tasks_callbacks[t][:before].each { |block| block.call } if $deplomat_tasks_callbacks[t] && $deplomat_tasks_callbacks[t][:before]
@@ -6,6 +6,14 @@ module Deplomat
6
6
  super
7
7
  end
8
8
 
9
+ def path_exist?(path)
10
+ exists = File.exist?(adjusted_path(path))
11
+ print_to_terminal((exists ? "EXISTS: #{path}" : "NOT FOUND: #{path}"))
12
+ exists
13
+ end
14
+ alias :path_exists? :path_exist?
15
+ alias :file_exists? :path_exist?
16
+
9
17
  end
10
18
 
11
19
  end
@@ -2,8 +2,7 @@ module Deplomat
2
2
 
3
3
  class Node
4
4
 
5
- attr_accessor :log_to, :raise_exceptions, :logfile, :wrap_in
6
- attr_reader :current_path
5
+ attr_accessor :log_to, :raise_exceptions, :logfile, :wrap_in, :current_path
7
6
  attr_writer :stdout_lines_to_ignore
8
7
 
9
8
  def stdout_lines_to_ignore
@@ -14,11 +13,12 @@ module Deplomat
14
13
  end.compact
15
14
  end
16
15
 
17
- def initialize(logfile: "#{Dir.pwd}/deplomat.log", log_to: [:stdout], path: nil, raise_exceptions: true)
16
+ def initialize(logfile: "#{Dir.pwd}/deplomat.log", log_to: [:stdout], path: nil, log_tasks_status: true, raise_exceptions: true)
18
17
  @log_to = log_to
18
+ @log_tasks_status = log_tasks_status
19
19
  @logfile = logfile
20
20
  @raise_exceptions = raise_exceptions
21
- @current_path = path if path_exist?(path)
21
+ @current_path = path.sub(/\/+\Z/, '') if !path.nil? && path_exist?(path)
22
22
  end
23
23
 
24
24
  def execute(command, path=@current_path, message: [], stdout_source: :stdout, log_command: true, _raise_exceptions: @raise_exceptions)
@@ -105,29 +105,25 @@ module Deplomat
105
105
  alias :mkdir :create_dir
106
106
 
107
107
  def create_symlink(source, target)
108
- execute("ln -s #{source} #{target}")
108
+ execute("ln -sf #{source} #{target}")
109
109
  end
110
110
  alias :ln :create_symlink
111
111
 
112
- def path_exist?(path)
113
- execute("[ -e #{path} ]", @current_path, log_command: false, _raise_exceptions: true) && true
114
- rescue Deplomat::ExecutionError # returned 1, file doesn't exist
115
- false
112
+ def adjusted_path(path)
113
+ if !path.match(/\A\/|~\//)
114
+ path = "#{@current_path}/#{path}".sub("//", "/")
115
+ end
116
+ File.absolute_path(path)
116
117
  end
117
- alias :path_exists? :path_exist?
118
- alias :file_exists? :path_exist?
119
118
 
120
119
  def cd(path)
121
- raise Deplomat::NoSuchPathError, path if !path.nil? && !path_exist?(path)
122
-
123
- @current_path = if path =~ /\A[\/~]/ || path.nil?
120
+ path = adjusted_path(path)
121
+ raise Deplomat::NoSuchPathError, path unless path_exist?(path)
122
+ @current_path = if path.match(/\A\/|~\//)
124
123
  path
125
124
  else
126
- File.expand_path("#{@current_path}#{path}")
127
- end
128
-
129
- # Making sure we don't end up with double // at the end of the path
130
- @current_path = @current_path.chomp("/") + "/"
125
+ "#{@current_path}/#{path}"
126
+ end.sub(/\/+\Z/, '')
131
127
  end
132
128
 
133
129
  def git_push(remote="origin", branch="master")
@@ -184,7 +180,7 @@ module Deplomat
184
180
  entries_by_date.reverse! if leave[1] == :first
185
181
  entries_by_date = entries_by_date[leave[0]..entries_by_date.length]
186
182
  end
187
- entries_by_date.each { |entry| remove("#{path}#{entry}") } if entries_by_date
183
+ entries_by_date.each { |entry| remove("#{path}/#{entry}") } if entries_by_date
188
184
  end
189
185
  end
190
186
 
@@ -24,7 +24,7 @@ module Deplomat
24
24
  end
25
25
  @pids.compact!
26
26
  if @pids.empty?
27
- raise Deplomat::ExecutionError.new("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.", color: "red")
27
+ raise Deplomat::ExecutionError.new("ERROR: no ssh pid found for\n\t#{first_ssh_command}.\nThis is weird.")
28
28
  elsif @pids.length > 1
29
29
  log("Connected with ssh, host #{host}, but looks like another connection has been opened before...", color: "white")
30
30
  log("connection pids: #{@pids.join(", ")}. We'll be closing them all when finished.", color: "white")
@@ -50,6 +50,15 @@ module Deplomat
50
50
  super("#{@ssh_command} '#{command}'", nil, message: message, stdout_source: stdout_source, log_command: false, _raise_exceptions: _raise_exceptions)
51
51
  end
52
52
 
53
+ def path_exist?(path)
54
+ path = adjusted_path(path)
55
+ status = execute("test -f #{path} || test -d #{path}", nil, log_command: true, _raise_exceptions: false)[:status]
56
+ log((status == 1 ? "NOT FOUND: #{path}" : "EXISTS: #{path}"))
57
+ status == 0
58
+ end
59
+ alias :path_exists? :path_exist?
60
+ alias :file_exists? :path_exist?
61
+
53
62
  def upload(what, where, except: nil)
54
63
  except = "--exclude '#{except}'" if except
55
64
  local_execute "rsync -arzve 'ssh #{@port ? "-p #{@port.to_s} " : ""}' #{except} --delete #{what} #{@user}@#{@host}:#{where}", nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - romanitup
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-05 00:00:00.000000000 Z
11
+ date: 2020-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.1.4
112
+ rubygems_version: 3.1.2
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Deplomat