directory_paradise 1.4.4

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.

Potentially problematic release.


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

Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +213 -0
  3. data/bin/show_directory_content +7 -0
  4. data/directory_paradise.gemspec +45 -0
  5. data/doc/README.gen +185 -0
  6. data/doc/todo/todo.md +4 -0
  7. data/lib/directory_paradise/base/base.rb +195 -0
  8. data/lib/directory_paradise/base/colours.rb +196 -0
  9. data/lib/directory_paradise/constants/newline.rb +14 -0
  10. data/lib/directory_paradise/content/constants.rb +23 -0
  11. data/lib/directory_paradise/content/content.rb +682 -0
  12. data/lib/directory_paradise/project/project.rb +22 -0
  13. data/lib/directory_paradise/report/constants.rb +39 -0
  14. data/lib/directory_paradise/report/initialize.rb +75 -0
  15. data/lib/directory_paradise/report/menu.rb +329 -0
  16. data/lib/directory_paradise/report/misc.rb +675 -0
  17. data/lib/directory_paradise/report/obtain.rb +357 -0
  18. data/lib/directory_paradise/report/report.rb +527 -0
  19. data/lib/directory_paradise/report/reset.rb +174 -0
  20. data/lib/directory_paradise/requires/require_class_content.rb +7 -0
  21. data/lib/directory_paradise/requires/require_class_report.rb +7 -0
  22. data/lib/directory_paradise/requires/require_the_directory_paradise_project.rb +10 -0
  23. data/lib/directory_paradise/sdc.rb +24 -0
  24. data/lib/directory_paradise/to_human_readable/to_human_readable.rb +98 -0
  25. data/lib/directory_paradise/version/version.rb +19 -0
  26. data/lib/directory_paradise/yaml/colours_for_bytes_values.yml +14 -0
  27. data/lib/directory_paradise.rb +1 -0
  28. data/test/testing_class_content.rb +16 -0
  29. data/test/testing_class_report.rb +40 -0
  30. data/test/testing_toplevel_methods.rb +14 -0
  31. metadata +110 -0
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'directory_paradise/report/reset.rb'
6
+ # =========================================================================== #
7
+ require 'directory_paradise/base/base.rb'
8
+
9
+ module DirectoryParadise
10
+
11
+ class Report < Base # === DirectoryParadise::Report
12
+
13
+ # ========================================================================= #
14
+ # === reset (reset tag)
15
+ # ========================================================================= #
16
+ def reset
17
+ # ======================================================================= #
18
+ # === @internal_hash
19
+ # ======================================================================= #
20
+ @internal_hash = {}
21
+ # ======================================================================= #
22
+ # === :work_on_this_directory
23
+ # ======================================================================= #
24
+ @internal_hash[:work_on_this_directory] = return_pwd
25
+ # ======================================================================= #
26
+ # === :collapse
27
+ #
28
+ # Whether to collapse or not.
29
+ # ======================================================================= #
30
+ @internal_hash[:collapse] = false
31
+ # ======================================================================= #
32
+ # === :total_filesize
33
+ # ======================================================================= #
34
+ @internal_hash[:total_filesize] = 0 # Keep the total file size.
35
+ # ======================================================================= #
36
+ # === :report_filesize
37
+ #
38
+ # Tell the user the total filesize of the listing.
39
+ # ======================================================================= #
40
+ @internal_hash[:report_filesize] = true
41
+ # ======================================================================= #
42
+ # === :default_colour
43
+ # ======================================================================= #
44
+ @internal_hash[:default_colour] = :steelblue
45
+ # ======================================================================= #
46
+ # === :colourize_kb_and_mb
47
+ # ======================================================================= #
48
+ @internal_hash[:colourize_kb_and_mb] = COLOURIZE_KB_AND_MB
49
+ # ======================================================================= #
50
+ # === :threshold_for_file_size
51
+ #
52
+ # Only honoured if @truncate_long_file_names is true.
53
+ # ======================================================================= #
54
+ @internal_hash[:threshold_for_file_size] = FILE_SIZE_THRESHOLD
55
+ # ======================================================================= #
56
+ # === :show_group_information
57
+ # ======================================================================= #
58
+ @internal_hash[:show_group_information] = true
59
+ # ======================================================================= #
60
+ # === :show_modification_time
61
+ #
62
+ # if true then we show the modification time of the inode in question.
63
+ # ======================================================================= #
64
+ @internal_hash[:show_modification_time] = true
65
+ # ======================================================================= #
66
+ # === :use_colours
67
+ # ======================================================================= #
68
+ @internal_hash[:use_colours] = true
69
+ # ======================================================================= #
70
+ # === :show_leading_slash
71
+ #
72
+ # Show the leading slash in / directory.
73
+ # ======================================================================= #
74
+ @internal_hash[:show_leading_slash] = false
75
+ # ======================================================================= #
76
+ # === :sort_by
77
+ #
78
+ # This value must be nil initially, so that we will not do any
79
+ # sorting at all whatsoever.
80
+ # ======================================================================= #
81
+ @internal_hash[:sort_by] = nil
82
+ # ======================================================================= #
83
+ # === :show_only_symlinks
84
+ # ======================================================================= #
85
+ @internal_hash[:show_only_symlinks] = false
86
+ # ======================================================================= #
87
+ # === truncate_long_file_names
88
+ #
89
+ # If true, we truncate too-long file names.
90
+ # ======================================================================= #
91
+ @internal_hash[:truncate_long_file_names] = false
92
+ # ======================================================================= #
93
+ # === :show_simplified
94
+ #
95
+ # The following variable tells this class to keep a simplified directory
96
+ # layout.
97
+ #
98
+ # If it is true, then we only display a short variant of the file
99
+ # content.
100
+ # ======================================================================= #
101
+ @internal_hash[:show_simplified] = true
102
+ # ======================================================================= #
103
+ # === :colour_for_symlinks
104
+ # ======================================================================= #
105
+ @internal_hash[:colour_for_symlinks] = Colours.colour_for_symlinks
106
+ # ======================================================================= #
107
+ # === :show_size
108
+ #
109
+ # Whether to show the size of the entry at hand.
110
+ # ======================================================================= #
111
+ @internal_hash[:show_size] = true
112
+ # ======================================================================= #
113
+ # === :colourize_kb_and_mb
114
+ # ======================================================================= #
115
+ @internal_hash[:colourize_kb_and_mb] = true
116
+ # ======================================================================= #
117
+ # === :show_header
118
+ # ======================================================================= #
119
+ @internal_hash[:show_header] = true
120
+ # ======================================================================= #
121
+ # === :show_index
122
+ #
123
+ # Whether to show a leading index or not. I like this, so it is on
124
+ # by default.
125
+ # ======================================================================= #
126
+ @internal_hash[:show_index] = true
127
+ # ======================================================================= #
128
+ # === :colourize_path
129
+ #
130
+ # If the next variable is set to true then the path, such as
131
+ # /foo/bar.md will be colourized when .report() is called.
132
+ # ======================================================================= #
133
+ @internal_hash[:colourize_path] = true
134
+ # ======================================================================= #
135
+ # === :show_permission_bits
136
+ #
137
+ # If the following variable is set to true then the entry at hand
138
+ # will show inclusive "drwxr-xr-x".
139
+ # ======================================================================= #
140
+ @internal_hash[:show_permission_bits] = true
141
+ # ======================================================================= #
142
+ # === :show_dots_only_entries
143
+ #
144
+ # This setting filters away '.' and '..' from the result.
145
+ # ======================================================================= #
146
+ @internal_hash[:show_dots_only_entries] = false
147
+ # ======================================================================= #
148
+ # === :show_statistics
149
+ # ======================================================================= #
150
+ @internal_hash[:show_statistics] = true
151
+ # ======================================================================= #
152
+ # === :directory_content
153
+ #
154
+ # This variable will keep a reference to class
155
+ # DirectoryParadise::Content.
156
+ # ======================================================================= #
157
+ @internal_hash[:directory_content] = DirectoryParadise::Content.new
158
+ # ======================================================================= #
159
+ # === :hash_colours_for_bytes_value
160
+ #
161
+ # We need to capture this here because we may try to want to sanitize
162
+ # the given values, such as when the user types an incorrect colour,
163
+ # like "mediumpurples" rather than "mediumpurple".
164
+ # ======================================================================= #
165
+ @internal_hash[:hash_colours_for_bytes_value] = HASH_COLOURS_FOR_BYTES_VALUE
166
+ do_not_show_hidden_files # Do not show hidden files by default.
167
+ do_show_header
168
+ do_show_index
169
+ do_show_modification_time
170
+ do_show_the_content
171
+ do_not_stop_on_missing_symlink
172
+ end
173
+
174
+ end; end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'directory_paradise/requires/require_class_content.rb'
6
+ # =========================================================================== #
7
+ require 'directory_paradise/content/content.rb'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'directory_paradise/requires/require_class_report.rb'
6
+ # =========================================================================== #
7
+ require 'directory_paradise/report/report.rb'
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'directory_paradise/requires/require_the_directory_paradise_project.rb'
6
+ # =========================================================================== #
7
+ require 'directory_paradise/requires/require_class_content.rb'
8
+ require 'directory_paradise/requires/require_class_report.rb'
9
+ require 'directory_paradise/to_human_readable/to_human_readable.rb'
10
+ require 'directory_paradise/sdc.rb'
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This file adds a single method, the sdc() method, to your project,
6
+ # and an alias to said method.
7
+ #
8
+ # To use it in your project, do this:
9
+ #
10
+ # require 'directory_paradise/sdc'
11
+ #
12
+ # =========================================================================== #
13
+ require 'directory_paradise/report/report.rb'
14
+
15
+ # =========================================================================== #
16
+ # === sdc
17
+ #
18
+ # The first argument is the directory that should be displayed.
19
+ # =========================================================================== #
20
+ def sdc(
21
+ i = Dir.pwd
22
+ )
23
+ DirectoryParadise::Report.new(i)
24
+ end; alias show_directory_content sdc # === show_directory
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'directory_paradise/to_human_readable/to_human_readable.rb'
6
+ # DirectoryParadise.to_human_readable(123)
7
+ # =========================================================================== #
8
+ module DirectoryParadise
9
+
10
+ class ToHumanReadable
11
+
12
+ alias e puts
13
+
14
+ # ========================================================================= #
15
+ # === ARRAY_BYTE_UNITS
16
+ # ========================================================================= #
17
+ ARRAY_BYTE_UNITS = ['B','KB','MB','GB','TB'] # Should be two chars, for better alignment.
18
+
19
+ # ========================================================================= #
20
+ # === DIVIDE_BY
21
+ # ========================================================================= #
22
+ DIVIDE_BY = 1024.0
23
+
24
+ # ========================================================================= #
25
+ # === initialize
26
+ # ========================================================================= #
27
+ def initialize(
28
+ n_bytes = ARGV
29
+ )
30
+ reset
31
+ # ======================================================================= #
32
+ # === Handle blocks next
33
+ # ======================================================================= #
34
+ if block_given?
35
+ yielded = yield
36
+ @may_we_report = false if yielded == :do_not_report
37
+ end
38
+ if n_bytes.is_a? Array
39
+ n_bytes = n_bytes.first
40
+ end
41
+ n_bytes = n_bytes.to_i
42
+ hierarchy = 0
43
+ if n_bytes > DIVIDE_BY
44
+ loop {
45
+ n_bytes = n_bytes / DIVIDE_BY
46
+ hierarchy += 1
47
+ break if n_bytes < DIVIDE_BY
48
+ }
49
+ end
50
+ @result = ''.dup
51
+ @result << "#{n_bytes.to_f.round(1)} "
52
+ @result << "#{ARRAY_BYTE_UNITS[hierarchy].rjust(2)}"
53
+ end
54
+
55
+ # ========================================================================= #
56
+ # === reset
57
+ # ========================================================================= #
58
+ def reset
59
+ @may_we_report = true
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === result?
64
+ # ========================================================================= #
65
+ def result?
66
+ @result
67
+ end
68
+
69
+ # ========================================================================= #
70
+ # === report
71
+ # ========================================================================= #
72
+ def report
73
+ e @result if @may_we_report
74
+ end
75
+
76
+ end
77
+
78
+ # =========================================================================== #
79
+ # === DirectoryParadise.to_human_readable
80
+ #
81
+ # This variant will simply return the correct string that we want to
82
+ # have. This was the whole point of creating this class in the first
83
+ # place, anyway.
84
+ #
85
+ # Usage example:
86
+ #
87
+ # DirectoryParadise.to_human_readable(2_555_666)
88
+ #
89
+ # =========================================================================== #
90
+ def self.to_human_readable(i = ARGV)
91
+ return DirectoryParadise::ToHumanReadable.new(i) { :do_not_report }.result?
92
+ end
93
+
94
+ end
95
+
96
+ if __FILE__ == $PROGRAM_NAME
97
+ DirectoryParadise::ToHumanReadable.new(ARGV).report
98
+ end # rb to_human_readable 100
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'directory_paradise/version/version.rb'
6
+ # =========================================================================== #
7
+ class DirectoryParadise
8
+
9
+ # ========================================================================= #
10
+ # === VERSION
11
+ # ========================================================================= #
12
+ VERSION = '1.4.4'
13
+
14
+ # ========================================================================= #
15
+ # === LAST_UPDATE
16
+ # ========================================================================= #
17
+ LAST_UPDATE = '15.05.2022'
18
+
19
+ end
@@ -0,0 +1,14 @@
1
+ # =========================================================================== #
2
+ # === colours_for_bytes_values.yml
3
+ #
4
+ # The user can customise the colours via this .yml file. The colour in
5
+ # use must be registered in the Colours namespace, which is part of
6
+ # the colours-gem.
7
+ # =========================================================================== #
8
+ # x = YAML.load_file('colours_for_bytes_values.yml')
9
+ # =========================================================================== #
10
+
11
+ KB: :lightgreen
12
+ MB: :yellow
13
+ GB: :mediumpurple
14
+ B: :olive
@@ -0,0 +1 @@
1
+ require 'directory_paradise/requires/require_the_directory_paradise_project.rb'
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'colours/colours_e_autoinclude.rb'
6
+ require 'directory_paradise'
7
+ require 'cliner'
8
+ cliner
9
+ e 'We will return the entries at '+sdir('/Depot/')+' next:'
10
+ pp DirectoryParadise::Content.new '/Depot/'
11
+ cliner
12
+ e Colours.steelblue('Next, we will show the hash that describes '\
13
+ 'the content of the directory at /Depot/:')
14
+ entries = DirectoryParadise::Content.new('/Depot/').entries?
15
+ e 'This directory has '+entries.size.to_s+' entries.'
16
+ cliner
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'colours/colours_e_autoinclude.rb'
6
+ require 'directory_paradise'
7
+ require 'cliner'
8
+
9
+ # =========================================================================== #
10
+ # First, we set up some files and directories, a few which will be broken.
11
+ # =========================================================================== #
12
+ BASE_DIR = '/Depot/j/'
13
+ e 'The base directory is at '+sdir(BASE_DIR)+'.'
14
+ _ = DirectoryParadise::Report.new(BASE_DIR, :dont_run_yet)
15
+ _.menu 'no_full_path'
16
+ _.run
17
+ _.display
18
+ # =========================================================================== #
19
+ #
20
+ # =========================================================================== #
21
+ BASE_DIR = '/dev/'
22
+ e 'We will change directory into '+Colours.slateblue(BASE_DIR)+' soon:'
23
+ _ = DirectoryParadise::Report.new(BASE_DIR, :dont_run_yet)
24
+ Dir.chdir(BASE_DIR)
25
+ e "We are now in the directory #{Colours.slateblue(BASE_DIR)}."
26
+ _.apply_filter '*sr*' if _.respond_to? :apply_filter
27
+ _.display
28
+ e 'Next testing the difference between con and uncon'
29
+ _.menu 'con'
30
+ _.display
31
+ _.menu 'uncon'
32
+ _.display # test_sdc
33
+ e 'Next, we disable colours:'
34
+ _.disable_colours
35
+ _.show_content_for '/Depot/Temp'
36
+ e 'Next, we enable colours:'
37
+ _.enable_colours
38
+ _.show_content_for '/Depot/Temp'
39
+ e 'Next, we will test ShowDirectoryContent.do_show:'
40
+ DirectoryContent::ShowDirectoryContent.do_show
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'colours/autoinclude'
6
+ require 'directory_paradise'
7
+
8
+ e
9
+ e 'Next testing DirectoryParadise-related toplevel methods:'
10
+ e
11
+
12
+ DirectoryParadise.report
13
+ DirectoryParadise.show('/home/x/songs/')
14
+ DirectoryParadise.show(from: '/home/x/songs/')
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: directory_paradise
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.4
5
+ platform: ruby
6
+ authors:
7
+ - Robert A. Heiler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-15 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: "\nThis class will display the content of a directory. It\ncan also give
42
+ back a data-object that describes the \ncontent of a directory, e. g. all files
43
+ or directories\nfound in that directory.\n\nThe class aims to function somewhat
44
+ similar to the\nUNIX/coreutils program called \"ls\".\n\nThe latest version now
45
+ comes with a test/ directory.\n\nThe method apply_filter() was added, so now we
46
+ can\nfilter almost like \"ls *foo*\" could filter.\n\nAs of version 1.0.3, showing
47
+ the Index is optional.\n\n"
48
+ email: shevy@inbox.lt
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - README.md
54
+ - bin/show_directory_content
55
+ - directory_paradise.gemspec
56
+ - doc/README.gen
57
+ - doc/todo/todo.md
58
+ - lib/directory_paradise.rb
59
+ - lib/directory_paradise/base/base.rb
60
+ - lib/directory_paradise/base/colours.rb
61
+ - lib/directory_paradise/constants/newline.rb
62
+ - lib/directory_paradise/content/constants.rb
63
+ - lib/directory_paradise/content/content.rb
64
+ - lib/directory_paradise/project/project.rb
65
+ - lib/directory_paradise/report/constants.rb
66
+ - lib/directory_paradise/report/initialize.rb
67
+ - lib/directory_paradise/report/menu.rb
68
+ - lib/directory_paradise/report/misc.rb
69
+ - lib/directory_paradise/report/obtain.rb
70
+ - lib/directory_paradise/report/report.rb
71
+ - lib/directory_paradise/report/reset.rb
72
+ - lib/directory_paradise/requires/require_class_content.rb
73
+ - lib/directory_paradise/requires/require_class_report.rb
74
+ - lib/directory_paradise/requires/require_the_directory_paradise_project.rb
75
+ - lib/directory_paradise/sdc.rb
76
+ - lib/directory_paradise/to_human_readable/to_human_readable.rb
77
+ - lib/directory_paradise/version/version.rb
78
+ - lib/directory_paradise/yaml/colours_for_bytes_values.yml
79
+ - test/testing_class_content.rb
80
+ - test/testing_class_report.rb
81
+ - test/testing_toplevel_methods.rb
82
+ homepage: https://rubygems.org/gems/directory_paradise
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.5.8
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.3.13
100
+ requirements: []
101
+ rubygems_version: 3.3.13
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: This class will display the content of a directory. It can also give back
105
+ a data-object that describes the content of a directory, e. g. all files or directories
106
+ found in that directory. The class aims to function somewhat similar to the UNIX/coreutils
107
+ program called "ls". The latest version now comes with a test/ directory. The
108
+ method apply_filter() was added, so now we can filter almost like "ls *foo*" could
109
+ filter. As of version 1.0.3, showing the Index is optional.
110
+ test_files: []