mountpoints 1.0.13 → 1.1.3
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 +4 -4
- data/README.md +62 -0
- data/USAGE.md +0 -0
- data/doc/README.gen +34 -0
- data/lib/mountpoints/misc.rb +146 -0
- data/lib/mountpoints/mountpoints.rb +182 -163
- data/lib/mountpoints/version/version.rb +8 -3
- data/mountpoints.gemspec +19 -18
- metadata +36 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c85d47f97cbafda0facc4764b4edade704a5b6fca8e8789c8cea3ecf8e2ceefb
|
4
|
+
data.tar.gz: 8c96e1778f10f7e12feb708b3823a9a18525db577e6ff2cd455c426f1f7afec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df3c8b23e3ce1b8417b1423f532aac1ba6840a87b3d6d14a957155701fc438f31a8f95603809eefc5a639096296683f92f0cef4e5a57902e0ed45af883ec4920
|
7
|
+
data.tar.gz: 3982fecdeee18c74999b5b884d3a16e4123cfde2dbcbb192e4ed3dcf97ae570b8cdd71560af88f84e5a2028baa71f66ed770be88e9392b721751477490a674f5
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
[](https://www.gobolinux.org/)
|
2
|
+
[](https://www.ruby-lang.org/en/)
|
3
|
+
[](https://badge.fury.io/rb/mountpoints)
|
4
|
+
|
5
|
+
This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">15.05.2022</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">03:48:52</span> o'clock.
|
6
|
+
|
7
|
+
## Goals of this project
|
8
|
+
|
9
|
+
This project shall simply display the available mountpoints for
|
10
|
+
USB devices.
|
11
|
+
|
12
|
+
Usage example:
|
13
|
+
|
14
|
+
require 'mountpoints'
|
15
|
+
pp Mountpoints[] # This will return an Array, which contains the mounted devices.
|
16
|
+
|
17
|
+
## Commandline flags
|
18
|
+
|
19
|
+
The flag **--extra-verbose** can be used to report more information about
|
20
|
+
the mounpoints (on Linux).
|
21
|
+
|
22
|
+
## Using the project on windows
|
23
|
+
|
24
|
+
On linux we can use "fdisk -l" and this should work fine.
|
25
|
+
|
26
|
+
On Windows we have to use another way. I picked **wmic**.
|
27
|
+
|
28
|
+
Example:
|
29
|
+
|
30
|
+
wmic logicaldisk where "drivetype=3" get DeviceID
|
31
|
+
|
32
|
+
This then gets parsed and the last line is assumed to be the
|
33
|
+
currently inserted USB harddisc. This evidently may break for
|
34
|
+
many use cases, which is why I document it here - but for
|
35
|
+
my own simple use cases this actually works.
|
36
|
+
|
37
|
+
|
38
|
+
## Contact information
|
39
|
+
|
40
|
+
If your creative mind has ideas and specific suggestions to make this
|
41
|
+
gem more useful in general, feel free to drop me an email at any
|
42
|
+
time, via:
|
43
|
+
|
44
|
+
shevy@inbox.lt
|
45
|
+
|
46
|
+
Before that email I used an email account at Google gmail, but in **2021** I
|
47
|
+
decided to slowly abandon gmail for various reasons. In part this is because
|
48
|
+
the UI annoys me (on non-chrome browser loading takes too long), but also
|
49
|
+
because of Google's attempt to establish mass surveillance via its
|
50
|
+
federated cohorts sniffing (FLoC). I do not know what happened at Google,
|
51
|
+
but enough is enough - there is only so much you can take while supporting
|
52
|
+
greed. When it comes to data mining done by private groups, ultimately
|
53
|
+
the user became the product.
|
54
|
+
|
55
|
+
Do keep in mind that responding to emails may take some time,
|
56
|
+
depending on the amount of work I may have at that moment, due
|
57
|
+
to reallife time constraints. I will, however had, read feedback
|
58
|
+
eventually. Patches and code changes are welcome too, of course,
|
59
|
+
as long as they are in the spirit of the project at hand, e. g.
|
60
|
+
fitting to the general theme. For this I may make use of github
|
61
|
+
as a discussion site, but this has a low priority right now.
|
62
|
+
|
data/USAGE.md
CHANGED
File without changes
|
data/doc/README.gen
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
ADD_RUBY_HEAD
|
2
|
+
ADD_MAIN_TIMESTAMP
|
3
|
+
|
4
|
+
## Goals of this project
|
5
|
+
|
6
|
+
This project shall simply display the available mountpoints for
|
7
|
+
USB devices.
|
8
|
+
|
9
|
+
Usage example:
|
10
|
+
|
11
|
+
require 'mountpoints'
|
12
|
+
pp Mountpoints[] # This will return an Array, which contains the mounted devices.
|
13
|
+
|
14
|
+
## Commandline flags
|
15
|
+
|
16
|
+
The flag **--extra-verbose** can be used to report more information about
|
17
|
+
the mounpoints (on Linux).
|
18
|
+
|
19
|
+
## Using the project on windows
|
20
|
+
|
21
|
+
On linux we can use "fdisk -l" and this should work fine.
|
22
|
+
|
23
|
+
On Windows we have to use another way. I picked **wmic**.
|
24
|
+
|
25
|
+
Example:
|
26
|
+
|
27
|
+
wmic logicaldisk where "drivetype=3" get DeviceID
|
28
|
+
|
29
|
+
This then gets parsed and the last line is assumed to be the
|
30
|
+
currently inserted USB harddisc. This evidently may break for
|
31
|
+
many use cases, which is why I document it here - but for
|
32
|
+
my own simple use cases this actually works.
|
33
|
+
|
34
|
+
ADD_CONTACT_INFORMATION
|
@@ -0,0 +1,146 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'mountpoints/misc.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class Mountpoints
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === debug?
|
11
|
+
# ========================================================================= #
|
12
|
+
def debug?
|
13
|
+
DEBUG
|
14
|
+
end
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === rds
|
18
|
+
# ========================================================================= #
|
19
|
+
def rds(i)
|
20
|
+
i.squeeze('/')
|
21
|
+
end
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === determine_the_mountpoints_on_linux
|
25
|
+
# ========================================================================= #
|
26
|
+
def determine_the_mountpoints_on_linux
|
27
|
+
set_command_to_run(DF_COMMAND)
|
28
|
+
if debug?
|
29
|
+
e "Now running this command: #{sfancy(command_to_run?)}"
|
30
|
+
end
|
31
|
+
result = `#{command_to_run?}`.split("\n").select {|entry|
|
32
|
+
entry.include?('/dev/sd')
|
33
|
+
}.reject {|line|
|
34
|
+
splitted = line.split(' ').map {|inner_entry| inner_entry.strip }
|
35
|
+
splitted.last == '/'
|
36
|
+
}
|
37
|
+
result.map! {|entry|
|
38
|
+
# =================================================================== #
|
39
|
+
# The line may look like this:
|
40
|
+
#
|
41
|
+
# "/dev/sdc1 459G 436G 0 100% /Mount/USB3"
|
42
|
+
#
|
43
|
+
# =================================================================== #
|
44
|
+
entry.split(' ').last.strip
|
45
|
+
}
|
46
|
+
set_mountpoints(result)
|
47
|
+
end
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === determine_the_mountpoints_on_windows
|
51
|
+
# ========================================================================= #
|
52
|
+
def determine_the_mountpoints_on_windows
|
53
|
+
result = ''.dup
|
54
|
+
set_command_to_run('wmic logicaldisk where "drivetype=3" get DeviceID')
|
55
|
+
result << `#{command_to_run?}`.split(N).reject {|line| line.to_s.strip.empty? }.join(N) # This will keep the main result.
|
56
|
+
set_command_to_run('wmic logicaldisk where "drivetype=2" get DeviceID')
|
57
|
+
result << `#{command_to_run?}`.split(N).reject {|line| line.to_s.strip.empty? }.join(N) # This will keep the main result.
|
58
|
+
result = result.split(N).reverse.select {|entry|
|
59
|
+
entry.include? ':'
|
60
|
+
}.map {|entry|
|
61
|
+
entry.strip
|
62
|
+
}.reject {|entry| entry.include? 'DeviceID' } .uniq
|
63
|
+
set_mountpoints(result)
|
64
|
+
end
|
65
|
+
|
66
|
+
# ========================================================================= #
|
67
|
+
# === use_windows?
|
68
|
+
# ========================================================================= #
|
69
|
+
def use_windows?
|
70
|
+
return Mountpoints.use_windows?
|
71
|
+
end; alias is_on_windows? use_windows? # === is_on_windows?
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === Mountpoints.use_windows?
|
75
|
+
# ========================================================================= #
|
76
|
+
def self.use_windows?
|
77
|
+
case RUBY_PLATFORM
|
78
|
+
when /win/,
|
79
|
+
/mingw/,
|
80
|
+
/msys/
|
81
|
+
return true
|
82
|
+
else
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
end; self.instance_eval { alias is_on_windows? use_windows? } # === Mountpoints.is_on_windows?
|
86
|
+
|
87
|
+
# ========================================================================= #
|
88
|
+
# === Mountpoints.report
|
89
|
+
# ========================================================================= #
|
90
|
+
def self.report
|
91
|
+
Mountpoints[:be_extra_verbose]
|
92
|
+
end
|
93
|
+
|
94
|
+
# ========================================================================= #
|
95
|
+
# === Mountpoints.is_any_mountpoint_available?
|
96
|
+
# ========================================================================= #
|
97
|
+
def self.is_any_mountpoint_available?
|
98
|
+
!new(:be_quiet).array_mountpoints.empty?
|
99
|
+
end
|
100
|
+
|
101
|
+
# ========================================================================= #
|
102
|
+
# === Mountpoints.show
|
103
|
+
# ========================================================================= #
|
104
|
+
def self.show
|
105
|
+
new :be_extra_verbose
|
106
|
+
end
|
107
|
+
|
108
|
+
# ========================================================================= #
|
109
|
+
# === Mountpoints[]
|
110
|
+
#
|
111
|
+
# This method will return an array such as:
|
112
|
+
#
|
113
|
+
# ["/Mount/USB1/"]
|
114
|
+
#
|
115
|
+
# In other words, it will be a silent result.
|
116
|
+
#
|
117
|
+
# Usage examples:
|
118
|
+
#
|
119
|
+
# Mountpoints[]
|
120
|
+
# Mountpoints[:be_extra_verbose]
|
121
|
+
#
|
122
|
+
# ========================================================================= #
|
123
|
+
def self.[](
|
124
|
+
be_extra_verbose = :normal_verbosity
|
125
|
+
)
|
126
|
+
case be_extra_verbose
|
127
|
+
# ======================================================================= #
|
128
|
+
# === :be_extra_verbose
|
129
|
+
# ======================================================================= #
|
130
|
+
when :be_extra_verbose
|
131
|
+
_ = new(be_extra_verbose)
|
132
|
+
_.report_result
|
133
|
+
return _.array_mountpoints
|
134
|
+
else
|
135
|
+
return new(be_extra_verbose).array_mountpoints
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# ========================================================================= #
|
140
|
+
# === Mountpoints.array_mountpoints
|
141
|
+
# ========================================================================= #
|
142
|
+
def self.array_mountpoints
|
143
|
+
new { :be_quiet }.array_mountpoints
|
144
|
+
end; self.instance_eval { alias mountpoints_as_array array_mountpoints } # === Mountpoints.mountpoints_as_array
|
145
|
+
|
146
|
+
end
|
@@ -1,40 +1,47 @@
|
|
1
|
-
#!/
|
2
|
-
# Encoding:
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
3
|
# frozen_string_literal: true
|
4
4
|
# =========================================================================== #
|
5
5
|
# === Mountpoints
|
6
6
|
#
|
7
|
-
#
|
8
|
-
# try to find a specific entry, if you give an argument to .find().
|
7
|
+
# The primary goal for this class is to scan for all mounted USB-devices.
|
9
8
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# '*'
|
13
|
-
#
|
14
|
-
# The above will return an array of all found entries.
|
15
|
-
#
|
16
|
-
# We may also store the target device in attr_reader :mounted_here
|
17
|
-
#
|
18
|
-
# Additionally, this class may use colours to provide easier to
|
19
|
-
# read information.
|
9
|
+
# Colours may be used on the commandline if the .report() method is
|
10
|
+
# called.
|
20
11
|
#
|
21
12
|
# Usage examples:
|
13
|
+
#
|
14
|
+
# Mountpoints.new(ARGV)
|
22
15
|
# Mountpoints.new
|
23
16
|
# Mountpoints.show
|
24
17
|
# Mountpoints.is_any_mountpoint_available?
|
18
|
+
#
|
25
19
|
# =========================================================================== #
|
26
|
-
# require 'mountpoints'
|
20
|
+
# require 'mountpoints/mountpoints.rb'
|
21
|
+
# Mountpoints[]
|
27
22
|
# =========================================================================== #
|
28
|
-
|
29
|
-
require 'colours'
|
30
|
-
rescue LoadError; end
|
31
|
-
require 'opn'
|
32
|
-
require 'mountpoints/version/version.rb'
|
23
|
+
class Mountpoints # === Mountpoints
|
33
24
|
|
34
|
-
|
25
|
+
require 'mountpoints/misc.rb'
|
26
|
+
require 'mountpoints/version/version.rb'
|
35
27
|
|
36
|
-
|
28
|
+
begin
|
29
|
+
require 'colours'
|
30
|
+
include Colours
|
31
|
+
rescue LoadError; end
|
37
32
|
|
33
|
+
begin
|
34
|
+
require 'opn'
|
35
|
+
rescue LoadError; end
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === NAMESPACE
|
39
|
+
# ========================================================================= #
|
40
|
+
NAMESPACE = inspect
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === N
|
44
|
+
# ========================================================================= #
|
38
45
|
N = "\n"
|
39
46
|
|
40
47
|
# ========================================================================= #
|
@@ -45,207 +52,219 @@ class Mountpoints # === Mountpoints.new
|
|
45
52
|
# ========================================================================= #
|
46
53
|
# === DF_COMMAND
|
47
54
|
# ========================================================================= #
|
48
|
-
DF_COMMAND
|
49
|
-
|
50
|
-
# ========================================================================= #
|
51
|
-
# === FDISK_COMMAND
|
52
|
-
# ========================================================================= #
|
53
|
-
FDISK_COMMAND = 'fdisk -l'
|
55
|
+
DF_COMMAND = 'df -T -ah'
|
54
56
|
|
55
57
|
# ========================================================================= #
|
56
58
|
# === DEBUG
|
59
|
+
#
|
60
|
+
# If true then we will debug this class.
|
57
61
|
# ========================================================================= #
|
58
|
-
DEBUG = false
|
62
|
+
DEBUG = false
|
59
63
|
|
60
64
|
# ========================================================================= #
|
61
65
|
# === initialize
|
62
66
|
#
|
63
|
-
# If the first argument is :be_extra_verbose then
|
64
|
-
# information.
|
67
|
+
# If the first argument to this method is :be_extra_verbose then the
|
68
|
+
# class will show more information on the commandline.
|
65
69
|
# ========================================================================= #
|
66
70
|
def initialize(
|
67
|
-
|
71
|
+
commandline_arguments = ARGV,
|
72
|
+
run_already = true
|
68
73
|
)
|
69
74
|
reset
|
70
75
|
case run_already
|
76
|
+
# ======================================================================= #
|
77
|
+
# === :be_quiet
|
78
|
+
# ======================================================================= #
|
79
|
+
when :be_quiet
|
80
|
+
@internal_hash[:be_extra_verbose] = false
|
81
|
+
run_already = true
|
82
|
+
# ======================================================================= #
|
83
|
+
# === :be_extra_verbose
|
84
|
+
# ======================================================================= #
|
71
85
|
when :be_extra_verbose
|
72
|
-
@be_extra_verbose = true
|
86
|
+
@internal_hash[:be_extra_verbose] = true
|
73
87
|
run_already = true
|
88
|
+
# ======================================================================= #
|
89
|
+
# === :normal_verbosity
|
90
|
+
# ======================================================================= #
|
74
91
|
when :normal_verbosity # Simply pass through here.
|
75
92
|
end
|
93
|
+
if commandline_arguments.is_a? Array
|
94
|
+
first = commandline_arguments.first
|
95
|
+
case first
|
96
|
+
when /^-?-?extra(-|_)?verbose$/
|
97
|
+
@internal_hash[:be_extra_verbose] = true
|
98
|
+
run_already = true
|
99
|
+
end
|
100
|
+
end
|
76
101
|
run if run_already
|
77
102
|
end
|
78
103
|
|
79
104
|
# ========================================================================= #
|
80
|
-
# === reset
|
105
|
+
# === reset (reset tag)
|
81
106
|
# ========================================================================= #
|
82
107
|
def reset
|
83
|
-
|
84
|
-
|
108
|
+
# ======================================================================= #
|
109
|
+
# === @namespace
|
110
|
+
# ======================================================================= #
|
111
|
+
@namespace = NAMESPACE
|
112
|
+
# ======================================================================= #
|
113
|
+
# === @internal_hash
|
114
|
+
# ======================================================================= #
|
115
|
+
@internal_hash = {}
|
116
|
+
# ======================================================================= #
|
117
|
+
# === :array_mountpoints
|
118
|
+
# ======================================================================= #
|
119
|
+
@internal_hash[:array_mountpoints] = []
|
120
|
+
# ======================================================================= #
|
121
|
+
# === :be_extra_verbose
|
122
|
+
# ======================================================================= #
|
123
|
+
@internal_hash[:be_extra_verbose] = false
|
124
|
+
# ======================================================================= #
|
125
|
+
# === :command_to_run
|
126
|
+
#
|
127
|
+
# This is the command that will be run via ``.
|
128
|
+
# ======================================================================= #
|
129
|
+
@internal_hash[:command_to_run] = ''.dup
|
85
130
|
end
|
86
131
|
|
87
132
|
# ========================================================================= #
|
88
|
-
# ===
|
133
|
+
# === be_extra_verbose?
|
89
134
|
# ========================================================================= #
|
90
|
-
def
|
91
|
-
|
92
|
-
i << '/' unless i.end_with? '/'
|
93
|
-
elsif i.is_a? Array
|
94
|
-
# ===================================================================== #
|
95
|
-
# Do not flatten here as we may have more than one Array-entry.
|
96
|
-
# ===================================================================== #
|
97
|
-
i.map! {|entry|
|
98
|
-
entry[0] = rds(entry.first+'/')
|
99
|
-
entry
|
100
|
-
} # We want directories to end in a '/'.
|
101
|
-
end
|
102
|
-
if i.is_a? Array
|
103
|
-
i.sort_by! {|entry| entry }
|
104
|
-
end
|
105
|
-
@result = i # Will include trailing /.
|
106
|
-
determine_mountpoints
|
135
|
+
def be_extra_verbose?
|
136
|
+
@internal_hash[:be_extra_verbose]
|
107
137
|
end
|
108
138
|
|
109
139
|
# ========================================================================= #
|
110
|
-
# ===
|
140
|
+
# === set_command_to_run
|
111
141
|
# ========================================================================= #
|
112
|
-
def
|
113
|
-
i
|
142
|
+
def set_command_to_run(i)
|
143
|
+
@internal_hash[:command_to_run] = i
|
114
144
|
end
|
115
145
|
|
116
146
|
# ========================================================================= #
|
117
|
-
# ===
|
118
|
-
#
|
119
|
-
# The @array_mountpoints will keep all directory-names with a trailing
|
120
|
-
# '/'. In other words, the mountpoints will be stored there.
|
147
|
+
# === command_to_run?
|
121
148
|
# ========================================================================= #
|
122
|
-
def
|
123
|
-
@
|
149
|
+
def command_to_run?
|
150
|
+
@internal_hash[:command_to_run]
|
124
151
|
end
|
125
152
|
|
126
153
|
# ========================================================================= #
|
127
|
-
# ===
|
128
|
-
#
|
129
|
-
# This method will run the df-command.
|
154
|
+
# === run_the_system_command
|
130
155
|
# ========================================================================= #
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
156
|
+
def run_the_system_command
|
157
|
+
return `#{command_to_run?}`
|
158
|
+
end
|
159
|
+
|
160
|
+
# ========================================================================= #
|
161
|
+
# === set_mountpoints
|
162
|
+
#
|
163
|
+
# Note that all directories will be stored via a trailing '/' in this
|
164
|
+
# method.
|
165
|
+
# ========================================================================= #
|
166
|
+
def set_mountpoints(i)
|
167
|
+
i = [i].flatten.compact
|
168
|
+
i.map! {|entry|
|
169
|
+
if File.directory? entry
|
170
|
+
entry = rds(entry)
|
171
|
+
end
|
172
|
+
if File.directory?(entry) and !entry.end_with?('/')
|
173
|
+
entry << '/'
|
174
|
+
end
|
175
|
+
entry
|
146
176
|
}
|
147
|
-
|
177
|
+
@internal_hash[:array_mountpoints] = i
|
148
178
|
end
|
149
179
|
|
150
180
|
# ========================================================================= #
|
151
|
-
# ===
|
181
|
+
# === mountpoints?
|
182
|
+
# ========================================================================= #
|
183
|
+
def mountpoints?
|
184
|
+
@internal_hash[:array_mountpoints]
|
185
|
+
end; alias array_mountpoints? mountpoints? # === array_mountpoints?
|
186
|
+
alias array_mountpoints mountpoints? # === array_mountpoints
|
187
|
+
alias mounted_here mountpoints? # === mounted_here
|
188
|
+
alias result? mountpoints? # === result?
|
189
|
+
alias result mountpoints? # === result
|
190
|
+
|
152
191
|
# ========================================================================= #
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
192
|
+
# === report_result (report tag)
|
193
|
+
# ========================================================================= #
|
194
|
+
def report_result(
|
195
|
+
be_verbose = be_extra_verbose?
|
196
|
+
)
|
197
|
+
if be_verbose
|
198
|
+
if mountpoints?.empty?
|
199
|
+
opn; e 'No mount point was found. Thus, it is included '\
|
200
|
+
'that no USB device is currently mounted.'
|
158
201
|
else
|
159
|
-
opn; e '
|
202
|
+
opn; e 'The following mount points were found:'
|
160
203
|
e
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
204
|
+
mountpoints = mountpoints?
|
205
|
+
result = run_the_system_command.split("\n").select {|line|
|
206
|
+
# ================================================================= #
|
207
|
+
# The line may look like this:
|
208
|
+
#
|
209
|
+
# "/dev/sdc1 ext4 459G 436G 0 100% /Mount/USB3\n" +
|
210
|
+
#
|
211
|
+
# ================================================================= #
|
212
|
+
mountpoints.any? {|discovered_mountpoint|
|
213
|
+
line.include? discovered_mountpoint
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
mountpoints.each {|line|
|
218
|
+
if is_on_windows?
|
219
|
+
e line.ljust(LJUST)
|
220
|
+
else
|
221
|
+
line = result.select {|entry|
|
222
|
+
entry.include? entry
|
223
|
+
}.first
|
224
|
+
line = result.select {|inner_line|
|
225
|
+
inner_line.end_with? line
|
226
|
+
}.first
|
227
|
+
line = line.split(' ').map(&:strip)
|
228
|
+
filesize = line[2]
|
229
|
+
name_of_device = line[1]
|
230
|
+
mounted_here = line[0]
|
231
|
+
efancy ' '+
|
232
|
+
mounted_here.ljust(LJUST)+
|
233
|
+
' '+
|
234
|
+
swarn(name_of_device)+' '+
|
235
|
+
'('+Colours.green(filesize)+')'
|
236
|
+
end
|
168
237
|
}
|
169
238
|
e
|
170
239
|
end
|
171
|
-
else # else we report "normally.
|
172
|
-
e result?.join(N)
|
173
240
|
end
|
174
|
-
end; alias report_colourized_result report_result #
|
175
|
-
|
176
|
-
|
177
|
-
# === result?
|
178
|
-
# ========================================================================= #
|
179
|
-
def result?
|
180
|
-
@result
|
181
|
-
end; alias result result? # === result
|
182
|
-
|
183
|
-
# ========================================================================= #
|
184
|
-
# === debug?
|
185
|
-
# ========================================================================= #
|
186
|
-
def debug?
|
187
|
-
DEBUG
|
188
|
-
end
|
189
|
-
|
190
|
-
# ========================================================================= #
|
191
|
-
# === array_mountpoints?
|
192
|
-
# ========================================================================= #
|
193
|
-
def array_mountpoints? # This should always be an Array.
|
194
|
-
@array_mountpoints
|
195
|
-
end; alias array_mountpoints array_mountpoints? # === array_mountpoints
|
241
|
+
end; alias report_colourized_result report_result # === report_colourized_result
|
242
|
+
alias report report_result # === report
|
243
|
+
alias determine_result report_result # === determine_result
|
196
244
|
|
197
245
|
# ========================================================================= #
|
198
246
|
# === run (run tag)
|
199
247
|
# ========================================================================= #
|
200
248
|
def run
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
# ========================================================================= #
|
212
|
-
# === Mountpoints[]
|
213
|
-
#
|
214
|
-
# This method will return an array such as:
|
215
|
-
# ["/Mount/USB1/"]
|
216
|
-
#
|
217
|
-
# In other words, it will be a silent result.
|
218
|
-
#
|
219
|
-
# Mountpoints[]
|
220
|
-
# Mountpoints[:be_extra_verbose]
|
221
|
-
# ========================================================================= #
|
222
|
-
def self.[](be_extra_verbose = :normal_verbosity)
|
223
|
-
if be_extra_verbose == :be_extra_verbose
|
224
|
-
_ = Mountpoints.new(be_extra_verbose)
|
225
|
-
_.report_result
|
226
|
-
else
|
227
|
-
Mountpoints.new(be_extra_verbose).array_mountpoints
|
249
|
+
# ======================================================================= #
|
250
|
+
# === Handle windows next
|
251
|
+
# ======================================================================= #
|
252
|
+
if use_windows?
|
253
|
+
determine_the_mountpoints_on_windows
|
254
|
+
# ======================================================================= #
|
255
|
+
# === Handle linux next
|
256
|
+
# ======================================================================= #
|
257
|
+
else # This branch is specifically for linux
|
258
|
+
determine_the_mountpoints_on_linux
|
228
259
|
end
|
229
260
|
end
|
230
261
|
|
231
|
-
# ========================================================================= #
|
232
|
-
# === Mountpoints.is_any_mountpoint_available?
|
233
|
-
# ========================================================================= #
|
234
|
-
def self.is_any_mountpoint_available?
|
235
|
-
!Mountpoints.new(:be_quiet).array_mountpoints.empty?
|
236
|
-
end
|
237
|
-
|
238
|
-
# ========================================================================= #
|
239
|
-
# === Mountpoints.show
|
240
|
-
# ========================================================================= #
|
241
|
-
def self.show
|
242
|
-
Mountpoints.new :be_extra_verbose
|
243
|
-
end
|
244
|
-
|
245
262
|
end
|
246
263
|
|
247
264
|
if __FILE__ == $PROGRAM_NAME
|
248
265
|
_ = Mountpoints.new :be_extra_verbose
|
249
|
-
_
|
266
|
+
# pp _
|
267
|
+
#_.report
|
268
|
+
pp _.mountpoints?
|
250
269
|
# p _.result?
|
251
|
-
end #
|
270
|
+
end # rubymountpoints --extra-verbose
|
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/
|
2
|
-
# Encoding:
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
3
|
# frozen_string_literal: true
|
4
4
|
# =========================================================================== #
|
5
5
|
class Mountpoints
|
@@ -7,6 +7,11 @@ class Mountpoints
|
|
7
7
|
# ========================================================================= #
|
8
8
|
# === Mountpoints::VERSION
|
9
9
|
# ========================================================================= #
|
10
|
-
VERSION = '1.
|
10
|
+
VERSION = '1.1.3'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === Mountpoints::LAST_UPDATE
|
14
|
+
# ========================================================================= #
|
15
|
+
LAST_UPDATE = '15.05.2022'
|
11
16
|
|
12
17
|
end
|
data/mountpoints.gemspec
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# Gemspec for Project Mountpoints.
|
3
3
|
# =========================================================================== #
|
4
4
|
require 'mountpoints/version/version.rb'
|
5
|
+
require 'roebe'
|
5
6
|
|
6
7
|
Gem::Specification.new { |s|
|
7
8
|
|
@@ -11,27 +12,27 @@ Gem::Specification.new { |s|
|
|
11
12
|
|
12
13
|
DESCRIPTION = <<-EOF
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
and even then not always. It was mostly a "throw-away"
|
17
|
-
gem that I can use, rather than having to parse the
|
18
|
-
output of "fdisk -l".
|
15
|
+
This class will give you back all mountpoints on a Linux
|
16
|
+
System. It may also work on Windows, using "wmic".
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
Please do note that on Linux this works only via "fdisk",
|
19
|
+
and even then not always. It was mostly a "throw-away"
|
20
|
+
gem that I can use quickly, rather than having to parse
|
21
|
+
the output of "fdisk -l".
|
23
22
|
|
24
|
-
|
23
|
+
Also do note that we are only interested in external
|
24
|
+
devices that are mounted that way, NOT other
|
25
|
+
mountpoints.
|
25
26
|
|
26
|
-
|
27
|
-
Mountpoints.show
|
27
|
+
To use this in Ruby, do:
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
require 'mountpoints'
|
30
|
+
Mountpoints.show
|
31
31
|
|
32
|
-
|
32
|
+
# or this variant:
|
33
33
|
|
34
|
-
|
34
|
+
require 'mountpoints'
|
35
|
+
Mountpoints[]
|
35
36
|
|
36
37
|
EOF
|
37
38
|
s.summary = DESCRIPTION
|
@@ -40,13 +41,13 @@ Gem::Specification.new { |s|
|
|
40
41
|
s.extra_rdoc_files = %w()
|
41
42
|
|
42
43
|
s.authors = ['Robert A. Heiler']
|
43
|
-
s.email =
|
44
|
+
s.email = Roebe.email?
|
44
45
|
s.files = Dir['**/*']
|
45
46
|
s.files << 'USAGE.md'
|
46
47
|
s.license = 'GPL-2.0'
|
47
|
-
s.homepage = '
|
48
|
+
s.homepage = 'https://rubygems.org/gems/mountpoints'
|
48
49
|
|
49
|
-
s.required_ruby_version = '>= '+
|
50
|
+
s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
|
50
51
|
s.required_rubygems_version = '>= '+Gem::VERSION
|
51
52
|
s.rubygems_version = '>= '+Gem::VERSION
|
52
53
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mountpoints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert A. Heiler
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colours
|
@@ -40,44 +40,47 @@ dependencies:
|
|
40
40
|
version: '0'
|
41
41
|
description: |2+
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
and even then not always. It was mostly a "throw-away"
|
46
|
-
gem that I can use, rather than having to parse the
|
47
|
-
output of "fdisk -l".
|
43
|
+
This class will give you back all mountpoints on a Linux
|
44
|
+
System. It may also work on Windows, using "wmic".
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
Please do note that on Linux this works only via "fdisk",
|
47
|
+
and even then not always. It was mostly a "throw-away"
|
48
|
+
gem that I can use quickly, rather than having to parse
|
49
|
+
the output of "fdisk -l".
|
52
50
|
|
53
|
-
|
51
|
+
Also do note that we are only interested in external
|
52
|
+
devices that are mounted that way, NOT other
|
53
|
+
mountpoints.
|
54
54
|
|
55
|
-
|
56
|
-
Mountpoints.show
|
55
|
+
To use this in Ruby, do:
|
57
56
|
|
58
|
-
|
59
|
-
|
57
|
+
require 'mountpoints'
|
58
|
+
Mountpoints.show
|
60
59
|
|
61
|
-
|
60
|
+
# or this variant:
|
62
61
|
|
63
|
-
|
62
|
+
require 'mountpoints'
|
63
|
+
Mountpoints[]
|
64
64
|
|
65
|
-
email:
|
65
|
+
email: shevy@inbox.lt
|
66
66
|
executables: []
|
67
67
|
extensions: []
|
68
68
|
extra_rdoc_files: []
|
69
69
|
files:
|
70
|
+
- README.md
|
70
71
|
- USAGE.md
|
72
|
+
- doc/README.gen
|
71
73
|
- lib/mountpoints.rb
|
74
|
+
- lib/mountpoints/misc.rb
|
72
75
|
- lib/mountpoints/mountpoints.rb
|
73
76
|
- lib/mountpoints/version/version.rb
|
74
77
|
- mountpoints.gemspec
|
75
78
|
- test/testing_mountpoints.rb
|
76
|
-
homepage:
|
79
|
+
homepage: https://rubygems.org/gems/mountpoints
|
77
80
|
licenses:
|
78
81
|
- GPL-2.0
|
79
82
|
metadata: {}
|
80
|
-
post_install_message:
|
83
|
+
post_install_message:
|
81
84
|
rdoc_options: []
|
82
85
|
require_paths:
|
83
86
|
- lib
|
@@ -85,21 +88,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
88
|
requirements:
|
86
89
|
- - ">="
|
87
90
|
- !ruby/object:Gem::Version
|
88
|
-
version: 2.
|
91
|
+
version: 2.5.8
|
89
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
93
|
requirements:
|
91
94
|
- - ">="
|
92
95
|
- !ruby/object:Gem::Version
|
93
|
-
version: 3.
|
96
|
+
version: 3.3.13
|
94
97
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
96
|
-
signing_key:
|
98
|
+
rubygems_version: 3.3.13
|
99
|
+
signing_key:
|
97
100
|
specification_version: 4
|
98
|
-
summary: 'This class will give you back all mountpoints on a Linux System.
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
that
|
103
|
-
|
104
|
-
|
101
|
+
summary: 'This class will give you back all mountpoints on a Linux System. It may
|
102
|
+
also work on Windows, using "wmic". Please do note that on Linux this works only
|
103
|
+
via "fdisk", and even then not always. It was mostly a "throw-away" gem that I can
|
104
|
+
use quickly, rather than having to parse the output of "fdisk -l". Also do note
|
105
|
+
that we are only interested in external devices that are mounted that way, NOT other
|
106
|
+
mountpoints. To use this in Ruby, do: require ''mountpoints'' Mountpoints.show #
|
107
|
+
or this variant: require ''mountpoints'' Mountpoints[]'
|
105
108
|
test_files: []
|
109
|
+
...
|