directory_paradise 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9a9d6aaf616b92f7e2fcdbe01335b59fb54a4c754e3bf208ee2ef42c9eff961c
4
+ data.tar.gz: 487b2c07cc240cb7ef01bd5f05791f139763b8781cab95387d00f5002be3675d
5
+ SHA512:
6
+ metadata.gz: 337d80156b3150f15dd99ac6e1cabb3455c97b0ff23b47cfe28aeecd5f057594148640d5b59b7bd2bbdb079c0b4d268a5da51ffbc9c9a8c687b022cc69e82b39
7
+ data.tar.gz: 496af2302209e8716c0512822fbf116ff068212c1638580cd8787e25a4754cea63a7209297c1510d2035f34faa689868c6fa2c1c3c8942672d606e27f4a4a0b0
data/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # @title Directory Content
2
+ # @markup kramdown
3
+
4
+ [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
5
+ [![forthebadge](https://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
6
+ [![Gem Version](https://badge.fury.io/rb/directory_paradise.svg)](https://badge.fury.io/rb/directory_paradise)
7
+
8
+ This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">06.08.2022</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">00:57:31</span> o'clock.
9
+
10
+ <img src="https://i.imgur.com/hbGDM7i.jpg">
11
+
12
+ ## The directory_paradise gem - an introduction
13
+
14
+ The directory_paradise gem originated from the older directory_content gem.
15
+
16
+ I got tired of trying to fix bugs derived from the old code base, though,
17
+ so I decided to just start a new project altogether, while re-using the
18
+ parts of the code that works.
19
+
20
+ As I gained a bit of experience, I decided to adapt the old approach.
21
+ This will be mentioned at a later time in this document.
22
+
23
+ This small gem may be useful whenever you wish to display the content
24
+ of a (local) directory, similar to how the linux/unix program called
25
+ **ls** operates.
26
+
27
+ I needed a variant of **ls** for my ruby-shell (the **roebe-shell**),
28
+ so this project here was created years ago. Unfortunately over
29
+ the years I changed parts of the code, without properly
30
+ designing it, leading to quite some confusion as to what the
31
+ project really should do, and how it should achieve this.
32
+
33
+ Thus, this README here shall not only explain the use cases of the
34
+ project as such, but document a few internal decisions as well,
35
+ including the rationale behind having made that decision.
36
+
37
+ That way we can use the **documentation** as some form of
38
+ specification as well, and check to see that the code
39
+ adheres to this specification. This may be helpful in the
40
+ future, because I already rewrote this project several times
41
+ before already.
42
+
43
+ There are now two main classes for the **directory_paradise** project:
44
+
45
+ (1) **class Report**, which will be in the **report/** subdirectory.
46
+
47
+ This class will be responsible for displaying the content of a directory
48
+ to the user.
49
+
50
+ (2) **class Content** which will reside in the **content/** directory.
51
+
52
+ This class will be responsible for obtaining all the necessary
53
+ information to provide data to class Report. It may no longer
54
+ report anything to the user, except for debug output when we
55
+ test or modify it.
56
+
57
+ Hopefully these design choices will make it easier to maintain the
58
+ code base. In the past the old class that was similar to class
59
+ Content also displayed some information, which led to code duplication
60
+ and confusion, aka where to put new code in.
61
+
62
+ Furthermore, a new class called Base will now exist that can be used
63
+ to share code between these two classes, such return_pwd (which is
64
+ similar to Dir.pwd, but always ensures that a trailing / will be
65
+ there).
66
+
67
+ ## class Content
68
+
69
+ This is the main class of module DirectoryParadise. It will not report
70
+ anything to the user, but it will parse the entries in a given directory
71
+ and store these entries in a hash that is available via .entries?.
72
+
73
+ The method .entries? will return which entries (files, directories
74
+ or symlinks) were found in the given directory.
75
+
76
+ The method .n_entries? will return a number, indicating how many
77
+ such entries could be found.
78
+
79
+ The method .obtain_entries_from() can be used to fill up the
80
+ entries. If you also want to change the target directory,
81
+ make use of the method .set_target_directory().
82
+
83
+ The method .report() can be used to report the content. It is,
84
+ however had, not called by default for class DirectoryContent.
85
+ Note that another class, called ShowDirectoryContent, is the
86
+ one that is more apt and adjusted to displaying content.
87
+
88
+ This class is the one that should be used when you wish to display
89
+ the content of a directory. It will make use of class DirectoryContent,
90
+ so there is a **separation-of-concern**.
91
+
92
+ Note that you could also use class DirectoryContent to display
93
+ content too, via the .report() method - but this is mostly just
94
+ as a way to quickly debug something. For a more advanced display
95
+ of files and directories, use class DirectoryContent::ShowDirectoryContent
96
+ as it has been created precisely for that use case.
97
+
98
+ ## Specification for class Content - the individual entries explained
99
+
100
+ Essentially class Content has a hash that describes the content
101
+ of a directory. This subsection will explain some of the entries that
102
+ can be found in that hash, and thus may serve as some kind of
103
+ specification.
104
+
105
+ First, the path to the file or directory at hand will be the main key.
106
+ So, for example, if you have an archive called Images.tar.xz at
107
+ the directory /Depot/, then the key to the description of that
108
+ entry will be **/Depot/Images.tar.xz**. That way we always know
109
+ where class DirectoryContent 'points' at.
110
+
111
+ Now knowing this key, let's have a look at the individual entries:
112
+
113
+ :type=>"file" # keep track of the file type, e. g. file, directory or link.
114
+ :size=>47626780 # we want to know the file size too, so that we don't have to call any other method querying this again.
115
+ :is_executable=>false # is our file executable? Typically entries in /usr/bin/ will be executables
116
+ :path=>"/Depot/Images.tar.xz" # here we store the path again, to simplify querying the path.
117
+ :ascii_representation=>"-rw-r--r--" # This is mostly used to keep compatibility to GNU coreutils "ls"
118
+ :last_modified=>2021-03-09 01:20:09.432056708 +0000 # Keep track as to when this entry was last modified.
119
+ :gid=>0 # group id
120
+ :inode_number=>93857180 # its inode number
121
+ :uid=>0 # user id
122
+ :access_mode=>"644" # access mode
123
+ :name_of_owner=>"root" # name of the current owner of that entry
124
+ :name_of_group=>"root" # name of the current group of that entry
125
+
126
+ ## Behaviour on missing symlinks
127
+
128
+ If a missing symlink (that is, the target to which this symlink points
129
+ to does not exist) is encountered, then class ShowDirectoryContent
130
+ will either ignore this, or display to the user that a symlink is
131
+ missing. Additionally it may stop altogether when a missing
132
+ symlink is discovered. That way the user is sort of forced to
133
+ fix this issue - I needed this once on **GoboLinux**, which is why
134
+ this functionality had to exist.
135
+
136
+ This is handled internally via the method call **stop_on_missing_symlink?**.
137
+
138
+ The next subsection deals with class DirectoryParadise::Report, which
139
+ is the main class when you wish to display the content of a directory.
140
+
141
+ ## Display only directory in the current working directory
142
+
143
+ If you only wish to display all directories in the current
144
+ working directory then you can use the method called
145
+ <b>.only_directories</b>, or, from the commandline:
146
+
147
+ sdc --only-directories
148
+
149
+ ## Do not show the header
150
+
151
+ By default, class DirectoryParadise::Report will show a header on
152
+ top, to explain some of the options.
153
+
154
+ This may not always be wanted, so a commandline option exists
155
+ to NOT show the header.
156
+
157
+ Example for this:
158
+
159
+ sdc --noheader
160
+ sdc --no-header
161
+
162
+ This is more similar to how "ls" works by default too, by the
163
+ way.
164
+
165
+ ## Show hidden files
166
+
167
+ This should show hidden files aka those with a leading '.':
168
+
169
+ sdc --show
170
+
171
+ Several aliases exist to this. Have a look at **menu.rb** to
172
+ see all aliases to it, at **directory_paradise/report/menu.rb**.
173
+
174
+ # Customising colours via the yaml file called colours_for_bytes_values.yml
175
+
176
+ You can customize the existing colours for KB, MB and GB values,
177
+ via the yaml file called **colours_for_bytes_values.yml**. Currently
178
+ only a few colours are supported, though. This may be extended one
179
+ day, if people want to use other colours by default for the KB,
180
+ MB and GB entries.
181
+
182
+ Since as of **January 2022** the code will also check whether the
183
+ colour names are correct. I had a typo called **mediumpurples**
184
+ which did not exist, leading to another project break. This
185
+ is bad, so now the directory_paradise gem will verify whether
186
+ the colours exist or not.
187
+
188
+
189
+ ## Contact information and mandatory 2FA coming up in 2022
190
+
191
+ If your creative mind has ideas and specific suggestions to make this gem
192
+ more useful in general, feel free to drop me an email at any time, via:
193
+
194
+ shevy@inbox.lt
195
+
196
+ Before that email I used an email account at Google gmail, but in **2021** I
197
+ decided to slowly abandon gmail for various reasons. In order to limit this
198
+ explanation here, allow me to just briefly state that I do not feel as if I
199
+ want to promote any Google service anymore, for various reasons.
200
+
201
+ Do keep in mind that responding to emails may take some time, depending on
202
+ the amount of work I may have at that moment.
203
+
204
+ In 2022 rubygems.org decided to make 2FA mandatory for every gem owner:
205
+ see https://blog.rubygems.org/2022/06/13/making-packages-more-secure.html
206
+
207
+ As I can not use 2FA, for reasons I will skip explaining here (see
208
+ various github issue discussions in the past), this effectively means that
209
+ Betty Li and others who run the show at rubygems.org will perma-ban me
210
+ from using rubygems as a developer.
211
+
212
+ As I disagree with that decision completely, this will mean that all my
213
+ gems will be removed from rubygems.org prior to that sunset date, e. g.
214
+ before they permanently lock me out from the code that I used
215
+ to maintain. It is pointless to want to discuss this with them anymore -
216
+ they have made up their minds and decided that you can only use
217
+ the code if 2FA is in place, even though the code itself works just
218
+ fine. If you don't use 2FA you are effectively locked out from your
219
+ own code; I consider this a malicious attack. See also how they limited
220
+ discussions to people with mandatory 2FA on the ruby-bugtracker, thus
221
+ banning everyone permanently without 2FA:
222
+
223
+ https://bugs.ruby-lang.org/issues/18800
224
+
225
+ Guess it may indeed be time to finally abandon ruby - not because
226
+ ruby is a bad language, but there are people now in charge who
227
+ really should not be part of ruby in the first place.
228
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'directory_paradise'
6
+
7
+ DirectoryParadise.show(ARGV)
@@ -0,0 +1,45 @@
1
+ require 'directory_paradise/version/version.rb'
2
+ require 'roebe/toplevel_methods/misc.rb'
3
+
4
+ Gem::Specification.new { |s|
5
+
6
+ s.name = 'directory_paradise'
7
+ s.version = DirectoryParadise::VERSION
8
+ s.date = Time.now.strftime('%Y-%m-%d')
9
+
10
+ DESCRIPTION = <<-EOF
11
+
12
+ This class will display the content of a directory. It
13
+ can also give back a data-object that describes the
14
+ content of a directory, e. g. all files or directories
15
+ found in that directory.
16
+
17
+ The class aims to function somewhat similar to the
18
+ UNIX/coreutils program called "ls".
19
+
20
+ The latest version now comes with a test/ directory.
21
+
22
+ The method apply_filter() was added, so now we can
23
+ filter almost like "ls *foo*" could filter.
24
+
25
+ As of version 1.0.3, showing the Index is optional.
26
+
27
+ EOF
28
+
29
+ s.summary = DESCRIPTION
30
+ s.description = DESCRIPTION
31
+
32
+ s.authors = ['Robert A. Heiler']
33
+ s.email = Roebe.email?
34
+ s.files = Dir['**/*']
35
+ s.homepage = 'https://rubygems.org/gems/directory_paradise'
36
+ s.licenses = 'MIT'
37
+
38
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
39
+ s.required_rubygems_version = '>= '+Gem::VERSION
40
+ s.rubygems_version = '>= '+Gem::VERSION
41
+
42
+ s.add_dependency 'colours'
43
+ s.add_dependency 'opn'
44
+
45
+ }
data/doc/README.gen ADDED
@@ -0,0 +1,185 @@
1
+ # @title Directory Content
2
+ # @markup kramdown
3
+
4
+ ADD_RUBY_BADGE
5
+ ADD_TIME_STAMP
6
+
7
+ <img src="https://i.imgur.com/hbGDM7i.jpg">
8
+
9
+ ## The directory_paradise gem - an introduction
10
+
11
+ The directory_paradise gem originated from the older directory_content gem.
12
+
13
+ I got tired of trying to fix bugs derived from the old code base, though,
14
+ so I decided to just start a new project altogether, while re-using the
15
+ parts of the code that works.
16
+
17
+ As I gained a bit of experience, I decided to adapt the old approach.
18
+ This will be mentioned at a later time in this document.
19
+
20
+ This small gem may be useful whenever you wish to display the content
21
+ of a (local) directory, similar to how the linux/unix program called
22
+ **ls** operates.
23
+
24
+ I needed a variant of **ls** for my ruby-shell (the **roebe-shell**),
25
+ so this project here was created years ago. Unfortunately over
26
+ the years I changed parts of the code, without properly
27
+ designing it, leading to quite some confusion as to what the
28
+ project really should do, and how it should achieve this.
29
+
30
+ Thus, this README here shall not only explain the use cases of the
31
+ project as such, but document a few internal decisions as well,
32
+ including the rationale behind having made that decision.
33
+
34
+ That way we can use the **documentation** as some form of
35
+ specification as well, and check to see that the code
36
+ adheres to this specification. This may be helpful in the
37
+ future, because I already rewrote this project several times
38
+ before already.
39
+
40
+ There are now two main classes for the **directory_paradise** project:
41
+
42
+ (1) **class Report**, which will be in the **report/** subdirectory.
43
+
44
+ This class will be responsible for displaying the content of a directory
45
+ to the user.
46
+
47
+ (2) **class Content** which will reside in the **content/** directory.
48
+
49
+ This class will be responsible for obtaining all the necessary
50
+ information to provide data to class Report. It may no longer
51
+ report anything to the user, except for debug output when we
52
+ test or modify it.
53
+
54
+ Hopefully these design choices will make it easier to maintain the
55
+ code base. In the past the old class that was similar to class
56
+ Content also displayed some information, which led to code duplication
57
+ and confusion, aka where to put new code in.
58
+
59
+ Furthermore, a new class called Base will now exist that can be used
60
+ to share code between these two classes, such return_pwd (which is
61
+ similar to Dir.pwd, but always ensures that a trailing / will be
62
+ there).
63
+
64
+ ## class Content
65
+
66
+ This is the main class of module DirectoryParadise. It will not report
67
+ anything to the user, but it will parse the entries in a given directory
68
+ and store these entries in a hash that is available via .entries?.
69
+
70
+ The method .entries? will return which entries (files, directories
71
+ or symlinks) were found in the given directory.
72
+
73
+ The method .n_entries? will return a number, indicating how many
74
+ such entries could be found.
75
+
76
+ The method .obtain_entries_from() can be used to fill up the
77
+ entries. If you also want to change the target directory,
78
+ make use of the method .set_target_directory().
79
+
80
+ The method .report() can be used to report the content. It is,
81
+ however had, not called by default for class DirectoryContent.
82
+ Note that another class, called ShowDirectoryContent, is the
83
+ one that is more apt and adjusted to displaying content.
84
+
85
+ This class is the one that should be used when you wish to display
86
+ the content of a directory. It will make use of class DirectoryContent,
87
+ so there is a **separation-of-concern**.
88
+
89
+ Note that you could also use class DirectoryContent to display
90
+ content too, via the .report() method - but this is mostly just
91
+ as a way to quickly debug something. For a more advanced display
92
+ of files and directories, use class DirectoryContent::ShowDirectoryContent
93
+ as it has been created precisely for that use case.
94
+
95
+ ## Specification for class Content - the individual entries explained
96
+
97
+ Essentially class Content has a hash that describes the content
98
+ of a directory. This subsection will explain some of the entries that
99
+ can be found in that hash, and thus may serve as some kind of
100
+ specification.
101
+
102
+ First, the path to the file or directory at hand will be the main key.
103
+ So, for example, if you have an archive called Images.tar.xz at
104
+ the directory /Depot/, then the key to the description of that
105
+ entry will be **/Depot/Images.tar.xz**. That way we always know
106
+ where class DirectoryContent 'points' at.
107
+
108
+ Now knowing this key, let's have a look at the individual entries:
109
+
110
+ :type=>"file" # keep track of the file type, e. g. file, directory or link.
111
+ :size=>47626780 # we want to know the file size too, so that we don't have to call any other method querying this again.
112
+ :is_executable=>false # is our file executable? Typically entries in /usr/bin/ will be executables
113
+ :path=>"/Depot/Images.tar.xz" # here we store the path again, to simplify querying the path.
114
+ :ascii_representation=>"-rw-r--r--" # This is mostly used to keep compatibility to GNU coreutils "ls"
115
+ :last_modified=>2021-03-09 01:20:09.432056708 +0000 # Keep track as to when this entry was last modified.
116
+ :gid=>0 # group id
117
+ :inode_number=>93857180 # its inode number
118
+ :uid=>0 # user id
119
+ :access_mode=>"644" # access mode
120
+ :name_of_owner=>"root" # name of the current owner of that entry
121
+ :name_of_group=>"root" # name of the current group of that entry
122
+
123
+ ## Behaviour on missing symlinks
124
+
125
+ If a missing symlink (that is, the target to which this symlink points
126
+ to does not exist) is encountered, then class ShowDirectoryContent
127
+ will either ignore this, or display to the user that a symlink is
128
+ missing. Additionally it may stop altogether when a missing
129
+ symlink is discovered. That way the user is sort of forced to
130
+ fix this issue - I needed this once on **GoboLinux**, which is why
131
+ this functionality had to exist.
132
+
133
+ This is handled internally via the method call **stop_on_missing_symlink?**.
134
+
135
+ The next subsection deals with class DirectoryParadise::Report, which
136
+ is the main class when you wish to display the content of a directory.
137
+
138
+ ## Display only directory in the current working directory
139
+
140
+ If you only wish to display all directories in the current
141
+ working directory then you can use the method called
142
+ <b>.only_directories</b>, or, from the commandline:
143
+
144
+ sdc --only-directories
145
+
146
+ ## Do not show the header
147
+
148
+ By default, class DirectoryParadise::Report will show a header on
149
+ top, to explain some of the options.
150
+
151
+ This may not always be wanted, so a commandline option exists
152
+ to NOT show the header.
153
+
154
+ Example for this:
155
+
156
+ sdc --noheader
157
+ sdc --no-header
158
+
159
+ This is more similar to how "ls" works by default too, by the
160
+ way.
161
+
162
+ ## Show hidden files
163
+
164
+ This should show hidden files aka those with a leading '.':
165
+
166
+ sdc --show
167
+
168
+ Several aliases exist to this. Have a look at **menu.rb** to
169
+ see all aliases to it, at **directory_paradise/report/menu.rb**.
170
+
171
+ # Customising colours via the yaml file called colours_for_bytes_values.yml
172
+
173
+ You can customize the existing colours for KB, MB and GB values,
174
+ via the yaml file called **colours_for_bytes_values.yml**. Currently
175
+ only a few colours are supported, though. This may be extended one
176
+ day, if people want to use other colours by default for the KB,
177
+ MB and GB entries.
178
+
179
+ Since as of **January 2022** the code will also check whether the
180
+ colour names are correct. I had a typo called **mediumpurples**
181
+ which did not exist, leading to another project break. This
182
+ is bad, so now the directory_paradise gem will verify whether
183
+ the colours exist or not.
184
+
185
+ ADD_CONTACT_INFORMATION
data/doc/todo/todo.md ADDED
@@ -0,0 +1,4 @@
1
+ (1) At the display of the file size,
2
+ consider using:
3
+
4
+ to_human_readable(file_size)