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,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.5'
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === LAST_UPDATE
|
16
|
+
# ========================================================================= #
|
17
|
+
LAST_UPDATE = '06.08.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,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: directory_paradise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert A. Heiler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-06 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/menu.rb
|
66
|
+
- lib/directory_paradise/report/report.rb
|
67
|
+
- lib/directory_paradise/requires/require_class_content.rb
|
68
|
+
- lib/directory_paradise/requires/require_class_report.rb
|
69
|
+
- lib/directory_paradise/requires/require_the_directory_paradise_project.rb
|
70
|
+
- lib/directory_paradise/sdc.rb
|
71
|
+
- lib/directory_paradise/to_human_readable/to_human_readable.rb
|
72
|
+
- lib/directory_paradise/version/version.rb
|
73
|
+
- lib/directory_paradise/yaml/colours_for_bytes_values.yml
|
74
|
+
- test/testing_class_content.rb
|
75
|
+
- test/testing_class_report.rb
|
76
|
+
- test/testing_toplevel_methods.rb
|
77
|
+
homepage: https://rubygems.org/gems/directory_paradise
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.5.8
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 3.3.18
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.3.18
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: This class will display the content of a directory. It can also give back
|
100
|
+
a data-object that describes the content of a directory, e. g. all files or directories
|
101
|
+
found in that directory. The class aims to function somewhat similar to the UNIX/coreutils
|
102
|
+
program called "ls". The latest version now comes with a test/ directory. The
|
103
|
+
method apply_filter() was added, so now we can filter almost like "ls *foo*" could
|
104
|
+
filter. As of version 1.0.3, showing the Index is optional.
|
105
|
+
test_files: []
|