directory_paradise 1.4.5
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/README.md +228 -0
- data/bin/show_directory_content +7 -0
- data/directory_paradise.gemspec +45 -0
- data/doc/README.gen +185 -0
- data/doc/todo/todo.md +4 -0
- data/lib/directory_paradise/base/base.rb +228 -0
- data/lib/directory_paradise/base/colours.rb +196 -0
- data/lib/directory_paradise/constants/newline.rb +14 -0
- data/lib/directory_paradise/content/constants.rb +23 -0
- data/lib/directory_paradise/content/content.rb +682 -0
- data/lib/directory_paradise/project/project.rb +22 -0
- data/lib/directory_paradise/report/menu.rb +329 -0
- data/lib/directory_paradise/report/report.rb +1874 -0
- data/lib/directory_paradise/requires/require_class_content.rb +7 -0
- data/lib/directory_paradise/requires/require_class_report.rb +7 -0
- data/lib/directory_paradise/requires/require_the_directory_paradise_project.rb +10 -0
- data/lib/directory_paradise/sdc.rb +24 -0
- data/lib/directory_paradise/to_human_readable/to_human_readable.rb +98 -0
- data/lib/directory_paradise/version/version.rb +19 -0
- data/lib/directory_paradise/yaml/colours_for_bytes_values.yml +14 -0
- data/lib/directory_paradise.rb +1 -0
- data/test/testing_class_content.rb +16 -0
- data/test/testing_class_report.rb +40 -0
- data/test/testing_toplevel_methods.rb +14 -0
- metadata +105 -0
@@ -0,0 +1,228 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === DirectoryParadise::Base
|
6
|
+
#
|
7
|
+
# Usage example:
|
8
|
+
#
|
9
|
+
# DirectoryParadise::Base.new(ARGV)
|
10
|
+
#
|
11
|
+
# =========================================================================== #
|
12
|
+
# require 'directory_paradise/base/base.rb'
|
13
|
+
# =========================================================================== #
|
14
|
+
require 'directory_paradise/constants/newline.rb'
|
15
|
+
|
16
|
+
module DirectoryParadise
|
17
|
+
|
18
|
+
class Base
|
19
|
+
|
20
|
+
alias e puts
|
21
|
+
alias ee print
|
22
|
+
|
23
|
+
require 'directory_paradise/base/colours.rb'
|
24
|
+
require 'directory_paradise/project/project.rb'
|
25
|
+
require 'directory_paradise/to_human_readable/to_human_readable.rb'
|
26
|
+
|
27
|
+
# ========================================================================= #
|
28
|
+
# === is_on_windows?
|
29
|
+
# ========================================================================= #
|
30
|
+
def is_on_windows?
|
31
|
+
if RUBY_PLATFORM.include?('win') or # if on windows.
|
32
|
+
RUBY_PLATFORM.include?('mingw')
|
33
|
+
return true
|
34
|
+
end
|
35
|
+
return false # ← Otherwise we are evidently NOT on windows, if we reach this point here.
|
36
|
+
end
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === rds
|
40
|
+
# ========================================================================= #
|
41
|
+
def rds(i)
|
42
|
+
i.squeeze '/'
|
43
|
+
end
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === register_sigint
|
47
|
+
# ========================================================================= #
|
48
|
+
def register_sigint
|
49
|
+
Signal.trap('SIGINT') { exit }
|
50
|
+
end
|
51
|
+
|
52
|
+
# ========================================================================= #
|
53
|
+
# === return_chmod_value_of_this_file
|
54
|
+
# ========================================================================= #
|
55
|
+
def return_chmod_value_of_this_file(i)
|
56
|
+
if File.exist? i
|
57
|
+
File.stat(i).mode.to_s(8).split('')[-4..-1].join # => "0755"
|
58
|
+
else
|
59
|
+
'0000'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# ========================================================================= #
|
64
|
+
# === set_commandline_arguments
|
65
|
+
# ========================================================================= #
|
66
|
+
def set_commandline_arguments(i = '')
|
67
|
+
i = [i].flatten.compact
|
68
|
+
@commandline_arguments = i
|
69
|
+
end
|
70
|
+
|
71
|
+
# ========================================================================= #
|
72
|
+
# === commandline_arguments?
|
73
|
+
# ========================================================================= #
|
74
|
+
def commandline_arguments?
|
75
|
+
@commandline_arguments
|
76
|
+
end
|
77
|
+
|
78
|
+
# ========================================================================= #
|
79
|
+
# === commandline_arguments_starting_with_two_hyphens?
|
80
|
+
# ========================================================================= #
|
81
|
+
def commandline_arguments_starting_with_two_hyphens?
|
82
|
+
@commandline_arguments.select {|entry| entry.start_with? '--' }
|
83
|
+
end
|
84
|
+
|
85
|
+
# ========================================================================= #
|
86
|
+
# === return_non_hyphen_entries_from
|
87
|
+
# ========================================================================= #
|
88
|
+
def return_non_hyphen_entries_from(i)
|
89
|
+
if i.is_a? Array
|
90
|
+
i.select {|entry| !entry.start_with?('--') }
|
91
|
+
else
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# ========================================================================= #
|
97
|
+
# === first_argument?
|
98
|
+
# ========================================================================= #
|
99
|
+
def first_argument?
|
100
|
+
@commandline_arguments.first
|
101
|
+
end; alias first? first_argument? # === first?
|
102
|
+
|
103
|
+
# ========================================================================= #
|
104
|
+
# === return_pwd
|
105
|
+
# ========================================================================= #
|
106
|
+
def return_pwd
|
107
|
+
"#{Dir.pwd}/".squeeze('/')
|
108
|
+
end
|
109
|
+
|
110
|
+
# ========================================================================= #
|
111
|
+
# === eliner
|
112
|
+
# ========================================================================= #
|
113
|
+
def eliner
|
114
|
+
e '―' * 80
|
115
|
+
end
|
116
|
+
|
117
|
+
# ========================================================================= #
|
118
|
+
# === liner
|
119
|
+
# ========================================================================= #
|
120
|
+
def liner # adds a line.
|
121
|
+
if block_given?
|
122
|
+
liner
|
123
|
+
yield
|
124
|
+
end
|
125
|
+
return ('*' * 80)+N
|
126
|
+
end
|
127
|
+
|
128
|
+
# ========================================================================= #
|
129
|
+
# === return_owner
|
130
|
+
#
|
131
|
+
# This method determines the owner of a file or directory.
|
132
|
+
# ========================================================================= #
|
133
|
+
def return_owner(
|
134
|
+
of_this_uid
|
135
|
+
)
|
136
|
+
_ = ''.dup # The _ is the return value.
|
137
|
+
# ======================================================================= #
|
138
|
+
# The next block of code can fail on windows, hence why this is
|
139
|
+
# wrapped carefully.
|
140
|
+
# ======================================================================= #
|
141
|
+
begin
|
142
|
+
if of_this_uid.is_a? String
|
143
|
+
of_this_uid = of_this_uid.to_i
|
144
|
+
end
|
145
|
+
# ===================================================================== #
|
146
|
+
# The next line must be rescued because the filesystem may be faulty.
|
147
|
+
# ===================================================================== #
|
148
|
+
begin
|
149
|
+
result_from_getpwuid = Etc.getpwuid(of_this_uid)
|
150
|
+
rescue TypeError
|
151
|
+
result_from_getpwuid = false
|
152
|
+
end
|
153
|
+
if result_from_getpwuid
|
154
|
+
_ << result_from_getpwuid.name
|
155
|
+
else
|
156
|
+
_ << '(unknown)'
|
157
|
+
end
|
158
|
+
rescue ArgumentError
|
159
|
+
_ << '(unknown)'
|
160
|
+
rescue Errno::ENOENT
|
161
|
+
_ << '(missing)'
|
162
|
+
end
|
163
|
+
_ # Return it here.
|
164
|
+
end; alias owner? return_owner # === owner?
|
165
|
+
|
166
|
+
# ========================================================================= #
|
167
|
+
# === return_assumed_modification_time
|
168
|
+
# ========================================================================= #
|
169
|
+
def return_assumed_modification_time(i)
|
170
|
+
month = Date::MONTHNAMES[i.month][0,3] # => "Jun"
|
171
|
+
"#{month} #{i.day.to_s.rjust(2)}"
|
172
|
+
end
|
173
|
+
|
174
|
+
# ========================================================================= #
|
175
|
+
# === clear_the_internal_hash
|
176
|
+
# ========================================================================= #
|
177
|
+
def clear_the_internal_hash
|
178
|
+
@internal_hash.clear
|
179
|
+
end; alias clear clear_the_internal_hash # === clear
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === to_human_readable
|
183
|
+
#
|
184
|
+
# The strange thing is, in bash, we seem to round up.
|
185
|
+
#
|
186
|
+
# How many MB (megabyte) are in 1 GB (gigabyte)? 1024.
|
187
|
+
# ========================================================================= #
|
188
|
+
def to_human_readable(i)
|
189
|
+
return DirectoryParadise.to_human_readable(i)
|
190
|
+
end
|
191
|
+
|
192
|
+
# ========================================================================= #
|
193
|
+
# === infer_the_namespace
|
194
|
+
#
|
195
|
+
# This will assume the true namespace from the inspectable name.
|
196
|
+
# ========================================================================= #
|
197
|
+
def infer_the_namespace
|
198
|
+
_ = inspect.to_s.delete('<')
|
199
|
+
if _.include? ' '
|
200
|
+
_ = _.split(' ').first.delete('#')
|
201
|
+
if _.include? ':'
|
202
|
+
_ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::')
|
203
|
+
end
|
204
|
+
elsif _.include? ':0x'
|
205
|
+
_ = _.split(':0x').first
|
206
|
+
end
|
207
|
+
@namespace = _.delete('#') # And assign it here.
|
208
|
+
end
|
209
|
+
|
210
|
+
# ========================================================================= #
|
211
|
+
# === namespace?
|
212
|
+
# ========================================================================= #
|
213
|
+
def namespace?
|
214
|
+
@namespace
|
215
|
+
end
|
216
|
+
|
217
|
+
# ========================================================================= #
|
218
|
+
# === print_the_namespace
|
219
|
+
# ========================================================================= #
|
220
|
+
def print_the_namespace
|
221
|
+
print namespace?
|
222
|
+
end
|
223
|
+
|
224
|
+
end; end
|
225
|
+
|
226
|
+
if __FILE__ == $PROGRAM_NAME
|
227
|
+
DirectoryParadise::Base.new(ARGV)
|
228
|
+
end # base.rb
|
@@ -0,0 +1,196 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'directory_paradise/base/colours.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module DirectoryParadise
|
8
|
+
|
9
|
+
class Base
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === do_use_colours
|
13
|
+
# ========================================================================= #
|
14
|
+
def do_use_colours(optional_args = '')
|
15
|
+
@internal_hash[:use_colours] = true # Whether we will use colours or whether we will not.
|
16
|
+
end; alias enable_colours do_use_colours # === enable_colours
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === use_colours?
|
20
|
+
#
|
21
|
+
# Whether we use colours or whether we don't.
|
22
|
+
# ========================================================================= #
|
23
|
+
def use_colours?(
|
24
|
+
i = @internal_hash[:use_colours]
|
25
|
+
)
|
26
|
+
return i
|
27
|
+
end
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === disable_colours
|
31
|
+
#
|
32
|
+
# Disable colours through this method.
|
33
|
+
# ========================================================================= #
|
34
|
+
def disable_colours
|
35
|
+
@internal_hash[:use_colours] = false
|
36
|
+
end
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === slink
|
40
|
+
# ========================================================================= #
|
41
|
+
def slink(i)
|
42
|
+
return Colours.slink(i) if use_colours?
|
43
|
+
return i
|
44
|
+
end
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === simp
|
48
|
+
# ========================================================================= #
|
49
|
+
def simp(i)
|
50
|
+
return Colours.simp(i) if use_colours?
|
51
|
+
return i
|
52
|
+
end
|
53
|
+
|
54
|
+
# ========================================================================= #
|
55
|
+
# === sfancy
|
56
|
+
# ========================================================================= #
|
57
|
+
def sfancy(i)
|
58
|
+
return Colours.sfancy(i) if use_colours?
|
59
|
+
return i
|
60
|
+
end
|
61
|
+
|
62
|
+
# ========================================================================= #
|
63
|
+
# === bold_yellow
|
64
|
+
# ========================================================================= #
|
65
|
+
def bold_yellow(i)
|
66
|
+
if use_colours?
|
67
|
+
Colours::BOLD_YELLOW+i+rev
|
68
|
+
else
|
69
|
+
i
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# ========================================================================= #
|
74
|
+
# === steelblue
|
75
|
+
# ========================================================================= #
|
76
|
+
def steelblue(i)
|
77
|
+
return Colours.steelblue(i) if use_colours?
|
78
|
+
i
|
79
|
+
end
|
80
|
+
|
81
|
+
# ========================================================================= #
|
82
|
+
# === springgreen
|
83
|
+
# ========================================================================= #
|
84
|
+
def springgreen(i)
|
85
|
+
return ::Colours.springgreen(i) if use_colours?
|
86
|
+
i
|
87
|
+
end
|
88
|
+
|
89
|
+
# ========================================================================= #
|
90
|
+
# === royalblue
|
91
|
+
# ========================================================================= #
|
92
|
+
def royalblue(i)
|
93
|
+
return ::Colours.royalblue(i) if use_colours?
|
94
|
+
i
|
95
|
+
end
|
96
|
+
|
97
|
+
# ========================================================================= #
|
98
|
+
# === lightblue
|
99
|
+
# ========================================================================= #
|
100
|
+
def lightblue(i)
|
101
|
+
return ::Colours.lightblue(i) if use_colours?
|
102
|
+
i
|
103
|
+
end
|
104
|
+
|
105
|
+
# ========================================================================= #
|
106
|
+
# === lightgreen
|
107
|
+
# ========================================================================= #
|
108
|
+
def lightgreen(i)
|
109
|
+
return ::Colours.lightgreen(i) if use_colours?
|
110
|
+
i
|
111
|
+
end
|
112
|
+
|
113
|
+
# ========================================================================= #
|
114
|
+
# === yellow
|
115
|
+
# ========================================================================= #
|
116
|
+
def yellow(i)
|
117
|
+
return ::Colours.yellow(i) if use_colours?
|
118
|
+
i
|
119
|
+
end
|
120
|
+
|
121
|
+
# ========================================================================= #
|
122
|
+
# === tomato
|
123
|
+
# ========================================================================= #
|
124
|
+
def tomato(i)
|
125
|
+
return ::Colours.tomato(i) if use_colours?
|
126
|
+
end
|
127
|
+
|
128
|
+
# ========================================================================= #
|
129
|
+
# === skyblue
|
130
|
+
# ========================================================================= #
|
131
|
+
def skyblue(i)
|
132
|
+
return ::Colours.skyblue(i) if use_colours?
|
133
|
+
end
|
134
|
+
|
135
|
+
# ========================================================================= #
|
136
|
+
# === olive
|
137
|
+
# ========================================================================= #
|
138
|
+
def olive(i)
|
139
|
+
return ::Colours.olive(i) if use_colours?
|
140
|
+
i
|
141
|
+
end
|
142
|
+
|
143
|
+
# ========================================================================= #
|
144
|
+
# === ssymlink
|
145
|
+
# ========================================================================= #
|
146
|
+
def ssymlink(i)
|
147
|
+
return ::Colours.ssymlink(i) if use_colours?
|
148
|
+
i
|
149
|
+
end
|
150
|
+
|
151
|
+
# ========================================================================= #
|
152
|
+
# === sdir
|
153
|
+
# ========================================================================= #
|
154
|
+
def sdir(i)
|
155
|
+
i = i.to_s.dup
|
156
|
+
# i << '/' unless i.end_with? '/'
|
157
|
+
# ^^^ Nope, that is bad.
|
158
|
+
i = rds(i) if i.include? '//'
|
159
|
+
i = Colours.sdir(i) if use_colours?
|
160
|
+
return i
|
161
|
+
end; alias colourize_directory sdir # === colourize_directory tag
|
162
|
+
|
163
|
+
# ========================================================================= #
|
164
|
+
# === sfile
|
165
|
+
#
|
166
|
+
# We will invoke this only when we have a file.
|
167
|
+
# ========================================================================= #
|
168
|
+
def sfile(i)
|
169
|
+
if use_colours?
|
170
|
+
splitted = i.split('/')
|
171
|
+
filename = Colours.sfile(splitted.pop) # Must come before dirname, due to .pop().
|
172
|
+
dirname = Colours.sdir( rds(splitted.join('/')+'/') )
|
173
|
+
unless show_leading_slash?
|
174
|
+
dirname = '' # Reset it in this case.
|
175
|
+
end
|
176
|
+
i = "#{dirname}#{filename}"
|
177
|
+
end
|
178
|
+
return i
|
179
|
+
end; alias colourize_file sfile # === colourize_file()
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === mediumpurple
|
183
|
+
# ========================================================================= #
|
184
|
+
def mediumpurple(i)
|
185
|
+
return ::Colours.mediumpurple(i) if use_colours?
|
186
|
+
return i
|
187
|
+
end
|
188
|
+
|
189
|
+
# ========================================================================= #
|
190
|
+
# === rev
|
191
|
+
# ========================================================================= #
|
192
|
+
def rev
|
193
|
+
return "\e[0;37m"
|
194
|
+
end
|
195
|
+
|
196
|
+
end; end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'directory_content/constants/newline.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
class DirectoryContent
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === N
|
11
|
+
# ========================================================================= #
|
12
|
+
N = "\n"
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'directory_paradise/content/constants.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'directory_paradise/base/base.rb'
|
8
|
+
|
9
|
+
module DirectoryParadise
|
10
|
+
|
11
|
+
class Content < Base
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === NAMESPACE
|
15
|
+
# ========================================================================= #
|
16
|
+
NAMESPACE = inspect
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === UNKNOWN
|
20
|
+
# ========================================================================= #
|
21
|
+
UNKNOWN = '(unknown)'
|
22
|
+
|
23
|
+
end; end
|