diskman 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/diskman +2 -0
- data/lib/diskman.rb +0 -1
- data/lib/diskman/chooser.rb +6 -10
- data/lib/diskman/commands/mkfs.rb +2 -2
- data/lib/diskman/confirmer.rb +1 -1
- data/lib/diskman/mount.rb +5 -5
- data/lib/diskman/root_device.rb +21 -20
- data/lib/diskman/system.rb +7 -8
- data/lib/diskman/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f495782abb13ab1f2378141a37adccc8795754376bceb7b431424f72773bf0b
|
4
|
+
data.tar.gz: a858344c43c168dc352e3ee6e68b9009ba607e89a8ca20f3cc92ba6085ad964a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adee8c52252440fd704dac86884cae71c63b4fd476f316ecd70029e324b9fe5b75679f80f996edd8b6675abd2dee6044c03b3ba99b8aba477630ea76dadcfea3
|
7
|
+
data.tar.gz: '09ed132b747d2b505e822f96c399df95302c5ac152260489d64fb496cc64e68e11211b33e2f69859e6f89dca959a88d4c511af85fbb38b0907d1841859fcecb9'
|
data/bin/diskman
CHANGED
data/lib/diskman.rb
CHANGED
data/lib/diskman/chooser.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Diskman
|
2
2
|
# Presents the user with a list of items to choose from.
|
3
3
|
class Chooser
|
4
|
-
def initialize(items,
|
4
|
+
def initialize(items, item:)
|
5
5
|
@items = items
|
6
|
-
@singular =
|
7
|
-
@plural =
|
6
|
+
@singular = item
|
7
|
+
@plural = item + 's'
|
8
8
|
end
|
9
9
|
|
10
10
|
def label
|
@@ -15,10 +15,6 @@ module Diskman
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def space
|
19
|
-
' '
|
20
|
-
end
|
21
|
-
|
22
18
|
def select
|
23
19
|
if @items.length == 0
|
24
20
|
puts 'No %s found'.yellow % @plural
|
@@ -28,13 +24,13 @@ module Diskman
|
|
28
24
|
if @items.length == 1
|
29
25
|
puts 'Found the following %s.' % label
|
30
26
|
else
|
31
|
-
puts '
|
27
|
+
puts 'Choose from the following %s.' % @plural
|
32
28
|
end
|
33
29
|
|
34
30
|
puts
|
35
31
|
|
36
32
|
@items.each_with_index do |device, i|
|
37
|
-
puts "
|
33
|
+
puts "%6d. %s" % [i + 1, device]
|
38
34
|
end
|
39
35
|
|
40
36
|
puts
|
@@ -45,7 +41,7 @@ module Diskman
|
|
45
41
|
return @items.first
|
46
42
|
end
|
47
43
|
|
48
|
-
puts 'Enter
|
44
|
+
puts 'Enter your selection.'
|
49
45
|
puts
|
50
46
|
print '> '
|
51
47
|
|
@@ -15,9 +15,9 @@ module Command
|
|
15
15
|
device = RootDevice.choose
|
16
16
|
device.ensure_not_mounted!
|
17
17
|
|
18
|
-
device = device.
|
18
|
+
device = device.choose_with_partitions
|
19
19
|
|
20
|
-
fs = Chooser.new(get_list,
|
20
|
+
fs = Chooser.new(get_list, item: 'filesystem').select
|
21
21
|
cmd = device.get_mkfs_command(fs)
|
22
22
|
|
23
23
|
puts "Filesystem: #{fs.yellow}"
|
data/lib/diskman/confirmer.rb
CHANGED
data/lib/diskman/mount.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Diskman
|
2
|
-
class
|
3
|
-
def self.
|
4
|
-
|
2
|
+
class Mtab
|
3
|
+
def self.mounted?(name)
|
4
|
+
new.find(name)
|
5
5
|
end
|
6
6
|
|
7
|
-
def self.
|
8
|
-
|
7
|
+
def self.mount_point(name)
|
8
|
+
new.find(name).chomp.match(/[^ ]+ (?<m>[^ ]+)/)[:m]
|
9
9
|
end
|
10
10
|
|
11
11
|
def find(name)
|
data/lib/diskman/root_device.rb
CHANGED
@@ -4,46 +4,38 @@ module Diskman
|
|
4
4
|
Dir['/sys/block/*/removable'].select do |file|
|
5
5
|
File.read(file).strip == '1'
|
6
6
|
end.map do |path|
|
7
|
-
path =~
|
7
|
+
path =~ %r[^/sys/block/(.*)/removable$]x && RootDevice.new($1)
|
8
8
|
end.sort
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.choose
|
12
|
-
Chooser.new(RootDevice.get_removable,
|
12
|
+
Chooser.new(RootDevice.get_removable, item: 'removable device').select
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
file =~ %r[/dev/(.*)] && Device.new($1)
|
18
|
-
end.sort
|
19
|
-
end
|
20
|
-
|
21
|
-
def choose_block_device
|
22
|
-
Chooser.new(get_devices, what: 'device').select
|
15
|
+
def choose_with_partitions
|
16
|
+
Chooser.new(get_with_partitions, item: 'block device').select
|
23
17
|
end
|
24
18
|
|
25
19
|
def ensure_not_mounted!
|
26
20
|
if mounted?
|
27
|
-
puts ('Warning: device appears to be mounted at ' +
|
21
|
+
puts ('Warning: device appears to be mounted at ' + mount_point).yellow
|
28
22
|
puts 'Not continuing'.red
|
29
23
|
raise Interrupt
|
30
24
|
end
|
31
25
|
end
|
32
26
|
|
33
|
-
def mounted?
|
34
|
-
Mount.is_mounted(@name)
|
35
|
-
end
|
36
|
-
|
37
|
-
def get_mount_point
|
38
|
-
Mount.get_mount_point(@name)
|
39
|
-
end
|
40
|
-
|
41
27
|
def to_s
|
42
28
|
@path + ' [' + [size, label].reject(&:empty?).join(', ') + ']'
|
43
29
|
end
|
44
30
|
|
45
31
|
private
|
46
32
|
|
33
|
+
def get_with_partitions
|
34
|
+
Dir[@path + '*'].sort.map do |file|
|
35
|
+
file =~ %r[/dev/(.*)] && Device.new($1)
|
36
|
+
end.sort
|
37
|
+
end
|
38
|
+
|
47
39
|
def get_int_prop(name)
|
48
40
|
get_prop(name).to_i
|
49
41
|
end
|
@@ -54,7 +46,8 @@ module Diskman
|
|
54
46
|
end
|
55
47
|
|
56
48
|
def label
|
57
|
-
[get_prop('device/vendor'), get_prop('device/model')]
|
49
|
+
parts = [get_prop('device/vendor'), get_prop('device/model')]
|
50
|
+
parts.reject(&:empty?).join(' ')
|
58
51
|
end
|
59
52
|
|
60
53
|
def size_bytes
|
@@ -64,5 +57,13 @@ module Diskman
|
|
64
57
|
def size
|
65
58
|
System.bytes2human(size_bytes)
|
66
59
|
end
|
60
|
+
|
61
|
+
def mounted?
|
62
|
+
Mtab.mounted?(@name)
|
63
|
+
end
|
64
|
+
|
65
|
+
def mount_point
|
66
|
+
Mtab.mount_point(@name)
|
67
|
+
end
|
67
68
|
end
|
68
69
|
end
|
data/lib/diskman/system.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
module Diskman
|
2
|
-
|
2
|
+
module System
|
3
3
|
# If sudo prompts for the password when a pipeline with pv has already
|
4
|
-
# started then we're unable to enter the password. Run
|
5
|
-
#
|
6
|
-
# for the password, if necessary.
|
4
|
+
# started then we're unable to enter the password. Run sudo --validate
|
5
|
+
# first to ensure that we are preauthenticated.
|
7
6
|
def self.prepare_sudo_session!
|
8
|
-
system('sudo
|
7
|
+
system('sudo --validate')
|
9
8
|
end
|
10
9
|
|
11
10
|
# Execute a command.
|
@@ -27,10 +26,10 @@ module Diskman
|
|
27
26
|
# advertised.
|
28
27
|
k = 1000
|
29
28
|
|
30
|
-
|
29
|
+
suffixes = ['T', 'G', 'M', 'K', 'B']
|
31
30
|
|
32
|
-
|
33
|
-
threshold = k ** (
|
31
|
+
suffixes.each_with_index do |suffix, i|
|
32
|
+
threshold = k ** (suffixes.length - i - 1)
|
34
33
|
if b >= threshold
|
35
34
|
return (b / threshold).to_s + suffix
|
36
35
|
end
|
data/lib/diskman/version.rb
CHANGED