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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6831a1ef183d31bdae66d4ae5080cf3a019b0ace76d259a0783d4751cfca1f94
4
- data.tar.gz: 62ac2d6b97e14081766fd44cefbeca8529afcf51ffd2a63c309850b3c58013cc
3
+ metadata.gz: 5f495782abb13ab1f2378141a37adccc8795754376bceb7b431424f72773bf0b
4
+ data.tar.gz: a858344c43c168dc352e3ee6e68b9009ba607e89a8ca20f3cc92ba6085ad964a
5
5
  SHA512:
6
- metadata.gz: 314214d528f832e92563265161fbf3e11d8960a04720686084ed4d78361a7f2e2b08e67f8bac3c014f329f088f9d9c6b15b32dc3d9e7a48000780d9b1146e9f9
7
- data.tar.gz: 48598af4a378a4190d1292d872133e9c334a214d5d42f02a969b8765079da8ac74f8cdc9c6a8fa82db6c5caae38a8d80b620914542c3905e2176c52210a53608
6
+ metadata.gz: adee8c52252440fd704dac86884cae71c63b4fd476f316ecd70029e324b9fe5b75679f80f996edd8b6675abd2dee6044c03b3ba99b8aba477630ea76dadcfea3
7
+ data.tar.gz: '09ed132b747d2b505e822f96c399df95302c5ac152260489d64fb496cc64e68e11211b33e2f69859e6f89dca959a88d4c511af85fbb38b0907d1841859fcecb9'
@@ -2,6 +2,8 @@
2
2
  require_relative '../lib/diskman'
3
3
  include Diskman
4
4
 
5
+ require 'docopt'
6
+
5
7
  class Main
6
8
  def initialize(opts)
7
9
  @opts = opts
@@ -1,6 +1,5 @@
1
1
  require 'require_all'
2
2
  require 'colorize'
3
- require 'docopt'
4
3
 
5
4
  require 'ostruct'
6
5
 
@@ -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, what:)
4
+ def initialize(items, item:)
5
5
  @items = items
6
- @singular = what
7
- @plural = what + 's'
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 'Please pick from the following %s.' % @plural
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 "#{(space * 4) }#{i + 1}. #{device}"
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 the number of your selection.'
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.choose_block_device
18
+ device = device.choose_with_partitions
19
19
 
20
- fs = Chooser.new(get_list, what: 'filesystem').select
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}"
@@ -4,7 +4,7 @@ module Diskman
4
4
  YES = 'YES'
5
5
 
6
6
  def self.check!
7
- self.new.check!
7
+ new.check!
8
8
  end
9
9
 
10
10
  def check!
@@ -1,11 +1,11 @@
1
1
  module Diskman
2
- class Mount
3
- def self.is_mounted(name)
4
- Mount.new.find(name)
2
+ class Mtab
3
+ def self.mounted?(name)
4
+ new.find(name)
5
5
  end
6
6
 
7
- def self.get_mount_point(name)
8
- Mount.new.find(name).chomp.match(/[^ ]+ (?<m>[^ ]+)/)[:m]
7
+ def self.mount_point(name)
8
+ new.find(name).chomp.match(/[^ ]+ (?<m>[^ ]+)/)[:m]
9
9
  end
10
10
 
11
11
  def find(name)
@@ -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 =~ /^\/sys\/block\/(.*)\/removable$/ && RootDevice.new($1)
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, what: 'removable device').select
12
+ Chooser.new(RootDevice.get_removable, item: 'removable device').select
13
13
  end
14
14
 
15
- def get_devices
16
- Dir[@path + '*'].sort.map do |file|
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 ' + get_mount_point).yellow
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')].reject(&:empty?).join(' ')
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
@@ -1,11 +1,10 @@
1
1
  module Diskman
2
- class System
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 a pointless
5
- # command with sudo first to ensure that we can accept keyboard input
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 echo >/dev/null')
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
- suffices = ['T', 'G', 'M', 'K', 'B']
29
+ suffixes = ['T', 'G', 'M', 'K', 'B']
31
30
 
32
- suffices.each_with_index do |suffix, i|
33
- threshold = k ** (suffices.length - i - 1)
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
@@ -1,3 +1,3 @@
1
1
  module Diskman
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx