stat_file 1.0.13

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of stat_file might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 63e270a21b1fac3d14e6b2f3059b2d2af31518b439e04540678db3faeabe2100
4
+ data.tar.gz: ae4524bc6b5758bbacf88b9f9700d7e2a6a5b1895cab75ccb34d5e5562cfa11f
5
+ SHA512:
6
+ metadata.gz: 771dfcc38b1a5fe2e9350855b5113699fb94feb290326e07fe337cdc60c6513adab7a757fb52762082b336e1c0f1e59aaccbce1db904167099ad8ee79adfeef8
7
+ data.tar.gz: 34643c90bd90270b043d6f15296d9688bf8a9e377dba647f90480142e1c2243614d5b3f8759701bd31822fc21fe6c6cd4f896227b8938d03ddddc785972fca57
data/lib/stat_file.rb ADDED
@@ -0,0 +1 @@
1
+ require 'stat_file/stat_file.rb'
@@ -0,0 +1,237 @@
1
+ #!/System/Index/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
+ require 'etc'
14
+ begin
15
+ require 'colours'
16
+ rescue LoadError; end
17
+ require 'opn'
18
+
19
+ class StatFile
20
+
21
+ include Colours
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
57
+ # ========================================================================= #
58
+ def reset
59
+ @be_verbose = false # Default.
60
+ @debug = SHALL_WE_DEBUG
61
+ @padding_left = ' '
62
+ end
63
+
64
+ # ========================================================================= #
65
+ # === file?
66
+ # ========================================================================= #
67
+ def file?
68
+ @file
69
+ end
70
+
71
+ # ========================================================================= #
72
+ # === set_file
73
+ # ========================================================================= #
74
+ def set_file(i, get_rid_of_slashdot = false)
75
+ if get_rid_of_slashdot
76
+ i.delete!('/') if i.include? '/' # Since 06.12.2011 we try to get rid of possible '/' in the string.
77
+ end
78
+ i = i.first if i.is_a? Array
79
+ i = i.to_s.dup
80
+ @file = i
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === set_be_verbose
85
+ # ========================================================================= #
86
+ def set_be_verbose
87
+ @be_verbose = true
88
+ end
89
+
90
+ # ========================================================================= #
91
+ # === is_on_roebe?
92
+ # ========================================================================= #
93
+ def is_on_roebe?
94
+ ENV['IS_ROEBE'].to_s == '1'
95
+ end
96
+
97
+ # ========================================================================= #
98
+ # === stat_file
99
+ # ========================================================================= #
100
+ def stat_file(f = @file)
101
+ if f.to_s.empty?
102
+ opn; e 'No such file could be found. Perhaps you '
103
+ opn; e 'forgot to pass in a valid filename?'
104
+ end
105
+ if f
106
+ if f.is_a? Array
107
+ f.each { |this_file| stat_file(this_file) }
108
+ else
109
+ @is_symlink = File.symlink?(f) ? true : false
110
+ if @debug
111
+ e "Debugging in stat_file.rb: Is `#{f}` a symlink or not? #{@is_symlink}"
112
+ end
113
+ if is_on_roebe? and !File.exist?(f)
114
+ begin
115
+ require 'beautiful_url'
116
+ f = BeautifulUrl[f]
117
+ f = f.first if f.is_a? Array
118
+ rescue LoadError; end
119
+ end
120
+ string = ' File: `'+f+"'"
121
+ # =================================================================== #
122
+ # If it is a symlink we have to check whether the target exists
123
+ # or not.
124
+ # =================================================================== #
125
+ if @is_symlink
126
+ f = File.readlink(f)
127
+ string << ' -> `'+f+"'"
128
+ end
129
+ # =================================================================== #
130
+ # Now we can retrieve the information.
131
+ # =================================================================== #
132
+ if File.exist?(f)
133
+ _ = File.stat(f)
134
+ file_type = File.ftype(f)
135
+ case file_type
136
+ when 'directory'
137
+ target_type = 'directory'
138
+ when 'file'
139
+ target_type = 'regular file'
140
+ when 'symlink','link'
141
+ target_type = 'symlink'
142
+ end
143
+ # Prepend a newline to it. I think it looks better that way.
144
+ @result = N+string+N # reset again here.
145
+ @result << @padding_left+' Size: '+
146
+ (@size = _.size.to_s).to_s+' Blocks: '+_.blocks.to_s+' '+target_type.to_s+N
147
+ @result << @padding_left+return_device_string+' Inode: '+_.ino.to_s+N
148
+ begin
149
+ gid = File.stat(f).gid.to_s
150
+ gid_name = Etc.getgrgid(File.stat(f).gid).name # i.e. "root"
151
+ uid = File.stat(f).uid.to_s
152
+ uid_name = Etc.getpwuid(File.stat(f).uid).name # i.e. "root"
153
+ # =============================================================== #
154
+ # Next we will add the access entry. The Access entry may
155
+ # have a leading 0 or 1.
156
+ # =============================================================== #
157
+ access_mode = File.stat(f).mode.to_s(8)[-4,4] # Get the last 4 chars only.
158
+ access_entry = 'Access: ('+access_mode+'/-rwxr-xr-x) Uid: ( '+uid+'/ '+uid_name+') Gid: ( '+gid+'/ '+gid_name+')'
159
+ @result << @padding_left+access_entry+N
160
+ rescue Exception => error; pp error; end
161
+ @result << @padding_left+'Created at: '+File.ctime(f).to_s+N
162
+ @result << @padding_left+'Last accessed: '+File.atime(f).to_s+N
163
+ @result << @padding_left+'Last modified: '+File.mtime(f).to_s+N
164
+ e @result if @be_verbose
165
+ else # Else the file does not exit.
166
+ if be_verbose?
167
+ opn; ewarn 'But target file `'+sfile(f)+
168
+ swarn('` does not exist.') # File.readlink(@file)
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end; alias run stat_file
174
+
175
+ # ========================================================================= #
176
+ # === result?
177
+ # ========================================================================= #
178
+ def result?
179
+ @result
180
+ end; alias result result? # === result
181
+
182
+ # ========================================================================= #
183
+ # === be_verbose?
184
+ # ========================================================================= #
185
+ def be_verbose?
186
+ @be_verbose
187
+ end
188
+
189
+ # ========================================================================= #
190
+ # === size?
191
+ # ========================================================================= #
192
+ def size?
193
+ @size
194
+ end; alias size size? # === size()
195
+
196
+ # ========================================================================= #
197
+ # === return_device_string
198
+ #
199
+ # This method is assumed to return an entry such as the following one:
200
+ #
201
+ # Device: 801h/2049d
202
+ #
203
+ # Note that this may differ from systemd to non-systemd systems.
204
+ # ========================================================================= #
205
+ def return_device_string
206
+ result = 'Device: '
207
+ # ======================================================================= #
208
+ # First, find out the current device:
209
+ # ======================================================================= #
210
+ base_dir = File.dirname(file?)
211
+ cmd = `df #{base_dir}`
212
+ device_number = cmd.split(N)[1].split(' ')[0]
213
+ # ======================================================================= #
214
+ # device_number now has something like /dev/sda1
215
+ # In order to obtain the major and minor version,
216
+ # we must do this:
217
+ # ======================================================================= #
218
+ cmd = "ls -al #{device_number}"
219
+ major_minor = `#{cmd}` # To get major/minor = 8/1
220
+ # ======================================================================= #
221
+ # This may however had fail. We assume that it will fail when it
222
+ # includes the string "by-uuid".
223
+ # ======================================================================= #
224
+ applied_match = major_minor.match(/disk (\d, \d)/)
225
+ if applied_match # Protect against nil values.
226
+ major, minor = applied_match[1].split(',').map(&:strip)
227
+ major_and_minor = major+'0'+minor
228
+ result << major_and_minor+'h/'+major_and_minor.to_i(16).to_s+'d '
229
+ end
230
+ result
231
+ end
232
+
233
+ end
234
+
235
+ if __FILE__ == $PROGRAM_NAME
236
+ StatFile.new(ARGV.first, true)
237
+ end # sfile $SYSBIN/ruby
data/stat_file.gemspec ADDED
@@ -0,0 +1,51 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project StatFile.
3
+ # =========================================================================== #
4
+ Gem::Specification.new { |s|
5
+
6
+ s.name = 'stat_file'
7
+ s.version = '1.0.13'
8
+ s.date = Time.now.strftime('%Y-%m-%d')
9
+
10
+ s.summary = <<-EOF
11
+
12
+ This library is called stat_file. It allows you to
13
+ do basic stat functionality, like the Unix Tool.
14
+
15
+ If you have specific suggestions to make this gem more
16
+ useful for others, please drop me an email at:
17
+
18
+ shevegen@gmail.com
19
+
20
+ Thank you.
21
+
22
+ EOF
23
+
24
+ s.description = <<-EOF
25
+
26
+ This library is called stat_file. It allows you to
27
+ do basic stat functionality, like the Unix Tool.
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
+
38
+ s.authors = ['Robert A. Heiler']
39
+ s.email = 'shevegen@gmail.com'
40
+ s.files = Dir['**/*']
41
+ s.license = 'GPL-2.0'
42
+ s.homepage = 'http://rubygems.org/gems/stat_file'
43
+
44
+ s.required_ruby_version = '>= '+RUBY_VERSION
45
+ s.required_rubygems_version = '>= '+Gem::VERSION
46
+ s.rubygems_version = '>= '+Gem::VERSION
47
+
48
+ s.add_dependency 'opn'
49
+ s.add_dependency 'colours'
50
+
51
+ }
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stat_file
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-07-24 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
+ If you have specific suggestions to make this gem more
47
+ useful for others, please drop me an email at:
48
+
49
+ shevegen@gmail.com
50
+
51
+ Thank you.
52
+
53
+ email: shevegen@gmail.com
54
+ executables: []
55
+ extensions: []
56
+ extra_rdoc_files: []
57
+ files:
58
+ - lib/stat_file.rb
59
+ - lib/stat_file/stat_file.rb
60
+ - stat_file.gemspec
61
+ homepage: http://rubygems.org/gems/stat_file
62
+ licenses:
63
+ - GPL-2.0
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.6.3
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 3.0.4
79
+ requirements: []
80
+ rubygems_version: 3.0.4
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: 'This library is called stat_file. It allows you to do basic stat functionality,
84
+ like the Unix Tool. If you have specific suggestions to make this gem more useful
85
+ for others, please drop me an email at: shevegen@gmail.com Thank you.'
86
+ test_files: []