mountpoints 1.0.13 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +101 -0
- data/bin/mountpoints +7 -0
- data/doc/README.gen +72 -0
- data/lib/mountpoints/class/mountpoints.rb +425 -0
- data/lib/mountpoints/constants/constants.rb +19 -0
- data/lib/mountpoints/toplevel_methods/toplevel_methods.rb +92 -0
- data/lib/mountpoints/version/version.rb +8 -3
- data/lib/mountpoints.rb +1 -1
- data/mountpoints.gemspec +24 -29
- data/test/testing_mountpoints.rb +5 -2
- metadata +40 -37
- data/USAGE.md +0 -14
- data/lib/mountpoints/mountpoints.rb +0 -251
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b0855050bed99b01644fa83a4ea8f15330234b30c6a79622968a1c07f4b5a71
|
4
|
+
data.tar.gz: 4970dd1d922f8e42ebc43e1912025d13512978c8604a7d9d3f5c525ab4738000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef6336f27b1a1883fdd5881ea16d13a9f32b2e3eaf4ba868451fcac4d47ede3972d86471fb1fadd773021e684850aad2765af6d33c258d6537f5c380b209fbe7
|
7
|
+
data.tar.gz: 297b56feeab21918d8707c589ce6b5c16c169b7b14328c8ca384f5a247f8829ab4731be73fde617fd7df16bf38a3c307d9511812d03e76e80981c94de1554b6f
|
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
|
2
|
+
[![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mountpoints.svg)](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">23:56:46</span> o'clock.
|
6
|
+
|
7
|
+
<img src="https://i.imgur.com/Oi4pNNi.png" style="margin: 1em">
|
8
|
+
|
9
|
+
## The goals for the mountpoints project
|
10
|
+
|
11
|
+
The mountpoints project shall simply display the available mountpoints
|
12
|
+
for USB devices. This should ideally work on Linux as well on Windows -
|
13
|
+
and, if possible, on other operating systems as well.
|
14
|
+
|
15
|
+
## Simple usage example
|
16
|
+
|
17
|
+
Consider using the mountpoints gem like this, after installation:
|
18
|
+
|
19
|
+
require 'mountpoints'
|
20
|
+
pp Mountpoints[] # This will (quietly) return an Array, which contains the mounted devices.
|
21
|
+
|
22
|
+
Alternative you can use it from the commandline, in which case it
|
23
|
+
will report to you (the user) what it has found, such as "Discovered
|
24
|
+
mountpoint /mnt/usb1/." or something like that.
|
25
|
+
|
26
|
+
## Commandline flags
|
27
|
+
|
28
|
+
The flag **--extra-verbose** can be used to report more information about
|
29
|
+
the mountpoints (on **Linux**).
|
30
|
+
|
31
|
+
## Storing the mountpoints internally
|
32
|
+
|
33
|
+
The current policy is to store all mountpoints as **directories**, that
|
34
|
+
is via a trailing **/**. So if the mountpoint is normally **/Mount/USB1**
|
35
|
+
then this will be stored as **/Mount/USB1/**.
|
36
|
+
|
37
|
+
The reason I document this here is so that I can refer to this policy
|
38
|
+
in case anything changes - and if this document is updated. As of **May
|
39
|
+
2022 this is the case**. This may be subject to change one day, but
|
40
|
+
I expect this to remain as long as the mountpoints gem will be made
|
41
|
+
available here on **rubygems.org**.
|
42
|
+
|
43
|
+
## Using the project on windows
|
44
|
+
|
45
|
+
On **Linux** we can simply use "**fdisk -l**" and this should work
|
46
|
+
fine. If **fdisk** is not available then **df** may suffice. (Since
|
47
|
+
as of the rewrite in **May 2022** the mountpoints gem now defaults
|
48
|
+
to df on linux, actually.)
|
49
|
+
|
50
|
+
On **Windows** we have to use another way. I picked **wmic**.
|
51
|
+
|
52
|
+
Usage example for **wmic**:
|
53
|
+
|
54
|
+
wmic logicaldisk where "drivetype=3" get DeviceID
|
55
|
+
|
56
|
+
This then gets parsed and the last line is assumed to be the
|
57
|
+
currently inserted USB harddisc. This evidently may break for
|
58
|
+
many use cases, in particular when there are several USB
|
59
|
+
devices mount, which is why I document this here - but for
|
60
|
+
my own simple use cases this actually works, and I verified
|
61
|
+
that this indeed does work for simple use cases.
|
62
|
+
|
63
|
+
In **May 2022* two ad-hoc methods were added called:
|
64
|
+
|
65
|
+
Mountpoints.windows1
|
66
|
+
Mountpoints.windows2
|
67
|
+
|
68
|
+
These will run the corresponding wmic commands via `` backticks
|
69
|
+
as well as output the command that is run.
|
70
|
+
|
71
|
+
Regular users won't really need to run this, but in the event
|
72
|
+
that something isn't right you can use these two methods
|
73
|
+
conveniently. It's mostly for debugging, though, so most users
|
74
|
+
will not need to run this.
|
75
|
+
|
76
|
+
|
77
|
+
## Contact information
|
78
|
+
|
79
|
+
If your creative mind has ideas and specific suggestions to make this
|
80
|
+
gem more useful in general, feel free to drop me an email at any
|
81
|
+
time, via:
|
82
|
+
|
83
|
+
shevy@inbox.lt
|
84
|
+
|
85
|
+
Before that email I used an email account at Google gmail, but in **2021** I
|
86
|
+
decided to slowly abandon gmail for various reasons. In part this is because
|
87
|
+
the UI annoys me (on non-chrome browser loading takes too long), but also
|
88
|
+
because of Google's attempt to establish mass surveillance via its
|
89
|
+
federated cohorts sniffing (FLoC). I do not know what happened at Google,
|
90
|
+
but enough is enough - there is only so much you can take while supporting
|
91
|
+
greed. When it comes to data mining done by private groups, ultimately
|
92
|
+
the user became the product.
|
93
|
+
|
94
|
+
Do keep in mind that responding to emails may take some time,
|
95
|
+
depending on the amount of work I may have at that moment, due
|
96
|
+
to reallife time constraints. I will, however had, read feedback
|
97
|
+
eventually. Patches and code changes are welcome too, of course,
|
98
|
+
as long as they are in the spirit of the project at hand, e. g.
|
99
|
+
fitting to the general theme. For this I may make use of github
|
100
|
+
as a discussion site, but this has a low priority right now.
|
101
|
+
|
data/bin/mountpoints
ADDED
data/doc/README.gen
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
ADD_RUBY_LOGO_AND_TIMESTAMP
|
2
|
+
|
3
|
+
<img src="https://i.imgur.com/Oi4pNNi.png" style="margin: 1em">
|
4
|
+
|
5
|
+
## The goals for the mountpoints project
|
6
|
+
|
7
|
+
The mountpoints project shall simply display the available mountpoints
|
8
|
+
for USB devices. This should ideally work on Linux as well on Windows -
|
9
|
+
and, if possible, on other operating systems as well.
|
10
|
+
|
11
|
+
## Simple usage example
|
12
|
+
|
13
|
+
Consider using the mountpoints gem like this, after installation:
|
14
|
+
|
15
|
+
require 'mountpoints'
|
16
|
+
pp Mountpoints[] # This will (quietly) return an Array, which contains the mounted devices.
|
17
|
+
|
18
|
+
Alternative you can use it from the commandline, in which case it
|
19
|
+
will report to you (the user) what it has found, such as "Discovered
|
20
|
+
mountpoint /mnt/usb1/." or something like that.
|
21
|
+
|
22
|
+
## Commandline flags
|
23
|
+
|
24
|
+
The flag **--extra-verbose** can be used to report more information about
|
25
|
+
the mountpoints (on **Linux**).
|
26
|
+
|
27
|
+
## Storing the mountpoints internally
|
28
|
+
|
29
|
+
The current policy is to store all mountpoints as **directories**, that
|
30
|
+
is via a trailing **/**. So if the mountpoint is normally **/Mount/USB1**
|
31
|
+
then this will be stored as **/Mount/USB1/**.
|
32
|
+
|
33
|
+
The reason I document this here is so that I can refer to this policy
|
34
|
+
in case anything changes - and if this document is updated. As of **May
|
35
|
+
2022 this is the case**. This may be subject to change one day, but
|
36
|
+
I expect this to remain as long as the mountpoints gem will be made
|
37
|
+
available here on **rubygems.org**.
|
38
|
+
|
39
|
+
## Using the project on windows
|
40
|
+
|
41
|
+
On **Linux** we can simply use "**fdisk -l**" and this should work
|
42
|
+
fine. If **fdisk** is not available then **df** may suffice. (Since
|
43
|
+
as of the rewrite in **May 2022** the mountpoints gem now defaults
|
44
|
+
to df on linux, actually.)
|
45
|
+
|
46
|
+
On **Windows** we have to use another way. I picked **wmic**.
|
47
|
+
|
48
|
+
Usage example for **wmic**:
|
49
|
+
|
50
|
+
wmic logicaldisk where "drivetype=3" get DeviceID
|
51
|
+
|
52
|
+
This then gets parsed and the last line is assumed to be the
|
53
|
+
currently inserted USB harddisc. This evidently may break for
|
54
|
+
many use cases, in particular when there are several USB
|
55
|
+
devices mount, which is why I document this here - but for
|
56
|
+
my own simple use cases this actually works, and I verified
|
57
|
+
that this indeed does work for simple use cases.
|
58
|
+
|
59
|
+
In **May 2022* two ad-hoc methods were added called:
|
60
|
+
|
61
|
+
Mountpoints.windows1
|
62
|
+
Mountpoints.windows2
|
63
|
+
|
64
|
+
These will run the corresponding wmic commands via `` backticks
|
65
|
+
as well as output the command that is run.
|
66
|
+
|
67
|
+
Regular users won't really need to run this, but in the event
|
68
|
+
that something isn't right you can use these two methods
|
69
|
+
conveniently. It's mostly for debugging, though, so most users
|
70
|
+
will not need to run this.
|
71
|
+
|
72
|
+
ADD_CONTACT_INFORMATION
|
@@ -0,0 +1,425 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Mountpoints
|
6
|
+
#
|
7
|
+
# The primary objective of this class is to scan for all mounted USB-devices.
|
8
|
+
#
|
9
|
+
# Note that toplevel-methods, that is in the form of Mountpoints.foobar(),
|
10
|
+
# will be stored in another .rb file, aptly named "toplevel_methods.rb".
|
11
|
+
#
|
12
|
+
# Colours may be used on the commandline if the .report() method is
|
13
|
+
# called and if use_colours? returns true (which is the default).
|
14
|
+
#
|
15
|
+
# Usage examples:
|
16
|
+
#
|
17
|
+
# Mountpoints.new(ARGV)
|
18
|
+
# Mountpoints.new
|
19
|
+
# Mountpoints.show
|
20
|
+
# Mountpoints.is_any_mountpoint_available?
|
21
|
+
#
|
22
|
+
# =========================================================================== #
|
23
|
+
# require 'mountpoints/class/mountpoints.rb'
|
24
|
+
# =========================================================================== #
|
25
|
+
class Mountpoints # === Mountpoints
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'colours'
|
29
|
+
rescue LoadError; end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'opn'
|
33
|
+
rescue LoadError; end
|
34
|
+
|
35
|
+
require 'mountpoints/constants/constants.rb'
|
36
|
+
require 'mountpoints/toplevel_methods/toplevel_methods.rb'
|
37
|
+
require 'mountpoints/version/version.rb'
|
38
|
+
|
39
|
+
# ========================================================================= #
|
40
|
+
# === NAMESPACE
|
41
|
+
# ========================================================================= #
|
42
|
+
NAMESPACE = inspect
|
43
|
+
|
44
|
+
# ========================================================================= #
|
45
|
+
# === N
|
46
|
+
# ========================================================================= #
|
47
|
+
N = "\n"
|
48
|
+
|
49
|
+
# ========================================================================= #
|
50
|
+
# === LJUST
|
51
|
+
# ========================================================================= #
|
52
|
+
LJUST = 15
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === DF_COMMAND
|
56
|
+
# ========================================================================= #
|
57
|
+
DF_COMMAND = 'df -T -ah 2>&1'
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === DEBUG
|
61
|
+
#
|
62
|
+
# If true then we will debug this class.
|
63
|
+
# ========================================================================= #
|
64
|
+
DEBUG = false
|
65
|
+
|
66
|
+
# ========================================================================= #
|
67
|
+
# === initialize
|
68
|
+
# ========================================================================= #
|
69
|
+
def initialize(
|
70
|
+
commandline_arguments = nil,
|
71
|
+
run_already = true
|
72
|
+
)
|
73
|
+
reset
|
74
|
+
set_commandline_arguments(
|
75
|
+
commandline_arguments
|
76
|
+
)
|
77
|
+
if block_given?
|
78
|
+
yielded = yield
|
79
|
+
case yielded
|
80
|
+
# ===================================================================== #
|
81
|
+
# === :be_quiet
|
82
|
+
# ===================================================================== #
|
83
|
+
when :be_quiet
|
84
|
+
set_be_quiet
|
85
|
+
run_already = true
|
86
|
+
# ===================================================================== #
|
87
|
+
# === :be_verbose
|
88
|
+
# ===================================================================== #
|
89
|
+
when :be_verbose,
|
90
|
+
:be_extra_verbose
|
91
|
+
set_be_verbose
|
92
|
+
run_already = true
|
93
|
+
# ===================================================================== #
|
94
|
+
# === :normal_verbosity
|
95
|
+
# ===================================================================== #
|
96
|
+
when :normal_verbosity # Simply pass through here. No longer that important as of 2022, though.
|
97
|
+
end
|
98
|
+
end
|
99
|
+
if commandline_arguments.is_a? Array
|
100
|
+
case commandline_arguments.first
|
101
|
+
# ===================================================================== #
|
102
|
+
# === --extra-verbose
|
103
|
+
# ===================================================================== #
|
104
|
+
when /^-?-?extra(-|_)?verbose$/
|
105
|
+
set_be_verbose
|
106
|
+
run_already = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
run if run_already
|
110
|
+
end
|
111
|
+
|
112
|
+
# ========================================================================= #
|
113
|
+
# === reset (reset tag)
|
114
|
+
# ========================================================================= #
|
115
|
+
def reset
|
116
|
+
# ======================================================================= #
|
117
|
+
# === @namespace
|
118
|
+
# ======================================================================= #
|
119
|
+
@namespace = NAMESPACE
|
120
|
+
# ======================================================================= #
|
121
|
+
# === @internal_hash
|
122
|
+
# ======================================================================= #
|
123
|
+
@internal_hash = {}
|
124
|
+
# ======================================================================= #
|
125
|
+
# === :array_available_mountpoints
|
126
|
+
# ======================================================================= #
|
127
|
+
@internal_hash[:array_available_mountpoints] = []
|
128
|
+
# ======================================================================= #
|
129
|
+
# === :use_colours
|
130
|
+
# ======================================================================= #
|
131
|
+
@internal_hash[:use_colours] = true
|
132
|
+
# ======================================================================= #
|
133
|
+
# === :be_verbose
|
134
|
+
# ======================================================================= #
|
135
|
+
@internal_hash[:be_verbose] = true
|
136
|
+
# ======================================================================= #
|
137
|
+
# === :command_to_run
|
138
|
+
#
|
139
|
+
# This is the command that will be run via ``.
|
140
|
+
# ======================================================================= #
|
141
|
+
@internal_hash[:command_to_run] = ''.dup
|
142
|
+
end
|
143
|
+
|
144
|
+
# ========================================================================= #
|
145
|
+
# === set_command_to_run
|
146
|
+
# ========================================================================= #
|
147
|
+
def set_command_to_run(
|
148
|
+
i = :default_command_on_linux
|
149
|
+
)
|
150
|
+
case i
|
151
|
+
# ======================================================================= #
|
152
|
+
# === :default_command_on_linux
|
153
|
+
# ======================================================================= #
|
154
|
+
when :default_command_on_linux,
|
155
|
+
:default
|
156
|
+
i = DF_COMMAND
|
157
|
+
end
|
158
|
+
@internal_hash[:command_to_run] = i
|
159
|
+
end
|
160
|
+
|
161
|
+
# ========================================================================= #
|
162
|
+
# === run_the_system_command
|
163
|
+
# ========================================================================= #
|
164
|
+
def run_the_system_command
|
165
|
+
return `#{command_to_run?}`
|
166
|
+
end
|
167
|
+
|
168
|
+
# ========================================================================= #
|
169
|
+
# === command_to_run?
|
170
|
+
# ========================================================================= #
|
171
|
+
def command_to_run?
|
172
|
+
@internal_hash[:command_to_run]
|
173
|
+
end
|
174
|
+
|
175
|
+
# ========================================================================= #
|
176
|
+
# === set_be_quiet
|
177
|
+
# ========================================================================= #
|
178
|
+
def set_be_quiet
|
179
|
+
@internal_hash[:be_verbose] = false
|
180
|
+
end
|
181
|
+
|
182
|
+
# ========================================================================= #
|
183
|
+
# === set_be_verbose
|
184
|
+
# ========================================================================= #
|
185
|
+
def set_be_verbose
|
186
|
+
@internal_hash[:be_verbose] = true
|
187
|
+
end
|
188
|
+
|
189
|
+
# ========================================================================= #
|
190
|
+
# === set_commandline_arguments
|
191
|
+
# ========================================================================= #
|
192
|
+
def set_commandline_arguments(i = '')
|
193
|
+
i = [i].flatten.compact
|
194
|
+
@commandline_arguments = i
|
195
|
+
end
|
196
|
+
|
197
|
+
# ========================================================================= #
|
198
|
+
# === commandline_arguments?
|
199
|
+
# ========================================================================= #
|
200
|
+
def commandline_arguments?
|
201
|
+
@commandline_arguments
|
202
|
+
end
|
203
|
+
|
204
|
+
# ========================================================================= #
|
205
|
+
# === first_argument?
|
206
|
+
# ========================================================================= #
|
207
|
+
def first_argument?
|
208
|
+
@commandline_arguments.first
|
209
|
+
end; alias first? first_argument? # === first?
|
210
|
+
|
211
|
+
# ========================================================================= #
|
212
|
+
# === available_mountpoints?
|
213
|
+
# ========================================================================= #
|
214
|
+
def available_mountpoints?
|
215
|
+
@internal_hash[:array_available_mountpoints]
|
216
|
+
end; alias mountpoints? available_mountpoints? # === mountpoints?
|
217
|
+
alias array? available_mountpoints? # === array?
|
218
|
+
alias array_mountpoints? available_mountpoints? # === array_mountpoints?
|
219
|
+
alias array_mountpoints available_mountpoints? # === array_mountpoints
|
220
|
+
alias mounted_here available_mountpoints? # === mounted_here
|
221
|
+
alias result? available_mountpoints? # === result?
|
222
|
+
alias result available_mountpoints? # === result
|
223
|
+
|
224
|
+
# ========================================================================= #
|
225
|
+
# === add_this_entry_to_the_available_mountpoints (add tag)
|
226
|
+
# ========================================================================= #
|
227
|
+
def add_this_entry_to_the_available_mountpoints(i)
|
228
|
+
unless i == '/' # Ignore the root entry here.
|
229
|
+
unless i.end_with? '/'
|
230
|
+
i = i.dup if i.frozen?
|
231
|
+
i << '/'
|
232
|
+
end
|
233
|
+
@internal_hash[:array_available_mountpoints] << i
|
234
|
+
end
|
235
|
+
end; alias add add_this_entry_to_the_available_mountpoints # === add
|
236
|
+
|
237
|
+
# ========================================================================= #
|
238
|
+
# === e
|
239
|
+
# ========================================================================= #
|
240
|
+
def e(i = '')
|
241
|
+
if use_colours?
|
242
|
+
::Colours.e(i)
|
243
|
+
else
|
244
|
+
puts i
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
# ========================================================================= #
|
249
|
+
# === debug?
|
250
|
+
# ========================================================================= #
|
251
|
+
def debug?
|
252
|
+
DEBUG
|
253
|
+
end
|
254
|
+
|
255
|
+
# ========================================================================= #
|
256
|
+
# === rds
|
257
|
+
# ========================================================================= #
|
258
|
+
def rds(i)
|
259
|
+
i.squeeze('/')
|
260
|
+
end
|
261
|
+
|
262
|
+
# ========================================================================= #
|
263
|
+
# === use_colours?
|
264
|
+
# ========================================================================= #
|
265
|
+
def use_colours?
|
266
|
+
@internal_hash[:use_colours]
|
267
|
+
end
|
268
|
+
|
269
|
+
# ========================================================================= #
|
270
|
+
# === be_verbose?
|
271
|
+
# ========================================================================= #
|
272
|
+
def be_verbose?
|
273
|
+
@internal_hash[:be_verbose]
|
274
|
+
end; alias be_extra_verbose? be_verbose? # === be_extra_verbose?
|
275
|
+
|
276
|
+
# ========================================================================= #
|
277
|
+
# === report_the_determined_mountpoints (report tag)
|
278
|
+
# ========================================================================= #
|
279
|
+
def report_the_determined_mountpoints(
|
280
|
+
available_mountpoints = available_mountpoints?,
|
281
|
+
be_verbose = be_verbose?
|
282
|
+
)
|
283
|
+
if be_verbose
|
284
|
+
if available_mountpoints.empty?
|
285
|
+
opn; e 'No mount point was found. Thus, it is assumed '\
|
286
|
+
'that no USB device is currently mounted.'
|
287
|
+
else # else report the mountpoints here.
|
288
|
+
opn; e 'The following mount points were found:'
|
289
|
+
e
|
290
|
+
available_mountpoints.each {|entry|
|
291
|
+
e " #{forestgreen(entry)}".ljust(LJUST)
|
292
|
+
}
|
293
|
+
e
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end; alias report report_the_determined_mountpoints # === report
|
297
|
+
alias report_colourized_result report_the_determined_mountpoints # === report_colourized_result
|
298
|
+
alias report_result report_the_determined_mountpoints # === report_result
|
299
|
+
alias determine_result report_the_determined_mountpoints # === determine_result
|
300
|
+
|
301
|
+
# ========================================================================= #
|
302
|
+
# === forestgreen
|
303
|
+
# ========================================================================= #
|
304
|
+
def forestgreen(i)
|
305
|
+
return ::Colours.forestgreen(i) if use_colours?
|
306
|
+
return i
|
307
|
+
end
|
308
|
+
|
309
|
+
# ========================================================================= #
|
310
|
+
# === determine_the_available_mountpoints
|
311
|
+
#
|
312
|
+
# This method will branch into a linux-specific clause and a
|
313
|
+
# windows-specific clause.
|
314
|
+
# ========================================================================= #
|
315
|
+
def determine_the_available_mountpoints
|
316
|
+
clear_the_mountpoints # First clear the mountpoints - we don't want old entries.
|
317
|
+
# ======================================================================= #
|
318
|
+
# === Handle windows next
|
319
|
+
# ======================================================================= #
|
320
|
+
if use_windows?
|
321
|
+
determine_the_mountpoints_on_windows
|
322
|
+
# ======================================================================= #
|
323
|
+
# === Handle linux next
|
324
|
+
# ======================================================================= #
|
325
|
+
else # This branch is specifically for linux
|
326
|
+
determine_the_mountpoints_on_linux
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
# ========================================================================= #
|
331
|
+
# === determine_the_mountpoints_on_linux (linux tag, linux branch)
|
332
|
+
# ========================================================================= #
|
333
|
+
def determine_the_mountpoints_on_linux
|
334
|
+
set_command_to_run(:default_command_on_linux)
|
335
|
+
if debug?
|
336
|
+
e "Now running this command: #{sfancy(command_to_run?)}"
|
337
|
+
end
|
338
|
+
result = run_the_system_command.split(N)
|
339
|
+
# ======================================================================= #
|
340
|
+
# Next parse it for results such as:
|
341
|
+
#
|
342
|
+
# /dev/sdc1 2048 3907029134 3907027087 1.8T Linux filesystem
|
343
|
+
# /dev/sdc1 459G 436G 0 100% /Mount/USB3
|
344
|
+
#
|
345
|
+
# This stands for:
|
346
|
+
#
|
347
|
+
# Device Start End Sectors Size Type
|
348
|
+
#
|
349
|
+
# ======================================================================= #
|
350
|
+
matches = result.select {|entry| entry =~ /^\/dev\// } # Or check for: '/dev/sd'
|
351
|
+
matches.each {|line|
|
352
|
+
splitted = line.split(' ').map(&:strip)
|
353
|
+
last_entry = splitted.last.strip
|
354
|
+
add_this_entry_to_the_available_mountpoints(last_entry)
|
355
|
+
}
|
356
|
+
end
|
357
|
+
|
358
|
+
# ========================================================================= #
|
359
|
+
# === set_mountpoints
|
360
|
+
#
|
361
|
+
# Note that all directories will be stored via a trailing '/' in this
|
362
|
+
# method.
|
363
|
+
# ========================================================================= #
|
364
|
+
def set_mountpoints(i)
|
365
|
+
i = [i].flatten.compact
|
366
|
+
i.map! {|entry|
|
367
|
+
if File.directory? entry
|
368
|
+
entry = rds(entry)
|
369
|
+
end
|
370
|
+
if File.directory?(entry) and !entry.end_with?('/')
|
371
|
+
entry << '/'
|
372
|
+
end
|
373
|
+
entry
|
374
|
+
}
|
375
|
+
@internal_hash[:array_mountpoints] = i
|
376
|
+
end
|
377
|
+
|
378
|
+
# ========================================================================= #
|
379
|
+
# === clear_the_mountpoints
|
380
|
+
# ========================================================================= #
|
381
|
+
def clear_the_mountpoints
|
382
|
+
@internal_hash[:array_available_mountpoints].clear
|
383
|
+
end
|
384
|
+
|
385
|
+
# ========================================================================= #
|
386
|
+
# === use_windows?
|
387
|
+
# ========================================================================= #
|
388
|
+
def use_windows?
|
389
|
+
return Mountpoints.use_windows?
|
390
|
+
end; alias is_on_windows? use_windows? # === is_on_windows?
|
391
|
+
|
392
|
+
# ========================================================================= #
|
393
|
+
# === determine_the_mountpoints_on_windows
|
394
|
+
# ========================================================================= #
|
395
|
+
def determine_the_mountpoints_on_windows
|
396
|
+
result = ''.dup
|
397
|
+
set_command_to_run(WINDOWS_COMMAND1)
|
398
|
+
result << `#{command_to_run?}`.split(N).reject {|line| line.to_s.strip.empty? }.join(N) # This will keep the main result.
|
399
|
+
set_command_to_run(WINDOWS_COMMAND2)
|
400
|
+
result << `#{command_to_run?}`.split(N).reject {|line| line.to_s.strip.empty? }.join(N) # This will keep the main result.
|
401
|
+
result = result.split(N).reverse.select {|entry|
|
402
|
+
entry.include? ':'
|
403
|
+
}.map {|entry|
|
404
|
+
entry.strip
|
405
|
+
}.reject {|entry| entry.include? 'DeviceID' } .uniq
|
406
|
+
set_mountpoints(result)
|
407
|
+
end
|
408
|
+
|
409
|
+
# ========================================================================= #
|
410
|
+
# === run (run tag)
|
411
|
+
# ========================================================================= #
|
412
|
+
def run
|
413
|
+
determine_the_available_mountpoints
|
414
|
+
report_the_determined_mountpoints
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
|
419
|
+
if __FILE__ == $PROGRAM_NAME
|
420
|
+
Mountpoints.new(ARGV)
|
421
|
+
# To query the mountpoints do:
|
422
|
+
#
|
423
|
+
# pp _.mountpoints?
|
424
|
+
#
|
425
|
+
end # rawmountpoints
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'mountpoints/constants/constants.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class Mountpoints
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === WINDOWS_COMMAND1
|
11
|
+
# ========================================================================= #
|
12
|
+
WINDOWS_COMMAND1 = 'wmic logicaldisk where "drivetype=3" get DeviceID'
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === WINDOWS_COMMAND2
|
16
|
+
# ========================================================================= #
|
17
|
+
WINDOWS_COMMAND2 = 'wmic logicaldisk where "drivetype=2" get DeviceID'
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'mountpoints/toplevel_methods/toplevel_methods.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class Mountpoints # === Mountpoints
|
8
|
+
|
9
|
+
require 'mountpoints/constants/constants.rb'
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === Mountpoints.use_windows?
|
13
|
+
#
|
14
|
+
# This boolean method will return true if we are on windows, and
|
15
|
+
# false otherwise.
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.use_windows?
|
18
|
+
case RUBY_PLATFORM
|
19
|
+
when /win/,
|
20
|
+
/mingw/,
|
21
|
+
/msys/
|
22
|
+
return true
|
23
|
+
else
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end; self.instance_eval { alias is_on_windows? use_windows? } # === Mountpoints.is_on_windows?
|
27
|
+
|
28
|
+
# ========================================================================= #
|
29
|
+
# === Mountpoints[]
|
30
|
+
#
|
31
|
+
# This method will return an Array, such as:
|
32
|
+
#
|
33
|
+
# ["/Mount/USB1/"]
|
34
|
+
#
|
35
|
+
# It will be quiet by default.
|
36
|
+
|
37
|
+
# Usage example:
|
38
|
+
#
|
39
|
+
# x = Mountpoints # => ["/Mount/USB3/"]
|
40
|
+
#
|
41
|
+
# ========================================================================= #
|
42
|
+
def self.[](i = ARGV)
|
43
|
+
new(i) { :be_quiet }.array_mountpoints # The Array will be returned as well.
|
44
|
+
end
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === Mountpoints.array?
|
48
|
+
#
|
49
|
+
# This variant will only return the mountpoints, as Array.
|
50
|
+
# ========================================================================= #
|
51
|
+
def self.array?(i = ARGV)
|
52
|
+
new(i) { :be_quiet }.array?
|
53
|
+
end; self.instance_eval { alias mountpoints_as_array array? } # === Mountpoints.mountpoints_as_array
|
54
|
+
self.instance_eval { alias array_mountpoints array? } # === Mountpoints.mountpoints_as_array
|
55
|
+
self.instance_eval { alias mountpoints? array? } # === Mountpoints.mountpoints_as_array
|
56
|
+
|
57
|
+
# ========================================================================= #
|
58
|
+
# === Mountpoints.report
|
59
|
+
# ========================================================================= #
|
60
|
+
def self.report
|
61
|
+
new(i) { :be_verbose }
|
62
|
+
end; self.instance_eval { alias show report } # === Mountpoints.show
|
63
|
+
|
64
|
+
# ========================================================================= #
|
65
|
+
# === Mountpoints.is_any_mountpoint_available?
|
66
|
+
# ========================================================================= #
|
67
|
+
def self.is_any_mountpoint_available?
|
68
|
+
!new { :be_quiet }.array_mountpoints.empty?
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === Mountpoints.windows1
|
73
|
+
# ========================================================================= #
|
74
|
+
def self.windows1(cmd_to_run = WINDOWS_COMMAND1)
|
75
|
+
e cmd_to_run
|
76
|
+
`#{cmd_to_run}`
|
77
|
+
end
|
78
|
+
|
79
|
+
# ========================================================================= #
|
80
|
+
# === Mountpoints.windows2
|
81
|
+
# ========================================================================= #
|
82
|
+
def self.windows2(cmd_to_run = WINDOWS_COMMAND2)
|
83
|
+
e cmd_to_run
|
84
|
+
`#{cmd_to_run}`
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
if __FILE__ == $PROGRAM_NAME
|
90
|
+
require 'mountpoints/class/mountpoints.rb'
|
91
|
+
pp Mountpoints.array?
|
92
|
+
end # rawmountpoints
|
@@ -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.2.3'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === Mountpoints::LAST_UPDATE
|
14
|
+
# ========================================================================= #
|
15
|
+
LAST_UPDATE = '15.05.2022'
|
11
16
|
|
12
17
|
end
|
data/lib/mountpoints.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require 'mountpoints/mountpoints.rb'
|
1
|
+
require 'mountpoints/class/mountpoints.rb'
|
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/toplevel_methods/misc.rb'
|
5
6
|
|
6
7
|
Gem::Specification.new { |s|
|
7
8
|
|
@@ -11,42 +12,36 @@ Gem::Specification.new { |s|
|
|
11
12
|
|
12
13
|
DESCRIPTION = <<-EOF
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
gem that I can use, rather than having to parse the
|
18
|
-
output of "fdisk -l".
|
15
|
+
This class will yield to the user the information about all
|
16
|
+
mountpoints on a Linux System. It may also work on Windows,
|
17
|
+
by making use of "wmic".
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
Please do note that on Linux this works only via "fdisk",
|
20
|
+
and even then not always. This gem was initially started
|
21
|
+
as a "throw-away" gem that can be used quickly, rather
|
22
|
+
than having to parse the output of "fdisk -l" manually
|
23
|
+
(or by eyes only).
|
23
24
|
|
24
|
-
|
25
|
+
Also do note that we are only interested in external devices
|
26
|
+
that are mounted that way, NOT other mountpoints. The
|
27
|
+
reason for this is because this gem here serves as a
|
28
|
+
foundation for backing up data onto external USB devices.
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
If you have specific suggestions to make this gem more
|
30
|
-
useful for others, please drop me an email at:
|
31
|
-
|
32
|
-
shevegen@gmail.com
|
33
|
-
|
34
|
-
Thank you.
|
30
|
+
For more information pertaining to this gem have a look
|
31
|
+
at the official homepage of this gem.
|
35
32
|
|
36
33
|
EOF
|
34
|
+
|
37
35
|
s.summary = DESCRIPTION
|
38
36
|
s.description = DESCRIPTION
|
39
|
-
|
40
|
-
s.
|
41
|
-
|
42
|
-
s.
|
43
|
-
s.
|
44
|
-
s.
|
45
|
-
|
46
|
-
s.
|
47
|
-
s.homepage = 'http://rubygems.org/gems/mountpoints'
|
48
|
-
|
49
|
-
s.required_ruby_version = '>= '+RUBY_VERSION
|
37
|
+
|
38
|
+
s.authors = ['Robert A. Heiler']
|
39
|
+
s.email = Roebe.email?
|
40
|
+
s.files = Dir['**/*']
|
41
|
+
s.license = 'GPL-2.0'
|
42
|
+
s.homepage = 'https://rubygems.org/gems/mountpoints'
|
43
|
+
|
44
|
+
s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
|
50
45
|
s.required_rubygems_version = '>= '+Gem::VERSION
|
51
46
|
s.rubygems_version = '>= '+Gem::VERSION
|
52
47
|
|
data/test/testing_mountpoints.rb
CHANGED
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.2.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,44 @@ dependencies:
|
|
40
40
|
version: '0'
|
41
41
|
description: |2+
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
gem that I can use, rather than having to parse the
|
47
|
-
output of "fdisk -l".
|
43
|
+
This class will yield to the user the information about all
|
44
|
+
mountpoints on a Linux System. It may also work on Windows,
|
45
|
+
by making use of "wmic".
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
Please do note that on Linux this works only via "fdisk",
|
48
|
+
and even then not always. This gem was initially started
|
49
|
+
as a "throw-away" gem that can be used quickly, rather
|
50
|
+
than having to parse the output of "fdisk -l" manually
|
51
|
+
(or by eyes only).
|
52
52
|
|
53
|
-
|
53
|
+
Also do note that we are only interested in external devices
|
54
|
+
that are mounted that way, NOT other mountpoints. The
|
55
|
+
reason for this is because this gem here serves as a
|
56
|
+
foundation for backing up data onto external USB devices.
|
54
57
|
|
55
|
-
|
56
|
-
|
58
|
+
For more information pertaining to this gem have a look
|
59
|
+
at the official homepage of this gem.
|
57
60
|
|
58
|
-
|
59
|
-
useful for others, please drop me an email at:
|
60
|
-
|
61
|
-
shevegen@gmail.com
|
62
|
-
|
63
|
-
Thank you.
|
64
|
-
|
65
|
-
email: shevegen@gmail.com
|
61
|
+
email: shevy@inbox.lt
|
66
62
|
executables: []
|
67
63
|
extensions: []
|
68
64
|
extra_rdoc_files: []
|
69
65
|
files:
|
70
|
-
-
|
66
|
+
- README.md
|
67
|
+
- bin/mountpoints
|
68
|
+
- doc/README.gen
|
71
69
|
- lib/mountpoints.rb
|
72
|
-
- lib/mountpoints/mountpoints.rb
|
70
|
+
- lib/mountpoints/class/mountpoints.rb
|
71
|
+
- lib/mountpoints/constants/constants.rb
|
72
|
+
- lib/mountpoints/toplevel_methods/toplevel_methods.rb
|
73
73
|
- lib/mountpoints/version/version.rb
|
74
74
|
- mountpoints.gemspec
|
75
75
|
- test/testing_mountpoints.rb
|
76
|
-
homepage:
|
76
|
+
homepage: https://rubygems.org/gems/mountpoints
|
77
77
|
licenses:
|
78
78
|
- GPL-2.0
|
79
79
|
metadata: {}
|
80
|
-
post_install_message:
|
80
|
+
post_install_message:
|
81
81
|
rdoc_options: []
|
82
82
|
require_paths:
|
83
83
|
- lib
|
@@ -85,21 +85,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 2.
|
88
|
+
version: 2.5.8
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
91
|
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 3.
|
93
|
+
version: 3.3.13
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
96
|
-
signing_key:
|
95
|
+
rubygems_version: 3.3.13
|
96
|
+
signing_key:
|
97
97
|
specification_version: 4
|
98
|
-
summary:
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
for
|
98
|
+
summary: This class will yield to the user the information about all mountpoints on
|
99
|
+
a Linux System. It may also work on Windows, by making use of "wmic". Please do
|
100
|
+
note that on Linux this works only via "fdisk", and even then not always. This gem
|
101
|
+
was initially started as a "throw-away" gem that can be used quickly, rather than
|
102
|
+
having to parse the output of "fdisk -l" manually (or by eyes only). Also do note
|
103
|
+
that we are only interested in external devices that are mounted that way, NOT other
|
104
|
+
mountpoints. The reason for this is because this gem here serves as a foundation
|
105
|
+
for backing up data onto external USB devices. For more information pertaining
|
106
|
+
to this gem have a look at the official homepage of this gem.
|
105
107
|
test_files: []
|
108
|
+
...
|
data/USAGE.md
DELETED
@@ -1,251 +0,0 @@
|
|
1
|
-
#!/System/Index/bin/ruby -w
|
2
|
-
# Encoding: ISO-8859-1
|
3
|
-
# frozen_string_literal: true
|
4
|
-
# =========================================================================== #
|
5
|
-
# === Mountpoints
|
6
|
-
#
|
7
|
-
# This class will scan for all mounted USB-devices first. Then it will
|
8
|
-
# try to find a specific entry, if you give an argument to .find().
|
9
|
-
#
|
10
|
-
# Arguments to find() could be:
|
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.
|
20
|
-
#
|
21
|
-
# Usage examples:
|
22
|
-
# Mountpoints.new
|
23
|
-
# Mountpoints.show
|
24
|
-
# Mountpoints.is_any_mountpoint_available?
|
25
|
-
# =========================================================================== #
|
26
|
-
# require 'mountpoints'
|
27
|
-
# =========================================================================== #
|
28
|
-
begin
|
29
|
-
require 'colours'
|
30
|
-
rescue LoadError; end
|
31
|
-
require 'opn'
|
32
|
-
require 'mountpoints/version/version.rb'
|
33
|
-
|
34
|
-
class Mountpoints # === Mountpoints.new
|
35
|
-
|
36
|
-
include Colours
|
37
|
-
|
38
|
-
N = "\n"
|
39
|
-
|
40
|
-
# ========================================================================= #
|
41
|
-
# === LJUST
|
42
|
-
# ========================================================================= #
|
43
|
-
LJUST = 15
|
44
|
-
|
45
|
-
# ========================================================================= #
|
46
|
-
# === DF_COMMAND
|
47
|
-
# ========================================================================= #
|
48
|
-
DF_COMMAND = 'df -T -ah'
|
49
|
-
|
50
|
-
# ========================================================================= #
|
51
|
-
# === FDISK_COMMAND
|
52
|
-
# ========================================================================= #
|
53
|
-
FDISK_COMMAND = 'fdisk -l'
|
54
|
-
|
55
|
-
# ========================================================================= #
|
56
|
-
# === DEBUG
|
57
|
-
# ========================================================================= #
|
58
|
-
DEBUG = false # If true then we will debug.
|
59
|
-
|
60
|
-
# ========================================================================= #
|
61
|
-
# === initialize
|
62
|
-
#
|
63
|
-
# If the first argument is :be_extra_verbose then we will show more
|
64
|
-
# information.
|
65
|
-
# ========================================================================= #
|
66
|
-
def initialize(
|
67
|
-
run_already = true
|
68
|
-
)
|
69
|
-
reset
|
70
|
-
case run_already
|
71
|
-
when :be_extra_verbose
|
72
|
-
@be_extra_verbose = true
|
73
|
-
run_already = true
|
74
|
-
when :normal_verbosity # Simply pass through here.
|
75
|
-
end
|
76
|
-
run if run_already
|
77
|
-
end
|
78
|
-
|
79
|
-
# ========================================================================= #
|
80
|
-
# === reset
|
81
|
-
# ========================================================================= #
|
82
|
-
def reset
|
83
|
-
@be_extra_verbose = false
|
84
|
-
@command_to_run = DF_COMMAND # This command will be run.
|
85
|
-
end
|
86
|
-
|
87
|
-
# ========================================================================= #
|
88
|
-
# === set_result
|
89
|
-
# ========================================================================= #
|
90
|
-
def set_result(i)
|
91
|
-
if i.is_a? String
|
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
|
107
|
-
end
|
108
|
-
|
109
|
-
# ========================================================================= #
|
110
|
-
# === rds
|
111
|
-
# ========================================================================= #
|
112
|
-
def rds(i)
|
113
|
-
i.squeeze('/')
|
114
|
-
end
|
115
|
-
|
116
|
-
# ========================================================================= #
|
117
|
-
# === determine_mountpoints
|
118
|
-
#
|
119
|
-
# The @array_mountpoints will keep all directory-names with a trailing
|
120
|
-
# '/'. In other words, the mountpoints will be stored there.
|
121
|
-
# ========================================================================= #
|
122
|
-
def determine_mountpoints
|
123
|
-
@array_mountpoints = @result.map {|entry| entry.first }
|
124
|
-
end
|
125
|
-
|
126
|
-
# ========================================================================= #
|
127
|
-
# === determine_result
|
128
|
-
#
|
129
|
-
# This method will run the df-command.
|
130
|
-
# ========================================================================= #
|
131
|
-
def determine_result
|
132
|
-
if debug?
|
133
|
-
e "Now running this command: #{sfancy(@command_to_run)}"
|
134
|
-
end
|
135
|
-
@result = `#{@command_to_run}`.split(N) # This will keep the main result.
|
136
|
-
_ = @result.reject {|entry| !entry.include? '/Mount' }.
|
137
|
-
reject {|entry| !entry.include? 'USB' }
|
138
|
-
# ======================================================================= #
|
139
|
-
# At this point, we have only the entries that have /Mount as part
|
140
|
-
# of their name.
|
141
|
-
# ======================================================================= #
|
142
|
-
_.map! {|entry|
|
143
|
-
splitted = entry.split(' ')
|
144
|
-
# filesize =
|
145
|
-
entry = [ splitted[-1], splitted.first, splitted[2] ]
|
146
|
-
}
|
147
|
-
set_result _ # Now contains the mountpoints here.
|
148
|
-
end
|
149
|
-
|
150
|
-
# ========================================================================= #
|
151
|
-
# === report_result
|
152
|
-
# ========================================================================= #
|
153
|
-
def report_result
|
154
|
-
if @be_extra_verbose
|
155
|
-
if result?.empty?
|
156
|
-
opn; e 'We did not find any mount point. We conclude that '\
|
157
|
-
'no USB device is mounted.'
|
158
|
-
else
|
159
|
-
opn; e 'We did find these mount points:'
|
160
|
-
e
|
161
|
-
result?.each {|line|
|
162
|
-
filesize = line[2]
|
163
|
-
name_of_device = line[1]
|
164
|
-
mounted_here = line[0]
|
165
|
-
efancy ' '+mounted_here.ljust(LJUST)+' '+
|
166
|
-
swarn(name_of_device)+' '+
|
167
|
-
'('+Colours.green(filesize)+')'
|
168
|
-
}
|
169
|
-
e
|
170
|
-
end
|
171
|
-
else # else we report "normally.
|
172
|
-
e result?.join(N)
|
173
|
-
end
|
174
|
-
end; alias report_colourized_result report_result # Not sure what to do with this here.
|
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
|
196
|
-
|
197
|
-
# ========================================================================= #
|
198
|
-
# === run (run tag)
|
199
|
-
# ========================================================================= #
|
200
|
-
def run
|
201
|
-
determine_result
|
202
|
-
end
|
203
|
-
|
204
|
-
# ========================================================================= #
|
205
|
-
# === Mountpoints.report
|
206
|
-
# ========================================================================= #
|
207
|
-
def self.report
|
208
|
-
Mountpoints[:be_extra_verbose]
|
209
|
-
end
|
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
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
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
|
-
end
|
246
|
-
|
247
|
-
if __FILE__ == $PROGRAM_NAME
|
248
|
-
_ = Mountpoints.new :be_extra_verbose
|
249
|
-
_.report_result
|
250
|
-
# p _.result?
|
251
|
-
end # mountpoints
|