mountpoints 1.0.13

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6ff0a164ec1b673135a911e81a3ec5648cff9b736f297aa087160245e13093c
4
+ data.tar.gz: c61a3240c419aa4598240dfc95e36db9ce372e3369b6eb014aabd04f2c81ea46
5
+ SHA512:
6
+ metadata.gz: 1e70743c2d4769ae3e9a211324c49ef298f8f430708ab57ac6d018b657543323ad915dd416416747ed5e62e23a7dc7841b58aed400e2548fe636be1eb42dbda8
7
+ data.tar.gz: 34c0c875dd9411458d76cde4a5f905475aae8173fe1fadd03b29048efd8b213def357ffedcdaf796623609a34ef71621415623ddebfee558b1647bf663ab469d
data/USAGE.md ADDED
@@ -0,0 +1,14 @@
1
+ = Usage of this Library
2
+
3
+ == Requiring it
4
+
5
+ require 'mountpoints'
6
+
7
+ == Using it in a project
8
+
9
+ _ = Mountpoints.new("science_news")
10
+ _.run
11
+
12
+ or
13
+
14
+ Mountpoints.show
@@ -0,0 +1 @@
1
+ require 'mountpoints/mountpoints.rb'
@@ -0,0 +1,251 @@
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
@@ -0,0 +1,12 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: ISO-8859-1
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ class Mountpoints
6
+
7
+ # ========================================================================= #
8
+ # === Mountpoints::VERSION
9
+ # ========================================================================= #
10
+ VERSION = '1.0.13'
11
+
12
+ end
@@ -0,0 +1,59 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Mountpoints.
3
+ # =========================================================================== #
4
+ require 'mountpoints/version/version.rb'
5
+
6
+ Gem::Specification.new { |s|
7
+
8
+ s.name = 'mountpoints'
9
+ s.version = Mountpoints::VERSION
10
+ s.date = Time.now.strftime('%Y-%m-%d')
11
+
12
+ DESCRIPTION = <<-EOF
13
+
14
+ This class will give you back all mountpoints on a Linux
15
+ System. Please do note that this works only via "fdisk",
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".
19
+
20
+ Also do note that we are only interested in external
21
+ devices that are mounted that way, NOT other
22
+ mountpoints.
23
+
24
+ To use this in Ruby, do:
25
+
26
+ require 'mountpoints'
27
+ Mountpoints.show
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.
35
+
36
+ EOF
37
+ s.summary = DESCRIPTION
38
+ s.description = DESCRIPTION
39
+
40
+ s.extra_rdoc_files = %w()
41
+
42
+ s.authors = ['Robert A. Heiler']
43
+ s.email = 'shevegen@gmail.com'
44
+ s.files = Dir['**/*']
45
+ s.files << 'USAGE.md'
46
+ s.license = 'GPL-2.0'
47
+ s.homepage = 'http://rubygems.org/gems/mountpoints'
48
+
49
+ s.required_ruby_version = '>= '+RUBY_VERSION
50
+ s.required_rubygems_version = '>= '+Gem::VERSION
51
+ s.rubygems_version = '>= '+Gem::VERSION
52
+
53
+ # ========================================================================= #
54
+ # Dependencies
55
+ # ========================================================================= #
56
+ s.add_dependency 'colours'
57
+ s.add_dependency 'opn'
58
+
59
+ }
@@ -0,0 +1,4 @@
1
+ require 'pp'
2
+ require 'mountpoints'
3
+
4
+ pp Mountpoints[]
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mountpoints
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.13
5
+ platform: ruby
6
+ authors:
7
+ - Robert A. Heiler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colours
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |2+
42
+
43
+ This class will give you back all mountpoints on a Linux
44
+ System. Please do note that this works only via "fdisk",
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".
48
+
49
+ Also do note that we are only interested in external
50
+ devices that are mounted that way, NOT other
51
+ mountpoints.
52
+
53
+ To use this in Ruby, do:
54
+
55
+ require 'mountpoints'
56
+ Mountpoints.show
57
+
58
+ If you have specific suggestions to make this gem more
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
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - USAGE.md
71
+ - lib/mountpoints.rb
72
+ - lib/mountpoints/mountpoints.rb
73
+ - lib/mountpoints/version/version.rb
74
+ - mountpoints.gemspec
75
+ - test/testing_mountpoints.rb
76
+ homepage: http://rubygems.org/gems/mountpoints
77
+ licenses:
78
+ - GPL-2.0
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.6.3
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 3.0.3
94
+ requirements: []
95
+ rubygems_version: 3.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: 'This class will give you back all mountpoints on a Linux System. Please
99
+ do note that this works only via "fdisk", and even then not always. It was mostly
100
+ a "throw-away" gem that I can use, rather than having to parse the output of "fdisk
101
+ -l". Also do note that we are only interested in external devices that are mounted
102
+ that way, NOT other mountpoints. To use this in Ruby, do: require ''mountpoints''
103
+ Mountpoints.show If you have specific suggestions to make this gem more useful
104
+ for others, please drop me an email at: shevegen@gmail.com Thank you.'
105
+ test_files: []