stat_file 1.0.19
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 +7 -0
- data/lib/stat_file/colours.rb +37 -0
- data/lib/stat_file/stat_file.rb +273 -0
- data/lib/stat_file/version/version.rb +17 -0
- data/lib/stat_file.rb +1 -0
- data/stat_file.gemspec +40 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1cac1d11cc3b1f2ce17e44e8eb2738c8b461d3cabc8c8582a3d572933db395a3
|
4
|
+
data.tar.gz: 297c2a359c301c58a216574dddd4f27c09354dee3f53bd744abc4a01c1ff30ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a73ad6f879f0331905fd3eb4945de41f373dc5ba5028e106f414a0021f17b46415c43cd3c57f051312c4bd7569814c3a0cd128bea815762ac1705bdeb3b58825
|
7
|
+
data.tar.gz: ac2060ef70a496ef060a370a28f403b44f194a9a88505dc7d91a6003038cc9637372e06c99a118162d4968a7f3218a628fcb1f195a2fd28eccd72070e52e024e
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'stat_file/colours.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class StatFile
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'colours/autogenerated/html_colours_methods.rb'
|
11
|
+
rescue LoadError; end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'colours/html_colours/html_colours.rb'
|
15
|
+
include ::Colours::HtmlColours
|
16
|
+
rescue LoadError; end
|
17
|
+
|
18
|
+
begin
|
19
|
+
require 'colours'
|
20
|
+
include ::Colours
|
21
|
+
rescue LoadError; end
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === steelblue
|
25
|
+
# ========================================================================= #
|
26
|
+
def steelblue(i = '')
|
27
|
+
::Colours::HtmlColoursMethods.steelblue(i)
|
28
|
+
end
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === rev
|
32
|
+
# ========================================================================= #
|
33
|
+
def rev
|
34
|
+
::Colours.rev
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === StatFile
|
6
|
+
#
|
7
|
+
# require 'stat_file/stat_file.rb'
|
8
|
+
# =========================================================================== #
|
9
|
+
# Bug:
|
10
|
+
# The access entry is not completely correct - the number is ok but
|
11
|
+
# the rxw--- format is wrong.
|
12
|
+
# =========================================================================== #
|
13
|
+
class StatFile
|
14
|
+
|
15
|
+
require 'etc'
|
16
|
+
|
17
|
+
require 'stat_file/colours.rb'
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'opn'
|
21
|
+
rescue LoadError; end
|
22
|
+
|
23
|
+
N = "\n" unless defined? N
|
24
|
+
|
25
|
+
# ========================================================================= #
|
26
|
+
# === SHALL_WE_DEBUG
|
27
|
+
# ========================================================================= #
|
28
|
+
SHALL_WE_DEBUG = false unless defined? SHALL_WE_DEBUG
|
29
|
+
|
30
|
+
# ========================================================================= #
|
31
|
+
# === RED_ON_BLACK
|
32
|
+
# ========================================================================= #
|
33
|
+
RED_ON_BLACK = "\e[31;48m" unless defined? RED_ON_BLACK
|
34
|
+
|
35
|
+
# ========================================================================= #
|
36
|
+
# === REVERT
|
37
|
+
# ========================================================================= #
|
38
|
+
REVERT = '\e[0m' unless defined? REVERT
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === initialize
|
42
|
+
# ========================================================================= #
|
43
|
+
def initialize(
|
44
|
+
this_file,
|
45
|
+
be_verbose = true,
|
46
|
+
run_already = true
|
47
|
+
)
|
48
|
+
reset # This must be called before set_be_verbose()
|
49
|
+
be_verbose = false if be_verbose == :dont_be_verbose
|
50
|
+
set_be_verbose if be_verbose
|
51
|
+
set_file(this_file)
|
52
|
+
run if run_already
|
53
|
+
end
|
54
|
+
|
55
|
+
# ========================================================================= #
|
56
|
+
# === reset (reset tag)
|
57
|
+
# ========================================================================= #
|
58
|
+
def reset
|
59
|
+
# ======================================================================= #
|
60
|
+
# === @be_verbose
|
61
|
+
# ======================================================================= #
|
62
|
+
@be_verbose = false # Default.
|
63
|
+
# ======================================================================= #
|
64
|
+
# === @debug
|
65
|
+
# ======================================================================= #
|
66
|
+
@debug = SHALL_WE_DEBUG
|
67
|
+
# ======================================================================= #
|
68
|
+
# === @padding_left
|
69
|
+
# ======================================================================= #
|
70
|
+
@padding_left = ' '
|
71
|
+
end
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === file?
|
75
|
+
# ========================================================================= #
|
76
|
+
def file?
|
77
|
+
@file
|
78
|
+
end
|
79
|
+
|
80
|
+
# ========================================================================= #
|
81
|
+
# === set_file
|
82
|
+
# ========================================================================= #
|
83
|
+
def set_file(i, get_rid_of_slashdot = false)
|
84
|
+
if get_rid_of_slashdot
|
85
|
+
i.delete!('/') if i.include? '/' # Since 06.12.2011 we try to get rid of possible '/' in the string.
|
86
|
+
end
|
87
|
+
i = i.first if i.is_a? Array
|
88
|
+
i = i.to_s.dup
|
89
|
+
@file = i
|
90
|
+
end
|
91
|
+
|
92
|
+
# ========================================================================= #
|
93
|
+
# === set_be_verbose
|
94
|
+
# ========================================================================= #
|
95
|
+
def set_be_verbose
|
96
|
+
@be_verbose = true
|
97
|
+
end
|
98
|
+
|
99
|
+
# ========================================================================= #
|
100
|
+
# === stat_file
|
101
|
+
# ========================================================================= #
|
102
|
+
def stat_file(f = @file)
|
103
|
+
if f.to_s.empty?
|
104
|
+
opn; e 'No such file could be found. Perhaps you '
|
105
|
+
opn; e 'forgot to pass in a valid filename?'
|
106
|
+
end
|
107
|
+
if f
|
108
|
+
if f.is_a? Array
|
109
|
+
f.each { |this_file| stat_file(this_file) }
|
110
|
+
else
|
111
|
+
@is_symlink = File.symlink?(f) ? true : false
|
112
|
+
if @debug
|
113
|
+
e "Debugging in stat_file.rb: Is `#{f}` a symlink or not? #{@is_symlink}"
|
114
|
+
end
|
115
|
+
if is_on_roebe? and !File.exist?(f)
|
116
|
+
begin
|
117
|
+
require 'beautiful_url'
|
118
|
+
f = BeautifulUrl[f]
|
119
|
+
f = f.first if f.is_a? Array
|
120
|
+
rescue LoadError; end
|
121
|
+
end
|
122
|
+
string = ' File: `'+f+"`"
|
123
|
+
# =================================================================== #
|
124
|
+
# If it is a symlink we have to check whether the target exists
|
125
|
+
# or not.
|
126
|
+
# =================================================================== #
|
127
|
+
if @is_symlink
|
128
|
+
f = File.readlink(f)
|
129
|
+
string << rev+' → `'+f+"`"
|
130
|
+
end
|
131
|
+
# =================================================================== #
|
132
|
+
# Now we can retrieve the information.
|
133
|
+
# =================================================================== #
|
134
|
+
if File.exist?(f)
|
135
|
+
_ = File.stat(f)
|
136
|
+
file_type = File.ftype(f)
|
137
|
+
case file_type
|
138
|
+
when 'directory'
|
139
|
+
target_type = 'directory'
|
140
|
+
when 'file'
|
141
|
+
target_type = 'regular file'
|
142
|
+
when 'symlink','link'
|
143
|
+
target_type = 'symlink'
|
144
|
+
end
|
145
|
+
# ================================================================= #
|
146
|
+
# Prepend a newline to it. I think it looks better that way.
|
147
|
+
# ================================================================= #
|
148
|
+
if are_the_colours_available?
|
149
|
+
use_this_regex = /`(.+)`/ # See: https://rubular.com/r/EnETP5vkCYgGEB
|
150
|
+
string.prepend(rev)
|
151
|
+
string.sub!(
|
152
|
+
use_this_regex,
|
153
|
+
steelblue('\1')
|
154
|
+
)
|
155
|
+
end
|
156
|
+
@result = N+string+N # reset again here.
|
157
|
+
@result << "#{rev}#{@padding_left}"+' Size: '+
|
158
|
+
(@size = _.size.to_s).to_s+' Blocks: '+_.blocks.to_s+' '+target_type.to_s+N
|
159
|
+
@result << @padding_left+
|
160
|
+
return_device_string+' Inode: '+_.ino.to_s+N
|
161
|
+
begin
|
162
|
+
gid = File.stat(f).gid.to_s
|
163
|
+
gid_name = Etc.getgrgid(File.stat(f).gid).name # i.e. "root"
|
164
|
+
uid = File.stat(f).uid.to_s
|
165
|
+
uid_name = Etc.getpwuid(File.stat(f).uid).name # i.e. "root"
|
166
|
+
# =============================================================== #
|
167
|
+
# Next we will add the access entry. The Access entry may
|
168
|
+
# have a leading 0 or 1.
|
169
|
+
# =============================================================== #
|
170
|
+
access_mode = File.stat(f).mode.to_s(8)[-4,4] # Get the last 4 chars only.
|
171
|
+
access_entry = 'Access: ('+access_mode+'/-rwxr-xr-x) Uid: ( '+uid+'/ '+uid_name+') Gid: ( '+gid+'/ '+gid_name+')'
|
172
|
+
@result << @padding_left+access_entry+N
|
173
|
+
rescue Exception => error; pp error; end
|
174
|
+
@result << "#{@padding_left}Created at: #{File.ctime(f)}#{N}"
|
175
|
+
@result << "#{@padding_left}Last accessed: #{File.atime(f)}#{N}"
|
176
|
+
@result << "#{@padding_left}Last modified: #{File.mtime(f)}#{N}"
|
177
|
+
@result << N
|
178
|
+
e @result if @be_verbose
|
179
|
+
else # Else the file does not exit.
|
180
|
+
if be_verbose?
|
181
|
+
opn; ewarn "No target file exists at: `#{sfile(f)}"
|
182
|
+
# File.readlink(@file)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
# ========================================================================= #
|
190
|
+
# === result?
|
191
|
+
# ========================================================================= #
|
192
|
+
def result?
|
193
|
+
@result
|
194
|
+
end; alias result result? # === result
|
195
|
+
alias text? result? # === text?
|
196
|
+
|
197
|
+
# ========================================================================= #
|
198
|
+
# === be_verbose?
|
199
|
+
# ========================================================================= #
|
200
|
+
def be_verbose?
|
201
|
+
@be_verbose
|
202
|
+
end
|
203
|
+
|
204
|
+
# ========================================================================= #
|
205
|
+
# === size?
|
206
|
+
# ========================================================================= #
|
207
|
+
def size?
|
208
|
+
@size
|
209
|
+
end; alias size size? # === size()
|
210
|
+
|
211
|
+
# ========================================================================= #
|
212
|
+
# === is_on_roebe?
|
213
|
+
# ========================================================================= #
|
214
|
+
def is_on_roebe?
|
215
|
+
ENV['IS_ROEBE'].to_s == '1'
|
216
|
+
end
|
217
|
+
|
218
|
+
# ========================================================================= #
|
219
|
+
# === are_the_colours_available?
|
220
|
+
# ========================================================================= #
|
221
|
+
def are_the_colours_available?
|
222
|
+
Object.const_defined? :Colours
|
223
|
+
end
|
224
|
+
|
225
|
+
# ========================================================================= #
|
226
|
+
# === return_device_string
|
227
|
+
#
|
228
|
+
# This method is assumed to return an entry such as the following one:
|
229
|
+
#
|
230
|
+
# Device: 801h/2049d
|
231
|
+
#
|
232
|
+
# Note that this may differ from systemd to non-systemd systems.
|
233
|
+
# ========================================================================= #
|
234
|
+
def return_device_string
|
235
|
+
result = 'Device: '.dup
|
236
|
+
# ======================================================================= #
|
237
|
+
# First, find out the current device:
|
238
|
+
# ======================================================================= #
|
239
|
+
base_dir = File.dirname(file?)
|
240
|
+
cmd = `df #{base_dir} 2>&1` # The 2>&1 is necessary for windows.
|
241
|
+
device_number = cmd.split(N)[1].split(' ')[0]
|
242
|
+
# ======================================================================= #
|
243
|
+
# device_number now has something like /dev/sda1
|
244
|
+
# In order to obtain the major and minor version,
|
245
|
+
# we must do this:
|
246
|
+
# ======================================================================= #
|
247
|
+
cmd = "ls -al #{device_number} 2>&1"
|
248
|
+
major_minor = `#{cmd}` # To get major/minor = 8/1
|
249
|
+
# ======================================================================= #
|
250
|
+
# This may however had fail. We assume that it will fail when it
|
251
|
+
# includes the string "by-uuid".
|
252
|
+
# ======================================================================= #
|
253
|
+
applied_match = major_minor.match(/disk (\d, \d)/)
|
254
|
+
if applied_match # Protect against nil values.
|
255
|
+
major, minor = applied_match[1].split(',').map(&:strip)
|
256
|
+
major_and_minor = "#{major}0#{minor}"
|
257
|
+
result << major_and_minor+'h/'+major_and_minor.to_i(16).to_s+'d '
|
258
|
+
end
|
259
|
+
result
|
260
|
+
end
|
261
|
+
|
262
|
+
# ========================================================================= #
|
263
|
+
# === run
|
264
|
+
# ========================================================================= #
|
265
|
+
def run
|
266
|
+
stat_file
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
if __FILE__ == $PROGRAM_NAME
|
272
|
+
StatFile.new(ARGV.first, true)
|
273
|
+
end # sfile $SYSBIN/ruby
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
class StatFile
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === VERSION
|
9
|
+
# ========================================================================= #
|
10
|
+
VERSION = '1.0.19'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === LAST_UPDATE
|
14
|
+
# ========================================================================= #
|
15
|
+
LAST_UPDATE = '17.01.2024'
|
16
|
+
|
17
|
+
end
|
data/lib/stat_file.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'stat_file/stat_file.rb'
|
data/stat_file.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Gemspec for Project StatFile.
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'stat_file/version/version.rb'
|
5
|
+
require 'roebe'
|
6
|
+
|
7
|
+
Gem::Specification.new { |s|
|
8
|
+
|
9
|
+
s.name = 'stat_file'
|
10
|
+
s.version = StatFile::VERSION
|
11
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
12
|
+
|
13
|
+
s.summary = <<-EOF
|
14
|
+
|
15
|
+
This library is called stat_file. It allows you to
|
16
|
+
do basic stat functionality, like the Unix Tool.
|
17
|
+
|
18
|
+
EOF
|
19
|
+
|
20
|
+
s.description = <<-EOF
|
21
|
+
|
22
|
+
This library is called stat_file. It allows you to
|
23
|
+
do basic stat functionality, like the Unix Tool.
|
24
|
+
|
25
|
+
EOF
|
26
|
+
|
27
|
+
s.authors = ['Robert A. Heiler']
|
28
|
+
s.email = Roebe.email?
|
29
|
+
s.files = Dir['**/*']
|
30
|
+
s.license = 'MIT'
|
31
|
+
s.homepage = 'https://rubygems.org/gems/stat_file'
|
32
|
+
|
33
|
+
s.required_ruby_version = '>= '+RUBY_VERSION
|
34
|
+
s.required_rubygems_version = '>= '+Gem::VERSION
|
35
|
+
s.rubygems_version = '>= '+Gem::VERSION
|
36
|
+
|
37
|
+
s.add_dependency 'opn'
|
38
|
+
s.add_dependency 'colours'
|
39
|
+
|
40
|
+
}
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stat_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.19
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert A. Heiler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: opn
|
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: colours
|
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 library is called stat_file. It allows you to
|
44
|
+
do basic stat functionality, like the Unix Tool.
|
45
|
+
|
46
|
+
email: shevy@inbox.lt
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- lib/stat_file.rb
|
52
|
+
- lib/stat_file/colours.rb
|
53
|
+
- lib/stat_file/stat_file.rb
|
54
|
+
- lib/stat_file/version/version.rb
|
55
|
+
- stat_file.gemspec
|
56
|
+
homepage: https://rubygems.org/gems/stat_file
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.3.0
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 3.5.3
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.5.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: This library is called stat_file. It allows you to do basic stat functionality,
|
79
|
+
like the Unix Tool.
|
80
|
+
test_files: []
|
81
|
+
...
|