diskcatalog 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0eefbdc894982861188be371c1236b7040a8c48098177c2fe136e0f852deaec
4
- data.tar.gz: 4cbc90895d7948d74b790d2976f9bb8443f53f09995e09830340512438f18bbf
3
+ metadata.gz: fecee62476c7ba3617e40c7508c6e89c1f7fd66f18c87b5e2b18d17b443275aa
4
+ data.tar.gz: ab1b8549fd18d8770b0e8919a4e2196bc0731c188b503fbbd5fa8bf76b378038
5
5
  SHA512:
6
- metadata.gz: 5ecba185745812d17e28423f960e734cd2266919b5854befa4ea24c38d4d78216d6bfffa6b9b3837557f9ea4f683f1fdf814c9e28dbff96e94782fd7e1bdd3b3
7
- data.tar.gz: 38842a37b131d732ceda1e49660619dfe4c91e23a6620e7cb00d3a4a29ffeb4db690964b21a13740222d89667247ff98a6099a0a2bce7b360989baedc6fa2379
6
+ metadata.gz: f407c0a3853b19894ed9f99332e9c88e2e51b9ea244ac48154d87385547f663cccccd842b70c12c08881cf20c5846248250ef14271b3bf6e2ea9a048527507a8
7
+ data.tar.gz: 9219b5b01ab1068a8865b95ec6412e05a8f4396dca81a471996d44e455a2c2812ef0177de5cf314e27a411a7334579eaeaadd6d77d457efd70a614bb399ecb00
data/Gemfile.lock CHANGED
@@ -1,15 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diskcatalog (0.1.0)
4
+ diskcatalog (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- minitest (5.14.2)
10
- rake (13.0.3)
9
+ minitest (5.19.0)
10
+ rake (13.0.6)
11
11
 
12
12
  PLATFORMS
13
+ arm64-darwin-22
13
14
  x64-mingw32
14
15
  x86_64-darwin-22
15
16
 
@@ -19,4 +20,4 @@ DEPENDENCIES
19
20
  rake (~> 13.0)
20
21
 
21
22
  BUNDLED WITH
22
- 2.3.25
23
+ 2.4.9
data/build.sh ADDED
@@ -0,0 +1,18 @@
1
+ #!/bin/sh
2
+ # rmagick for sierra
3
+ export PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig
4
+ #export PATH=/usr/local/Cellar/imagemagick@6/6.9.7-5/bin:$PATH
5
+
6
+ bundle_dir=./vendor/bundle
7
+ if [ -d "$bundle_dir" ] ; then
8
+ /bin/rm -rf "$bundle_dir"
9
+ bundle update
10
+ else
11
+ /bin/rm -rf "$bundle_dir"
12
+ bundle install --path "$bundle_dir"
13
+ fi
14
+
15
+
16
+
17
+
18
+
data/catalogrc ADDED
@@ -0,0 +1,2 @@
1
+ general:
2
+ catalogdir: ./data
File without changes
data/exe/diskcatalog CHANGED
File without changes
data/exe/mkcat ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "diskcatalog"
4
+
5
+ Diskcatalog::Command.run(ARGV)
@@ -0,0 +1,61 @@
1
+ module MyFind
2
+
3
+ #
4
+ # Calls the associated block with the name of every file and directory listed
5
+ # as arguments, then recursively on their subdirectories, and so on.
6
+ #
7
+ # Returns an enumerator if no block is given.
8
+ #
9
+ # See the +Find+ module documentation for an example.
10
+ #
11
+ def find(*paths, ignore_error: true) # :yield: path
12
+ block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
13
+
14
+ fs_encoding = Encoding.find("filesystem")
15
+
16
+ paths.collect!{|d| raise Errno::ENOENT, d unless File.exist?(d); d.dup}.each do |path|
17
+ path = path.to_path if path.respond_to? :to_path
18
+ enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
19
+ ps = [path]
20
+ while file = ps.shift
21
+ catch(:prune) do
22
+ yield file.dup
23
+ begin
24
+ s = File.lstat(file)
25
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EPERM
26
+ raise unless ignore_error
27
+ next
28
+ end
29
+ if s.directory? then
30
+ begin
31
+ fs = Dir.children(file, encoding: enc)
32
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EPERM
33
+ raise unless ignore_error
34
+ next
35
+ end
36
+ fs.sort!
37
+ fs.reverse_each {|f|
38
+ f = File.join(file, f)
39
+ ps.unshift f
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ nil
46
+ end
47
+
48
+ #
49
+ # Skips the current file or directory, restarting the loop with the next
50
+ # entry. If the current file is a directory, that directory will not be
51
+ # recursively entered. Meaningful only within the block associated with
52
+ # Find::find.
53
+ #
54
+ # See the +Find+ module documentation for an example.
55
+ #
56
+ def prune
57
+ throw :prune
58
+ end
59
+
60
+ module_function :find, :prune
61
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diskcatalog
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/diskcatalog.rb CHANGED
@@ -1,22 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "diskcatalog/my_find"
3
4
  require_relative "diskcatalog/version"
4
5
 
5
- require 'find'
6
6
  require 'optparse'
7
7
  require 'fileutils'
8
+ require 'yaml'
9
+
10
+
8
11
 
9
12
  module Diskcatalog
10
13
  class Error < StandardError; end
11
-
14
+
15
+ class Config
16
+ CATALOGDIR = File.expand_path("~/.catalog")
17
+
18
+ def self.create_from_yaml(yaml)
19
+ config = Config.new
20
+ catalogdir = config_value(yaml, "general", "catalogdir", true)
21
+ if catalogdir
22
+ catalogdir = File.expand_path(catalogdir)
23
+ end
24
+ config.catalogdir = catalogdir
25
+
26
+ ## puts config.catalogdir
27
+ config.init_default
28
+ if config.catalogdir.nil? || !FileTest.directory?(config.catalogdir)
29
+ raise RuntimeError, "catalogdir is not exist: #{config.catalogdir}"
30
+ end
31
+ config
32
+ end
33
+
34
+ def self.config_value(yaml, section, key, require)
35
+ return nil unless yaml
36
+ return nil unless yaml[section]
37
+ value = yaml[section][key]
38
+ if require && (value.nil? || value.empty?)
39
+ raise RuntimeError, "#{section}:#{key}: is empty"
40
+ end
41
+ value
42
+ end
43
+
44
+ def init_default
45
+ @catalogdir ||= CATALOGDIR
46
+ end
47
+
48
+ attr_accessor :catalogdir
49
+ end
50
+
51
+
12
52
  class Option
13
- def initialize(opts, dirs)
53
+ def initialize(opts, dirs, config)
14
54
  @opts = opts
15
55
  @dir = dirs[0] if dirs.size > 0
56
+ @config = config
16
57
  @debug = @opts[:d]
17
58
  @output = @opts[:o]
18
- @output_files = @output + '.files'
19
- @output_info = @output + '.info'
59
+ @output_files = File.join(config.catalogdir, @output + '.files')
60
+ @output_info = File.join(config.catalogdir, @output + '.info')
20
61
  @debug = true
21
62
  end
22
63
  attr_reader :dir, :debug, :output, :output_files, :output_info
@@ -36,12 +77,21 @@ module Diskcatalog
36
77
  end
37
78
  opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v}
38
79
  opt.on('-o FILENAME', '--output=FILENAME') {|v| opts[:o] = v}
80
+ opt.on('--config=CONFIGFILE', 'Config file') {|v| opts[:c] = v }
39
81
  opt.parse!(argv)
40
82
  if opts[:o].nil?
41
83
  puts opt.help
42
84
  exit
43
85
  end
44
- option = Option.new(opts, argv)
86
+ config_file = opts[:c] || "~/.catalogrc"
87
+ puts config_file
88
+ config_file = File.expand_path(config_file)
89
+ yaml = nil
90
+ if FileTest.file?(config_file)
91
+ yaml = YAML.load_file(config_file)
92
+ end
93
+ config = Config.create_from_yaml(yaml)
94
+ option = Option.new(opts, argv, config)
45
95
  begin
46
96
  command = Command.new(option)
47
97
  command.run
@@ -72,15 +122,20 @@ module Diskcatalog
72
122
  raise RuntimeError
73
123
  end
74
124
  out = File.open(@opt.output_files, "w:utf-8")
75
- Find.find(@opt.dir, ignore_error: true) do |f|
76
- if FileTest.file?(f)
77
- size = File.size(f)
78
- mtime = File.mtime(f).strftime("%Y-%m-%d")
79
- out.puts "#{f}\t#{size}\t#{mtime}"
80
- elsif FileTest.directory?(f)
81
- STDERR.puts f
82
- end
83
- end
125
+ begin
126
+ MyFind.find(@opt.dir, ignore_error: true) do |f|
127
+ if FileTest.file?(f)
128
+ size = File.size(f)
129
+ mtime = File.mtime(f).strftime("%Y-%m-%d")
130
+ out.puts "#{f}\t#{size}\t#{mtime}"
131
+ elsif FileTest.directory?(f)
132
+ STDERR.puts f
133
+ end
134
+ end
135
+ rescue => e
136
+ p e.class
137
+ puts e.message
138
+ end
84
139
  out.close if out
85
140
  end
86
141
 
data/run_mkcat.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ curdir=$(dirname $0)
4
+ bundle exec ruby $curdir/exe/mkcat "$@"
5
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskcatalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - src
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-16 00:00:00.000000000 Z
11
+ date: 2023-08-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create disk catalog.
14
14
  email:
@@ -16,6 +16,7 @@ email:
16
16
  executables:
17
17
  - catalogsearch.cmd
18
18
  - diskcatalog
19
+ - mkcat
19
20
  extensions: []
20
21
  extra_rdoc_files: []
21
22
  files:
@@ -25,13 +26,17 @@ files:
25
26
  - LICENSE.txt
26
27
  - README.md
27
28
  - Rakefile
29
+ - build.sh
30
+ - catalogrc
28
31
  - diskcatalog.gemspec
29
32
  - exe/catalogsearch.cmd
30
33
  - exe/diskcatalog
34
+ - exe/mkcat
31
35
  - lib/diskcatalog.rb
36
+ - lib/diskcatalog/my_find.rb
32
37
  - lib/diskcatalog/version.rb
33
- - run_diskcatalog.cmd
34
- - run_diskcatalog.sh
38
+ - run_mkcat.cmd
39
+ - run_mkcat.sh
35
40
  - sig/diskcatalog.rbs
36
41
  homepage: https://github.com/src256
37
42
  licenses:
@@ -55,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
60
  - !ruby/object:Gem::Version
56
61
  version: '0'
57
62
  requirements: []
58
- rubygems_version: 3.2.22
63
+ rubygems_version: 3.2.33
59
64
  signing_key:
60
65
  specification_version: 4
61
66
  summary: Create disk catalog.
data/run_diskcatalog.sh DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
-
3
- curdir=$(dirname $0)
4
- bundle exec ruby $curdir/exe/diskcatalog "$@"
File without changes