themigrator 0.1.11 → 0.1.12

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
  SHA1:
3
- metadata.gz: a23e1a028bd190e0c95beb0d3e3c8ff35dd1facd
4
- data.tar.gz: 0b68ce8a6ad7d4b0fa5c80edb0da03eff18a341f
3
+ metadata.gz: c881ca29c75388a9cb240c301e340245c1d9ae6f
4
+ data.tar.gz: b6d56b409c7e265b6cc5f425c1bdccb3cb2fdccd
5
5
  SHA512:
6
- metadata.gz: 542c8dc643d5a900528854bc85efa0a86f48aa6378b9d4fd54ec358fda01f809b247dca4db21040d47bebf33ba2ff72a0806370d90719649d589062cc4bbada9
7
- data.tar.gz: 4c9983b5338abea4be75ab3b1063a5f44e16fffd51704c5e8bbb241c33f77b537eb111732e8936c74905d989dc2026938672310762e6bb35cfd8a12c7a60ec62
6
+ metadata.gz: e2a3ecfcefedd3315e8b81624a5004c5989c468e94986350036292b14e80097ec93ea56d512ee5ae19d58b863add06d4f5547da3f6779776303c7223ce09b83f
7
+ data.tar.gz: 71d2296919a8e7d1b07f17666fd9cbbbc62442247ff161a8a67ea51637fe1ef4cc5ad4e44b425c7f027c3a8280e1bc98938cfc56c750031166988f4c4e71b384
@@ -1,5 +1,5 @@
1
1
  require 'thor'
2
- require 'themigrator/migrator'
2
+ require 'themigrator'
3
3
 
4
4
 
5
5
  module Themigrator
@@ -26,6 +26,7 @@ module Themigrator
26
26
  log_file = migrator.main_log_path(Dir.pwd, migrator.run_id)
27
27
  sleep 0.1
28
28
  system("tail --pid=#{pid} --lines=+0 --follow #{log_file}")
29
+ #system("#{$0} visualize #{migrator.run_id}")
29
30
  end
30
31
 
31
32
  desc "roles", "show the list of roles"
@@ -34,5 +35,12 @@ module Themigrator
34
35
  migration.analyze_project!
35
36
  puts migration.roles.join("\n")
36
37
  end
38
+
39
+ desc "visualize RUNID", "visualize a migration"
40
+ def visualize(run_id)
41
+ mp = Themigrator::MigrationProgress.new(Dir.pwd, run_id)
42
+ ui = Themigrator::UI.new(mp)
43
+ ui.start
44
+ end
37
45
  end
38
46
  end
@@ -5,7 +5,7 @@ module Themigrator
5
5
  # Holds the plan of the migration
6
6
  class Migration
7
7
 
8
- ACTIONS = %w(setup pre-migrate migrate cleanup)
8
+ ACTIONS = %w(setup pre-migrate migrate post-migrate cleanup)
9
9
  SCRIPTS = ACTIONS | %w(rollback)
10
10
 
11
11
  attr_reader :roles, :actions
@@ -28,7 +28,7 @@ module Themigrator
28
28
  File.executable?(f)
29
29
  }.each {|f|
30
30
  role = File.basename(File.dirname(f))
31
- if @user_roles.any? && @user_roles.include?(role)
31
+ if @user_roles.none? || @user_roles.include?(role)
32
32
  roles.add(role)
33
33
  used_actions << action
34
34
  @action_and_roles[action] << role
@@ -7,6 +7,21 @@ module Themigrator
7
7
  include Logger
8
8
 
9
9
  attr_reader :roles, :run_id, :start_time, :pid, :status, :current_action, :actions
10
+
11
+ def cbks=(a)
12
+ @cbks=a
13
+ end
14
+
15
+ # cbks
16
+ #
17
+ # :has_roles
18
+ # :start_action
19
+ # :start_role_action
20
+ # :end_action
21
+ # :end_role_action
22
+ # :start_migration
23
+ # :end_migration
24
+ #
10
25
 
11
26
 
12
27
  def initialize(dir, run_id)
@@ -14,10 +29,7 @@ module Themigrator
14
29
  @log_file_path = main_log_path(dir, run_id)
15
30
  @roles = []
16
31
  @current_action = nil
17
- @cbks = {
18
- has_roles: has_roles_cbk,
19
- start_action: start_action_cbk
20
- }
32
+ @cbks = {}
21
33
  @actions = Hash.new do |h,k|
22
34
  h[k] = {
23
35
  start_time: nil,
@@ -25,6 +37,13 @@ module Themigrator
25
37
  end_time: nil}
26
38
  end
27
39
 
40
+ end
41
+
42
+ def log_file(role,action)
43
+ log_path(@dir,@run_id,role,action)
44
+ end
45
+
46
+ def start
28
47
  start_log_parser
29
48
  end
30
49
 
@@ -40,7 +59,7 @@ module Themigrator
40
59
 
41
60
  def call_cbk(name, *args)
42
61
  cbk = @cbks[name]
43
- cbk.call(self) if cbk
62
+ cbk.call(*args) if cbk
44
63
  end
45
64
 
46
65
 
@@ -63,10 +82,13 @@ module Themigrator
63
82
  @pid = $1.to_i
64
83
  when /roles: (.+)/
65
84
  @roles = $1.strip.split.sort
85
+ call_cbk(:has_roles, @roles)
66
86
  when /(#{scripts}) => start/
67
87
  action = $1.to_sym
68
88
  @current_action = action
69
89
  @actions[action][:start_time] = time
90
+ call_cbk(:start_action, action)
91
+
70
92
  when /(#{scripts}) => (done|fail) \(([0-9\.]+) ms\)/
71
93
  action = $1.to_sym
72
94
  success = to_success($2)
@@ -91,8 +113,11 @@ module Themigrator
91
113
  @actions[action][:roles][role][:exitcode] = exitcode
92
114
  @actions[action][:roles][role][:success] = success
93
115
  @actions[action][:roles][role][:run_time] = run_time
116
+ when /end => (done|fail) \(([0-9.]+) ms\)/
117
+ @current_action = nil
118
+ @run_time = $3.to_f
94
119
  else
95
- raise line
120
+ raise line.inspect
96
121
  end
97
122
  end
98
123
 
@@ -3,27 +3,70 @@ require 'curses'
3
3
  module Themigrator
4
4
  class UI
5
5
  include Curses
6
+ include Logger
6
7
 
7
8
  def initialize(progress_monitor)
8
- @progress_monitor = progress_monitor
9
+ @pm = progress_monitor
10
+ @roles = []
11
+ end
12
+
13
+ def start
14
+ init_progress_monitor
9
15
  init_screen
10
- crmode()
11
- curs_set(0)
12
- ObjectSpace.define_finalizer(self, proc {
13
- close_screen
14
- })
16
+ Thread.new {@pm.start}
17
+ Thread.new {render_loop}
18
+ input_loop
15
19
  end
16
20
 
21
+ private
17
22
 
18
- def init_ui
23
+ def render_loop
24
+ loop do
25
+ render
26
+ sleep 0.1
27
+ end
19
28
  end
20
29
 
30
+ def input_loop
31
+ loop do
32
+ case e = getch
33
+ when Key::ENTER,10
34
+ exit 0
35
+ else
36
+ raise e.inspect
37
+ end
38
+ end
39
+ end
21
40
 
22
41
 
23
- def set_columns(n)
24
- @n_columns = n
42
+ def init_progress_monitor
43
+ @pm.cbks = {
44
+ start_action: self.method(:start_action),
45
+ end_action: self.method(:end_action),
46
+ has_roles: Proc.new{ @roles = @pm.roles},
47
+ new_line: Proc.new { sleep 1 }
48
+ }
25
49
  end
26
50
 
51
+
52
+ def start_action(action)
53
+ @current_action = action
54
+ end
55
+
56
+ def end_action
57
+ end
58
+
59
+ def init_screen
60
+ super
61
+ crmode()
62
+ curs_set(0)
63
+ ObjectSpace.define_finalizer(self, proc {
64
+ close_screen
65
+ })
66
+ end
67
+
68
+
69
+
27
70
  def render
28
71
  @cols = cols
29
72
  @lines = lines
@@ -36,9 +79,11 @@ module Themigrator
36
79
  private
37
80
  def render_title
38
81
 
82
+ title_window.setpos(0,0)
39
83
  title_window.addstr("The migrator")
40
84
  title_window.refresh
41
85
  now_str = Time.now.strftime("%d %b - %H:%M.%S")
86
+ time_window.setpos(0,0)
42
87
  time_window.addstr(now_str)
43
88
  time_window.refresh
44
89
  end
@@ -70,8 +115,13 @@ module Themigrator
70
115
  w.refresh
71
116
  end
72
117
  end
118
+
119
+
73
120
  def render_progress
74
- progress_window.addstr("hello")
121
+ progress_window.setpos(0,0)
122
+ progress_window.addstr(@pm.roles.inspect)
123
+ progress_window.addstr(@pm.current_action.inspect)
124
+ progress_window.addstr(@action)
75
125
  progress_window.refresh
76
126
  end
77
127
 
@@ -80,31 +130,34 @@ module Themigrator
80
130
  @columns ||= []
81
131
  if @columns[n].nil?
82
132
  column_height = @lines - 4
83
- column_width = @cols / n_columns
133
+ column_width = @cols / n_columns
84
134
  top = 2
85
135
  left = column_width * (n - 1)
86
- w = Window.new(column_height, column_width, top, left)
136
+ w = Window.new(column_height, column_width - 1, top, left)
87
137
  w.box("|", "-")
88
138
  @columns[n] = w
89
139
  end
90
140
  @columns[n]
91
-
92
141
  end
93
142
 
94
143
  def n_columns
95
- @n_columns || 3
144
+ @previous_columns ||=0
145
+ if @previous_columns != @roles.size
146
+ @columns = []
147
+ end
148
+ @roles.size
96
149
  end
97
150
 
98
151
 
99
152
  def something
100
153
  show_message "hello"
101
- # show_message("Hit any key")
102
- setpos((lines - 5) / 2, (cols - 10) / 2)
103
- addstr("Hit any key")
104
- refresh
105
- getch
106
- show_message("Hello, World!")
107
- refresh
154
+ # show_message("Hit any key")
155
+ setpos((lines - 5) / 2, (cols - 10) / 2)
156
+ addstr("Hit any key")
157
+ refresh
158
+ getch
159
+ show_message("Hello, World!")
160
+ refresh
108
161
  end
109
162
 
110
163
 
@@ -1,3 +1,3 @@
1
1
  module Themigrator
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
data/lib/themigrator.rb CHANGED
@@ -5,6 +5,7 @@ require "themigrator/migrator"
5
5
  require "themigrator/script_pool"
6
6
  require "themigrator/script"
7
7
  require "themigrator/migration_progress"
8
+ require "themigrator/ui"
8
9
 
9
10
  module Themigrator
10
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themigrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Álvarez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler