themigrator 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/themigrator/cli.rb +12 -1
- data/lib/themigrator/migration.rb +8 -5
- data/lib/themigrator/migration_progress.rb +1 -1
- data/lib/themigrator/migrator.rb +3 -2
- data/lib/themigrator/ui.rb +111 -3
- data/lib/themigrator/version.rb +1 -1
- data/themigrator.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08079339513cffb694953b4a06a194172e83ff3a
|
4
|
+
data.tar.gz: 4dd9914a7eed161c56113decf2411c41d7bb3e8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6bfbe9b098cdadcbbbedec114b395207a52df7c2bba8e0d0561bfa9b24d47f76519ae3719dddcdcf6e4d1ada40b6d807895b8f598a4c9dbfc88d4f9def2fac
|
7
|
+
data.tar.gz: f4f7e4c4f834718ff75acd1882a63785d7cdeca5a91244f29e6c492c5e75fb6bc1421567fe1b377952e8e828c88b54f55979d626a2cf873f8adae59d8250754f
|
data/lib/themigrator/cli.rb
CHANGED
@@ -6,8 +6,19 @@ module Themigrator
|
|
6
6
|
class CLI < Thor
|
7
7
|
|
8
8
|
desc "migrate", "Migrate the current project"
|
9
|
+
option :roles, desc: "list of roles. By default all."
|
10
|
+
option :background, default: true, type: :boolean, desc: "Don't move the migrator to the background"
|
9
11
|
def migrate
|
10
|
-
|
12
|
+
migrator_opts = {}
|
13
|
+
if options[:roles]
|
14
|
+
migrator_opts[:roles] = options[:roles].split(",")
|
15
|
+
end
|
16
|
+
migrator = Themigrator::Migrator.new(Dir.pwd, migrator_opts)
|
17
|
+
|
18
|
+
if !options[:background]
|
19
|
+
exit migrator.migrate! ? 0 : -1
|
20
|
+
end
|
21
|
+
|
11
22
|
pid = fork do
|
12
23
|
exit migrator.migrate! ? 0 : -1
|
13
24
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'set'
|
2
2
|
|
3
3
|
module Themigrator
|
4
|
-
|
4
|
+
|
5
5
|
# Holds the plan of the migration
|
6
6
|
class Migration
|
7
7
|
|
@@ -10,10 +10,11 @@ module Themigrator
|
|
10
10
|
|
11
11
|
attr_reader :roles, :actions
|
12
12
|
|
13
|
-
def initialize(dir)
|
13
|
+
def initialize(dir, options = {})
|
14
14
|
@dir = dir
|
15
15
|
@action_and_roles = Hash.new{|hash,key| hash[key] = [] }
|
16
16
|
@roles = []
|
17
|
+
@user_roles = options[:roles] || []
|
17
18
|
@actions = []
|
18
19
|
end
|
19
20
|
|
@@ -27,9 +28,11 @@ module Themigrator
|
|
27
28
|
File.executable?(f)
|
28
29
|
}.each {|f|
|
29
30
|
role = File.basename(File.dirname(f))
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
if @user_roles.any? && @user_roles.include?(role)
|
32
|
+
roles.add(role)
|
33
|
+
used_actions << action
|
34
|
+
@action_and_roles[action] << role
|
35
|
+
end
|
33
36
|
|
34
37
|
}
|
35
38
|
|
@@ -9,7 +9,7 @@ module Themigrator
|
|
9
9
|
attr_reader :roles, :run_id, :start_time, :pid, :status, :current_action, :actions
|
10
10
|
|
11
11
|
|
12
|
-
def initialize(dir, run_id
|
12
|
+
def initialize(dir, run_id)
|
13
13
|
@dir, @run_id = dir, run_id
|
14
14
|
@log_file_path = main_log_path(dir, run_id)
|
15
15
|
@roles = []
|
data/lib/themigrator/migrator.rb
CHANGED
@@ -9,7 +9,8 @@ module Themigrator
|
|
9
9
|
|
10
10
|
attr_reader :run_id
|
11
11
|
|
12
|
-
def initialize(dir)
|
12
|
+
def initialize(dir, options = {})
|
13
|
+
@options = options
|
13
14
|
@dir = dir
|
14
15
|
@runned_roles = []
|
15
16
|
@start_time = Time.now
|
@@ -17,7 +18,7 @@ module Themigrator
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def migrate!
|
20
|
-
@migration = Migration.new(@dir)
|
21
|
+
@migration = Migration.new(@dir, roles: @options[:roles])
|
21
22
|
@migration.analyze_project!
|
22
23
|
|
23
24
|
init_logger(main_log_path(@dir, run_id))
|
data/lib/themigrator/ui.rb
CHANGED
@@ -1,17 +1,125 @@
|
|
1
1
|
require 'curses'
|
2
2
|
|
3
3
|
module Themigrator
|
4
|
-
|
4
|
+
class UI
|
5
5
|
include Curses
|
6
6
|
|
7
|
-
def
|
7
|
+
def initialize(progress_monitor)
|
8
|
+
@progress_monitor = progress_monitor
|
8
9
|
init_screen
|
10
|
+
crmode()
|
11
|
+
curs_set(0)
|
12
|
+
ObjectSpace.define_finalizer(self, proc {
|
13
|
+
close_screen
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def init_ui
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def set_columns(n)
|
24
|
+
@n_columns = n
|
9
25
|
end
|
10
26
|
|
11
27
|
def render
|
12
|
-
|
28
|
+
@cols = cols
|
29
|
+
@lines = lines
|
13
30
|
|
31
|
+
render_title
|
32
|
+
render_columns
|
33
|
+
render_progress
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def render_title
|
38
|
+
|
39
|
+
title_window.addstr("The migrator")
|
40
|
+
title_window.refresh
|
41
|
+
now_str = Time.now.strftime("%d %b - %H:%M.%S")
|
42
|
+
time_window.addstr(now_str)
|
43
|
+
time_window.refresh
|
44
|
+
end
|
45
|
+
|
46
|
+
def title_window
|
47
|
+
@title_window ||= Window.new(1, @cols - 18 , 0, 0).tap do |w|
|
48
|
+
w.attrset(A_BOLD)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def time_window
|
53
|
+
width = 18
|
54
|
+
@time_window ||= Window.new(1, 18, 0, @cols - 18 ).tap do |w|
|
55
|
+
w.attrset(A_DIM)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def progress_window
|
61
|
+
@progress_widnow ||= Window.new(@lines - 1 , @cols - 1, @lines - 1, 0 ).tap do |w|
|
62
|
+
w.attrset(A_DIM)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def render_columns
|
67
|
+
n_columns.times do |n|
|
68
|
+
w = column_window(n + 1)
|
69
|
+
w.addstr("Window #{n}")
|
70
|
+
w.refresh
|
71
|
+
end
|
72
|
+
end
|
73
|
+
def render_progress
|
74
|
+
progress_window.addstr("hello")
|
75
|
+
progress_window.refresh
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def column_window(n)
|
80
|
+
@columns ||= []
|
81
|
+
if @columns[n].nil?
|
82
|
+
column_height = @lines - 4
|
83
|
+
column_width = @cols / n_columns
|
84
|
+
top = 2
|
85
|
+
left = column_width * (n - 1)
|
86
|
+
w = Window.new(column_height, column_width, top, left)
|
87
|
+
w.box("|", "-")
|
88
|
+
@columns[n] = w
|
89
|
+
end
|
90
|
+
@columns[n]
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def n_columns
|
95
|
+
@n_columns || 3
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def something
|
100
|
+
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
|
14
108
|
end
|
15
109
|
|
110
|
+
|
111
|
+
def show_message(message)
|
112
|
+
width = message.length + 6
|
113
|
+
win = Window.new(5, width,
|
114
|
+
(lines - 5) / 2, (cols - width) / 2)
|
115
|
+
win.box(?|, ?-)
|
116
|
+
win.setpos(2, 3)
|
117
|
+
win.addstr(message)
|
118
|
+
win.refresh
|
119
|
+
win.getch
|
120
|
+
win.close
|
121
|
+
end
|
122
|
+
|
123
|
+
|
16
124
|
end
|
17
125
|
end
|
data/lib/themigrator/version.rb
CHANGED
data/themigrator.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.12"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency "minitest", "~> 5.0"
|
24
|
+
spec.add_development_dependency "byebug"
|
24
25
|
|
25
26
|
spec.add_dependency "thor", "~> 0.19"
|
26
27
|
spec.add_dependency "curses", "~> 1.0"
|
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.
|
4
|
+
version: 0.1.10
|
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-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: thor
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|