themigrator 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1,156 @@
1
1
  require 'curses'
2
2
 
3
+ require 'themigrator/ui/log_area'
4
+ require 'themigrator/ui/title_bar'
5
+ require 'themigrator/ui/progress_window'
6
+ require 'themigrator/ui/getchar'
7
+ require 'thread'
8
+
9
+ Thread.abort_on_exception = true
10
+
11
+ UILOG = Logger.new('ui.log')
12
+ UILOG.formatter = proc { |_severity, _datetime, _progname, msg|
13
+ msg + "\n"
14
+ }
15
+ UILOGMUTEX = Mutex.new
16
+ def ui_log(*args)
17
+ UILOGMUTEX.synchronize do
18
+ UILOG << args.join("\n\r") + "\n"
19
+ end
20
+ end
21
+
22
+ def ui_log_exception(e)
23
+ ui_log ''
24
+ ui_log e.inspect
25
+ ui_log e.backtrace
26
+ end
27
+
3
28
  module Themigrator
4
29
  class UI
5
30
  include Curses
6
31
  include Logger
32
+ include LogArea
33
+ include TitleBar
34
+ include ProgressWindow
35
+ include Getchar
7
36
 
8
37
  def initialize(progress_monitor)
9
38
  @pm = progress_monitor
10
39
  @roles = []
40
+ @current_action = ''
11
41
  end
12
42
 
13
43
  def start
14
44
  init_progress_monitor
15
45
  init_screen
16
- Thread.new {@pm.start}
17
- Thread.new {render_loop}
18
- input_loop
46
+ Thread.new { @pm.start }
47
+ Thread.new { render_loop }
48
+ input_loop
19
49
  end
20
50
 
21
51
  private
22
52
 
23
53
  def render_loop
24
54
  loop do
25
- render
26
- sleep 0.1
55
+ sleep ENV['SLEEP'] ? ENV['SLEEP'].to_f : 0.2
56
+ render
27
57
  end
28
58
  end
29
59
 
30
60
  def input_loop
61
+ scripts = Themigrator::Migration::SCRIPTS
62
+ keys = []
31
63
  loop do
32
- case e = getch
33
- when Key::ENTER,10
34
- exit 0
35
- else
36
- raise e.inspect
37
- end
64
+ case e = getchar
65
+ when :left
66
+ previous_action
67
+ when :right
68
+ next_action
69
+ when :c_c, 'q'
70
+ exit 0
71
+ when :npage
72
+ la_npage
73
+ say 'next_page'
74
+ when :ppage
75
+ la_ppage
76
+ say 'previous_page'
77
+ else
78
+ keys.unshift(e)
79
+ say keys.map(&:inspect).join(' ')
80
+ end
38
81
  end
39
82
  end
40
83
 
84
+ def next_action
85
+ scripts = Themigrator::Migration::SCRIPTS
86
+ current_index = scripts.index(@current_action)
87
+ if current_index.nil?
88
+ switch_action(scripts.first)
89
+ return
90
+ end
91
+ return if current_index >= scripts.size - 1
92
+ current_index += 1
93
+ next_action_name = scripts[current_index]
94
+ switch_action(next_action_name)
95
+ end
96
+
97
+ def previous_action
98
+ scripts = Themigrator::Migration::SCRIPTS
99
+ current_index = scripts.index(@current_action)
100
+ if current_index.nil?
101
+ switch_action(scripts.first)
102
+ return
103
+ end
104
+ return if current_index.zero?
105
+ current_index -= 1
106
+ next_action_name = scripts[current_index]
107
+ switch_action(next_action_name)
108
+ end
41
109
 
42
110
  def init_progress_monitor
43
111
  @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 }
112
+ start_action: method(:start_action),
113
+ start_role_action: method(:start_role_action),
114
+ end_action: method(:end_action),
115
+ has_roles: method(:has_roles),
116
+ # new_line: proc { sleep 0.3234242 }
48
117
  }
49
118
  end
50
119
 
120
+ def has_roles(roles)
121
+ @roles = roles.sort
122
+ initialize_log_area(@roles)
123
+ end
124
+
125
+ def start_role_action(role, action)
126
+ Thread.new do
127
+ log_file = @pm.log_file(role, action)
128
+
129
+ begin
130
+ File.open(log_file, 'r') do |f|
131
+ loop do
132
+ la_append(action, role, f.read)
133
+ end
134
+ end
135
+ rescue => e
136
+ ui_log_exception(e)
137
+ end
138
+ end
139
+ end
51
140
 
52
141
  def start_action(action)
142
+ switch_action(action.to_s)
143
+ end
144
+
145
+ def switch_action(action)
146
+ action = action.to_s
147
+ return if @current_action == action
148
+ UILOG.debug("switch action from #{@current_index} to #{action}")
149
+ la_switch_action(action)
150
+ pg_set_action(action)
53
151
  @current_action = action
152
+ rescue => e
153
+ ui_log_exception(e)
54
154
  end
55
155
 
56
156
  def end_action
@@ -58,121 +158,31 @@ module Themigrator
58
158
 
59
159
  def init_screen
60
160
  super
61
- crmode()
161
+ # crmode
162
+ # cbreak
163
+ raw
164
+ stdscr.timeout = 100
165
+ noecho
62
166
  curs_set(0)
63
- ObjectSpace.define_finalizer(self, proc {
64
- close_screen
65
- })
167
+ ObjectSpace.define_finalizer(self, proc do
168
+ # close_screen
169
+ end)
66
170
  end
67
171
 
68
-
69
-
70
172
  def render
71
173
  @cols = cols
72
174
  @lines = lines
73
-
175
+ la_render if la_initialize?
74
176
  render_title
75
- render_columns
76
177
  render_progress
178
+ rescue => e
179
+ ui_log_exception(e)
77
180
  end
78
181
 
79
182
  private
80
- def render_title
81
-
82
- title_window.setpos(0,0)
83
- title_window.addstr("The migrator")
84
- title_window.refresh
85
- now_str = Time.now.strftime("%d %b - %H:%M.%S")
86
- time_window.setpos(0,0)
87
- time_window.addstr(now_str)
88
- time_window.refresh
89
- end
90
183
 
91
- def title_window
92
- @title_window ||= Window.new(1, @cols - 18 , 0, 0).tap do |w|
93
- w.attrset(A_BOLD)
94
- end
184
+ def fuck(*args)
185
+ File.open('fucking-log.log', 'a') { |f| f.write(args.join(' ') + "\n") }
95
186
  end
96
-
97
- def time_window
98
- width = 18
99
- @time_window ||= Window.new(1, 18, 0, @cols - 18 ).tap do |w|
100
- w.attrset(A_DIM)
101
- end
102
-
103
- end
104
-
105
- def progress_window
106
- @progress_widnow ||= Window.new(@lines - 1 , @cols - 1, @lines - 1, 0 ).tap do |w|
107
- w.attrset(A_DIM)
108
- end
109
- end
110
-
111
- def render_columns
112
- n_columns.times do |n|
113
- w = column_window(n + 1)
114
- w.addstr("Window #{n}")
115
- w.refresh
116
- end
117
- end
118
-
119
-
120
- def render_progress
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)
125
- progress_window.refresh
126
- end
127
-
128
-
129
- def column_window(n)
130
- @columns ||= []
131
- if @columns[n].nil?
132
- column_height = @lines - 4
133
- column_width = @cols / n_columns
134
- top = 2
135
- left = column_width * (n - 1)
136
- w = Window.new(column_height, column_width - 1, top, left)
137
- w.box("|", "-")
138
- @columns[n] = w
139
- end
140
- @columns[n]
141
- end
142
-
143
- def n_columns
144
- @previous_columns ||=0
145
- if @previous_columns != @roles.size
146
- @columns = []
147
- end
148
- @roles.size
149
- end
150
-
151
-
152
- def something
153
- show_message "hello"
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
161
- end
162
-
163
-
164
- def show_message(message)
165
- width = message.length + 6
166
- win = Window.new(5, width,
167
- (lines - 5) / 2, (cols - width) / 2)
168
- win.box(?|, ?-)
169
- win.setpos(2, 3)
170
- win.addstr(message)
171
- win.refresh
172
- win.getch
173
- win.close
174
- end
175
-
176
-
177
187
  end
178
188
  end
@@ -1,3 +1,3 @@
1
1
  module Themigrator
2
- VERSION = "0.1.12"
2
+ VERSION = '0.1.14'.freeze
3
3
  end
data/lib/themigrator.rb CHANGED
@@ -1,13 +1,11 @@
1
- require "themigrator/version"
2
- require "themigrator/logger"
3
- require "themigrator/migration"
4
- require "themigrator/migrator"
5
- require "themigrator/script_pool"
6
- require "themigrator/script"
7
- require "themigrator/migration_progress"
8
- require "themigrator/ui"
1
+ require 'themigrator/version'
2
+ require 'themigrator/logger'
3
+ require 'themigrator/migration'
4
+ require 'themigrator/migrator'
5
+ require 'themigrator/script_pool'
6
+ require 'themigrator/script'
7
+ require 'themigrator/migration_progress'
8
+ require 'themigrator/ui'
9
9
 
10
10
  module Themigrator
11
-
12
-
13
11
  end
data/themigrator.gemspec CHANGED
@@ -4,25 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'themigrator/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "themigrator"
7
+ spec.name = 'themigrator'
8
8
  spec.version = Themigrator::VERSION
9
- spec.authors = ["Guillermo Álvarez"]
10
- spec.email = ["guillermo@cientifico.net"]
9
+ spec.authors = ['Guillermo Álvarez']
10
+ spec.email = ['guillermo@cientifico.net']
11
11
 
12
- spec.summary = %q{tool to ease migration a data migration process.}
13
- spec.description = %q{The migrator is a program that eases and automates data migrations.}
14
- spec.homepage = "https://github.com/wooga/themigrator"
12
+ spec.summary = 'tool to ease migration a data migration process.'
13
+ spec.description = 'The migrator is a program that eases and automates data migrations.'
14
+ spec.homepage = 'https://github.com/wooga/themigrator'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
17
+ spec.bindir = 'exe'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.12"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "minitest", "~> 5.0"
24
- spec.add_development_dependency "byebug"
21
+ spec.add_development_dependency 'bundler', '~> 1.12'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'minitest', '~> 5.0'
24
+ spec.add_development_dependency 'byebug'
25
+ spec.add_development_dependency 'rubocop'
25
26
 
26
- spec.add_dependency "thor", "~> 0.19"
27
- spec.add_dependency "curses", "~> 1.0"
27
+ spec.add_dependency 'thor', '~> 0.19'
28
+ spec.add_dependency 'curses', '~> 1.0'
28
29
  end
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.12
4
+ version: 0.1.14
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-09-01 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: thor
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +124,9 @@ files:
110
124
  - Rakefile
111
125
  - bin/console
112
126
  - bin/setup
127
+ - bin/testui
113
128
  - exe/themigrator
129
+ - how_to_run_it
114
130
  - lib/themigrator.rb
115
131
  - lib/themigrator/cli.rb
116
132
  - lib/themigrator/helper.rb
@@ -118,9 +134,14 @@ files:
118
134
  - lib/themigrator/migration.rb
119
135
  - lib/themigrator/migration_progress.rb
120
136
  - lib/themigrator/migrator.rb
137
+ - lib/themigrator/progress_window.rb
121
138
  - lib/themigrator/script.rb
122
139
  - lib/themigrator/script_pool.rb
123
140
  - lib/themigrator/ui.rb
141
+ - lib/themigrator/ui/getchar.rb
142
+ - lib/themigrator/ui/log_area.rb
143
+ - lib/themigrator/ui/progress_window.rb
144
+ - lib/themigrator/ui/title_bar.rb
124
145
  - lib/themigrator/version.rb
125
146
  - test.sh
126
147
  - themigrator.gemspec