ehbrs_ruby_utils 0.41.1 → 0.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ehbrs_ruby_utils/fs/selected/build.rb +2 -0
- data/lib/ehbrs_ruby_utils/fs/selected/build_file.rb +1 -1
- data/lib/ehbrs_ruby_utils/music/sort/commands/base.rb +31 -0
- data/lib/ehbrs_ruby_utils/music/sort/commands/dump.rb +67 -0
- data/lib/ehbrs_ruby_utils/music/sort/commands/load.rb +36 -0
- data/lib/ehbrs_ruby_utils/music/sort/commands/shuffle.rb +55 -0
- data/lib/ehbrs_ruby_utils/music/sort/commands.rb +13 -0
- data/lib/ehbrs_ruby_utils/music/sort/files/base.rb +43 -0
- data/lib/ehbrs_ruby_utils/music/sort/files/factory.rb +64 -0
- data/lib/ehbrs_ruby_utils/music/sort/files/scanner.rb +60 -0
- data/lib/ehbrs_ruby_utils/music/sort/files.rb +13 -0
- data/lib/ehbrs_ruby_utils/music/sort.rb +11 -0
- data/lib/ehbrs_ruby_utils/patches/object/template.rb +1 -3
- data/lib/ehbrs_ruby_utils/version.rb +1 -1
- metadata +22 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d257573a9117902808e20c43bf002671f832d16cc40bf676cfb46282435b22f5
|
4
|
+
data.tar.gz: fa5b446750faae117f1902457683b1b46599f85e64d40b7402451433d007d861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f5dbbbcffc5213abb54303cc9272e3875f40ba4f80c759298c6ba4d6677e806862b5a221a26fd487f45c26c02f7075decbf1251b424dd15a28ab186c35d9d5c
|
7
|
+
data.tar.gz: dd456900169ed432a7c2b3aaef91ab93fff318b098eddcade488b5877df89b9babdeb45ec1336eadeb2ecde18d80a1c1b7011a5fa56952ed6427e60f3aab41ea
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/music/sort/files/scanner'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Music
|
8
|
+
module Sort
|
9
|
+
module Commands
|
10
|
+
class Base
|
11
|
+
enable_speaker
|
12
|
+
enable_simple_cache
|
13
|
+
common_constructor :root, :confirm do
|
14
|
+
self.root = root.to_pathname
|
15
|
+
run
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def config_file
|
21
|
+
scanner.config_file
|
22
|
+
end
|
23
|
+
|
24
|
+
def scanner_uncached
|
25
|
+
::EhbrsRubyUtils::Music::Sort::Files::Scanner.new(root)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/music/sort/commands/base'
|
5
|
+
require 'ehbrs_ruby_utils/music/sort/files/base'
|
6
|
+
require 'ehbrs_ruby_utils/music/sort/files/factory'
|
7
|
+
|
8
|
+
module EhbrsRubyUtils
|
9
|
+
module Music
|
10
|
+
module Sort
|
11
|
+
module Commands
|
12
|
+
class Dump < EhbrsRubyUtils::Music::Sort::Commands::Base
|
13
|
+
private
|
14
|
+
|
15
|
+
def run
|
16
|
+
if File.exist?(config_file)
|
17
|
+
@config = YAML.load_file(config_file)
|
18
|
+
to_rename.each { |sf| rename(sf) }
|
19
|
+
else
|
20
|
+
fatal_error("File \"#{config_file}\" does not exist")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_rename
|
25
|
+
r = []
|
26
|
+
::EhbrsRubyUtils::Music::Sort::Files::Factory::SECTIONS.each do |section|
|
27
|
+
i = 1
|
28
|
+
(@config[section] || []).each do |name|
|
29
|
+
r << ::EhbrsRubyUtils::Music::Sort::Files::Base.new(section, i, name, nil)
|
30
|
+
i += 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
r
|
34
|
+
end
|
35
|
+
|
36
|
+
def rename(source_file)
|
37
|
+
o = scanner.search(source_file.name)
|
38
|
+
if o
|
39
|
+
rename_on_found(source_file, o)
|
40
|
+
else
|
41
|
+
warn("File not found for \"#{source_file}\"")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def rename_on_found(source_file, sorted_file)
|
46
|
+
o = sorted_file.reorder(source_file.section, source_file.order, order_padding)
|
47
|
+
info("\"#{o.source_basename}\" => \"#{o.target_basename}\"")
|
48
|
+
confirm_rename(o.source_basename, o.target_basename) if confirm
|
49
|
+
end
|
50
|
+
|
51
|
+
def confirm_rename(old_basename, new_basename)
|
52
|
+
op = File.expand_path(old_basename, root)
|
53
|
+
np = File.expand_path(new_basename, root)
|
54
|
+
return if np == op
|
55
|
+
raise "\"#{np}\" (From \"#{op}\") already exists" if File.exist?(np)
|
56
|
+
|
57
|
+
File.rename(op, np)
|
58
|
+
end
|
59
|
+
|
60
|
+
def order_padding_uncached
|
61
|
+
scanner.count.to_s.length
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/music/sort/commands/base'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Music
|
8
|
+
module Sort
|
9
|
+
module Commands
|
10
|
+
class Load < EhbrsRubyUtils::Music::Sort::Commands::Base
|
11
|
+
private
|
12
|
+
|
13
|
+
def run
|
14
|
+
info "Reading \"#{root}\"..."
|
15
|
+
config = build_config
|
16
|
+
s = config.to_yaml
|
17
|
+
puts s
|
18
|
+
if confirm
|
19
|
+
info("Writing to \"#{config_file}\"...")
|
20
|
+
File.write(config_file, s)
|
21
|
+
end
|
22
|
+
puts 'Done!'.green
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_config
|
26
|
+
config = {}
|
27
|
+
scanner.by_section.each do |section, fs|
|
28
|
+
config[section] = fs.sort.map(&:name)
|
29
|
+
end
|
30
|
+
config
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/music/sort/commands/base'
|
5
|
+
require 'ehbrs_ruby_utils/music/sort/files/factory'
|
6
|
+
|
7
|
+
module EhbrsRubyUtils
|
8
|
+
module Music
|
9
|
+
module Sort
|
10
|
+
module Commands
|
11
|
+
class Shuffle < EhbrsRubyUtils::Music::Sort::Commands::Base
|
12
|
+
private
|
13
|
+
|
14
|
+
def run
|
15
|
+
if confirm
|
16
|
+
load_last_shuffle
|
17
|
+
else
|
18
|
+
dump_last_shuffle
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def dump_last_shuffle
|
23
|
+
s = build_config.to_yaml
|
24
|
+
puts s
|
25
|
+
info("Writing to \"#{last_shuffle_file}\"...")
|
26
|
+
File.write(last_shuffle_file, s)
|
27
|
+
puts 'Done!'.green
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_last_shuffle
|
31
|
+
if File.exist?(last_shuffle_file)
|
32
|
+
IO.copy_stream(last_shuffle_file, config_file)
|
33
|
+
File.unlink(last_shuffle_file)
|
34
|
+
puts 'Done!'.green
|
35
|
+
else
|
36
|
+
fatal_error "File \"#{last_shuffle_file}\" does not exist"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def last_shuffle_file
|
41
|
+
File.join(root, '.last_shuffle')
|
42
|
+
end
|
43
|
+
|
44
|
+
def build_config
|
45
|
+
config = {}
|
46
|
+
config[::EhbrsRubyUtils::Music::Sort::Files::Factory::SECTION_CURRENT] =
|
47
|
+
scanner.all.to_a.shuffle.map(&:name)
|
48
|
+
config[::EhbrsRubyUtils::Music::Sort::Files::Factory::SECTION_NEW] = []
|
49
|
+
config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Music
|
7
|
+
module Sort
|
8
|
+
module Files
|
9
|
+
class Base
|
10
|
+
common_constructor :section, :order, :name, :original_path, :padding, default: [nil, 0] do
|
11
|
+
self.original_path = original_path.if_present { |v| v.to_pathname.expand_path }
|
12
|
+
end
|
13
|
+
|
14
|
+
def reorder(new_section, new_order, padding)
|
15
|
+
self.class.new(new_section, new_order, name, original_path, padding)
|
16
|
+
end
|
17
|
+
|
18
|
+
def target_basename
|
19
|
+
"#{section}#{order.to_s.rjust(padding, '0')} #{name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def source_basename
|
23
|
+
original_path.if_present(&:basename) || raise('Original path is blank')
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
target_basename
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def <=>(other)
|
33
|
+
%i[section order name].each do |a|
|
34
|
+
r = send(a) <=> other.send(a)
|
35
|
+
return r unless r.zero?
|
36
|
+
end
|
37
|
+
0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Music
|
7
|
+
module Sort
|
8
|
+
module Files
|
9
|
+
class Factory
|
10
|
+
SECTION_CURRENT = 'A'
|
11
|
+
SECTION_NEW = 'Z'
|
12
|
+
SECTIONS = [SECTION_CURRENT, SECTION_NEW].freeze
|
13
|
+
NO_ORDER = Float::INFINITY
|
14
|
+
|
15
|
+
enable_simple_cache
|
16
|
+
common_constructor :path, :config_data
|
17
|
+
|
18
|
+
def basename
|
19
|
+
by_pattern(3).if_present(path.basename.to_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def build
|
23
|
+
::EhbrsRubyUtils::Music::Sort::Files::Base.new(section, order, basename, path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def order
|
27
|
+
order_from_config_data || by_pattern(2).if_present(NO_ORDER, &:to_i)
|
28
|
+
end
|
29
|
+
|
30
|
+
def section
|
31
|
+
r = section_from_config_data || by_pattern(1).if_present(SECTION_NEW)
|
32
|
+
return SECTION_CURRENT if r.blank? || r.upcase == SECTION_CURRENT
|
33
|
+
|
34
|
+
SECTION_NEW
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def by_pattern(index)
|
40
|
+
match_builded_pattern.if_present { |v| v[index] }
|
41
|
+
end
|
42
|
+
|
43
|
+
def match_builded_pattern_uncached
|
44
|
+
/\A([a-z])?([0-9]+)\s+(\S.*)\z/i.match(path.basename.to_path)
|
45
|
+
end
|
46
|
+
|
47
|
+
def order_from_config_data
|
48
|
+
config_data.each_value do |files|
|
49
|
+
files.index(basename).if_present { |v| return v + 1 }
|
50
|
+
end
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def section_from_config_data
|
55
|
+
config_data.each do |section, files|
|
56
|
+
return section if files.include?(basename)
|
57
|
+
end
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/music/sort/files/factory'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Music
|
8
|
+
module Sort
|
9
|
+
module Files
|
10
|
+
class Scanner
|
11
|
+
enable_simple_cache
|
12
|
+
common_constructor :root
|
13
|
+
|
14
|
+
def all
|
15
|
+
by_section.flat_map { |_s, fs| fs }
|
16
|
+
end
|
17
|
+
|
18
|
+
def config_file
|
19
|
+
root.join('.sort')
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Integer]
|
23
|
+
def count
|
24
|
+
by_section.values.inject(0) { |a, e| a + e.count }
|
25
|
+
end
|
26
|
+
|
27
|
+
def search(name)
|
28
|
+
all.find { |sf| sf.name == name }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def by_section_uncached
|
34
|
+
r = {}
|
35
|
+
to_sort.each do |f|
|
36
|
+
sf = ::EhbrsRubyUtils::Music::Sort::Files::Factory.new(f, config_data).build
|
37
|
+
r[sf.section] ||= []
|
38
|
+
r[sf.section] << sf
|
39
|
+
end
|
40
|
+
EhbrsRubyUtils::Music::Sort::Files::Factory::SECTIONS.index_with do |s|
|
41
|
+
r[s] || []
|
42
|
+
end.freeze
|
43
|
+
end
|
44
|
+
|
45
|
+
def config_data_uncached
|
46
|
+
if config_file.exist?
|
47
|
+
::EacRubyUtils::Yaml.load_file(config_file)
|
48
|
+
else
|
49
|
+
{}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_sort
|
54
|
+
root.children.reject { |e| e.basename.to_path.start_with?('.') }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.42.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aranha
|
@@ -50,34 +50,34 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0.
|
53
|
+
version: '0.10'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.10.1
|
54
57
|
type: :runtime
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
57
60
|
requirements:
|
58
61
|
- - "~>"
|
59
62
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0.
|
63
|
+
version: '0.10'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.10.1
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
name: avm
|
63
69
|
requirement: !ruby/object:Gem::Requirement
|
64
70
|
requirements:
|
65
71
|
- - "~>"
|
66
72
|
- !ruby/object:Gem::Version
|
67
|
-
version: '0.
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 0.84.2
|
73
|
+
version: '0.91'
|
71
74
|
type: :runtime
|
72
75
|
prerelease: false
|
73
76
|
version_requirements: !ruby/object:Gem::Requirement
|
74
77
|
requirements:
|
75
78
|
- - "~>"
|
76
79
|
- !ruby/object:Gem::Version
|
77
|
-
version: '0.
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 0.84.2
|
80
|
+
version: '0.91'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: dentaku
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -333,6 +333,16 @@ files:
|
|
333
333
|
- lib/ehbrs_ruby_utils/music/ous/artist.rb
|
334
334
|
- lib/ehbrs_ruby_utils/music/ous/category.rb
|
335
335
|
- lib/ehbrs_ruby_utils/music/ous/node.rb
|
336
|
+
- lib/ehbrs_ruby_utils/music/sort.rb
|
337
|
+
- lib/ehbrs_ruby_utils/music/sort/commands.rb
|
338
|
+
- lib/ehbrs_ruby_utils/music/sort/commands/base.rb
|
339
|
+
- lib/ehbrs_ruby_utils/music/sort/commands/dump.rb
|
340
|
+
- lib/ehbrs_ruby_utils/music/sort/commands/load.rb
|
341
|
+
- lib/ehbrs_ruby_utils/music/sort/commands/shuffle.rb
|
342
|
+
- lib/ehbrs_ruby_utils/music/sort/files.rb
|
343
|
+
- lib/ehbrs_ruby_utils/music/sort/files/base.rb
|
344
|
+
- lib/ehbrs_ruby_utils/music/sort/files/factory.rb
|
345
|
+
- lib/ehbrs_ruby_utils/music/sort/files/scanner.rb
|
336
346
|
- lib/ehbrs_ruby_utils/patches.rb
|
337
347
|
- lib/ehbrs_ruby_utils/patches/object.rb
|
338
348
|
- lib/ehbrs_ruby_utils/patches/object/template.rb
|