diskcatalog 0.2.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/diskcatalog.iml ADDED
@@ -0,0 +1,84 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ <orderEntry type="module-library">
9
+ <library name="minitest (vbundled(5.19.0)) [path][gem]" type="rubylib">
10
+ <properties>
11
+ <option name="version" value="4" />
12
+ </properties>
13
+ <CLASSES>
14
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/lib" />
15
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/test" />
16
+ </CLASSES>
17
+ <JAVADOC />
18
+ <SOURCES>
19
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/lib" />
20
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/test" />
21
+ </SOURCES>
22
+ <excluded>
23
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/test" />
24
+ </excluded>
25
+ </library>
26
+ </orderEntry>
27
+ <orderEntry type="module-library">
28
+ <library name="rake (vbundled(13.0.6)) [path][gem]" type="rubylib">
29
+ <properties>
30
+ <option name="version" value="4" />
31
+ </properties>
32
+ <CLASSES>
33
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/doc" />
34
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe" />
35
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib" />
36
+ </CLASSES>
37
+ <JAVADOC />
38
+ <SOURCES>
39
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/doc" />
40
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe" />
41
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib" />
42
+ </SOURCES>
43
+ <excluded>
44
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/doc" />
45
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe" />
46
+ </excluded>
47
+ </library>
48
+ </orderEntry>
49
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.10, rbenv: 3.1.4) [gem]" level="application" />
50
+ </component>
51
+ <component name="RakeTasksCache">
52
+ <option name="myRootTask">
53
+ <RakeTaskImpl id="rake">
54
+ <subtasks>
55
+ <RakeTaskImpl description="Build diskcatalog-0.3.0.gem into the pkg directory" fullCommand="build" id="build" />
56
+ <RakeTaskImpl id="build">
57
+ <subtasks>
58
+ <RakeTaskImpl description="Generate SHA512 checksum if diskcatalog-0.3.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
59
+ </subtasks>
60
+ </RakeTaskImpl>
61
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
62
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
63
+ <RakeTaskImpl description="Build and install diskcatalog-0.3.0.gem into system gems" fullCommand="install" id="install" />
64
+ <RakeTaskImpl id="install">
65
+ <subtasks>
66
+ <RakeTaskImpl description="Build and install diskcatalog-0.3.0.gem into system gems without network access" fullCommand="install:local" id="local" />
67
+ </subtasks>
68
+ </RakeTaskImpl>
69
+ <RakeTaskImpl description="Create tag v0.3.0 and build and push diskcatalog-0.3.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
70
+ <RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
71
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
72
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
73
+ <RakeTaskImpl id="release">
74
+ <subtasks>
75
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
76
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
77
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
78
+ </subtasks>
79
+ </RakeTaskImpl>
80
+ </subtasks>
81
+ </RakeTaskImpl>
82
+ </option>
83
+ </component>
84
+ </module>
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "diskcatalog"
4
4
 
5
- Diskcatalog::Command.run(ARGV)
5
+ Diskcatalog::CreateCommand.run(ARGV)
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "diskcatalog"
4
4
 
5
- Diskcatalog::Command.run(ARGV)
5
+ Diskcatalog::SearchCommand.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.2.0"
4
+ VERSION = "0.9.0"
5
5
  end
data/lib/diskcatalog.rb CHANGED
@@ -1,15 +1,20 @@
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
8
  require 'yaml'
9
9
 
10
+
11
+
10
12
  module Diskcatalog
13
+ DEF_CONFIG = File.expand_path("~/.catalogrc")
14
+ SEARCH_CMD = "rg"
15
+
11
16
  class Error < StandardError; end
12
-
17
+
13
18
  class Config
14
19
  CATALOGDIR = File.expand_path("~/.catalog")
15
20
 
@@ -46,22 +51,72 @@ module Diskcatalog
46
51
  attr_accessor :catalogdir
47
52
  end
48
53
 
49
-
50
54
  class Option
51
- def initialize(opts, dirs, config)
55
+ def initialize(opts, argv, config)
52
56
  @opts = opts
53
- @dir = dirs[0] if dirs.size > 0
57
+ @argv = argv
54
58
  @config = config
55
- @debug = @opts[:d]
59
+ @debug = @opts[:d]
60
+ @list = false
61
+ if @opts[:l]
62
+ @list = true
63
+ end
64
+ end
65
+ attr_reader :debug, :list
66
+ def catalogdir
67
+ @config.catalogdir
68
+ end
69
+ end
70
+
71
+ class CreateOption < Option
72
+ def initialize(opts, argv, config)
73
+ super
74
+ @dir = nil
75
+ if argv.size > 0 && FileTest.directory?(argv[0])
76
+ @dir = argv[0]
77
+ end
78
+
56
79
  @output = @opts[:o]
57
- @output_files = File.join(config.catalogdir, @output + '.files')
58
- @output_info = File.join(config.catalogdir, @output + '.info')
59
- @debug = true
80
+ if @output
81
+ @output_files = File.join(catalogdir, @output + '.files')
82
+ @output_info = File.join(catalogdir, @output + '.info')
83
+ end
60
84
  end
61
- attr_reader :dir, :debug, :output, :output_files, :output_info
85
+ attr_reader :dir, :search, :debug, :output, :output_files, :output_info
86
+ end
87
+
88
+ class SearchOption < Option
89
+ def initialize(opts, argv, config)
90
+ super
91
+ @search = nil
92
+ if argv.size > 0
93
+ @search = argv[0]
94
+ end
95
+ end
96
+ attr_reader :search
62
97
  end
63
98
 
64
99
  class Command
100
+ def self.load_yaml(config_file)
101
+ config_file ||= DEF_CONFIG
102
+ config_file = File.expand_path(config_file)
103
+ puts "Config: #{config_file}"
104
+ yaml = nil
105
+ if FileTest.file?(config_file)
106
+ yaml = YAML.load_file(config_file)
107
+ end
108
+ Config.create_from_yaml(yaml)
109
+ end
110
+
111
+ def list
112
+ puts "List catalog in #{@opt.catalogdir}"
113
+ Dir.glob(File.join(@opt.catalogdir, "*.info")).each do |path|
114
+ puts File.basename(path)
115
+ end
116
+ end
117
+ end
118
+
119
+ class CreateCommand < Command
65
120
  def self.run(argv)
66
121
  STDOUT.sync = true
67
122
  opts = {}
@@ -76,30 +131,23 @@ module Diskcatalog
76
131
  opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v}
77
132
  opt.on('-o FILENAME', '--output=FILENAME') {|v| opts[:o] = v}
78
133
  opt.on('--config=CONFIGFILE', 'Config file') {|v| opts[:c] = v }
134
+ opt.on('-l', '--list') {|v| opts[:l] = v}
79
135
  opt.parse!(argv)
80
- if opts[:o].nil?
81
- puts opt.help
82
- exit
83
- end
84
- config_file = opts[:c] || "~/.catalogrc"
85
- puts config_file
86
- config_file = File.expand_path(config_file)
87
- yaml = nil
88
- if FileTest.file?(config_file)
89
- yaml = YAML.load_file(config_file)
90
- end
91
- config = Config.create_from_yaml(yaml)
92
- option = Option.new(opts, argv, config)
136
+ # if opts[:o].nil?
137
+ # puts opt.help
138
+ # exit
139
+ # end
140
+ config = load_yaml(opts[:c])
141
+ option = CreateOption.new(opts, argv, config)
93
142
  begin
94
- command = Command.new(option)
143
+ command = CreateCommand.new(option)
95
144
  command.run
96
145
  rescue => e
146
+ puts e.message
97
147
  if option.debug
98
- p e.message
99
- p e.backtrace
148
+ puts e.backtrace
100
149
  end
101
150
  puts opt.help
102
- exit
103
151
  end
104
152
  end
105
153
 
@@ -108,27 +156,41 @@ module Diskcatalog
108
156
  end
109
157
 
110
158
  def run
111
- puts @opt.dir
112
-
113
- make_files
114
- make_info
159
+ if @opt.list
160
+ list
161
+ else
162
+ unless @opt.dir
163
+ raise "directory is not specified"
164
+ end
165
+ make_files
166
+ make_info
167
+ end
115
168
  end
116
169
 
117
170
  private
118
171
  def make_files
172
+ puts "Create catalog for #{@opt.dir}"
119
173
  unless FileTest.directory?(@opt.dir)
120
174
  raise RuntimeError
121
175
  end
122
176
  out = File.open(@opt.output_files, "w:utf-8")
123
- Find.find(@opt.dir, ignore_error: true) do |f|
124
- if FileTest.file?(f)
125
- size = File.size(f)
126
- mtime = File.mtime(f).strftime("%Y-%m-%d")
127
- out.puts "#{f}\t#{size}\t#{mtime}"
128
- elsif FileTest.directory?(f)
129
- STDERR.puts f
177
+ begin
178
+ MyFind.find(@opt.dir, ignore_error: true) do |f|
179
+ if FileTest.file?(f)
180
+ size = File.size(f)
181
+ mtime = File.mtime(f).strftime("%Y-%m-%d")
182
+ out.puts "#{f}\t#{size}\t#{mtime}"
183
+ elsif FileTest.directory?(f)
184
+ STDERR.puts f
185
+ end
186
+ end
187
+ rescue => e
188
+ puts e.message
189
+ if option.debug
190
+ p e.backtrace
130
191
  end
131
- end
192
+ p e.class
193
+ end
132
194
  out.close if out
133
195
  end
134
196
 
@@ -139,4 +201,50 @@ module Diskcatalog
139
201
  out.close if out
140
202
  end
141
203
  end
204
+
205
+ class SearchCommand < Command
206
+ def self.run(argv)
207
+ STDOUT.sync = true
208
+ opts = {}
209
+ opt = OptionParser.new(argv)
210
+ opt.version = VERSION
211
+ opt.banner = "Usage: #{opt.program_name} [options] <directory>"
212
+ opt.separator('Options')
213
+ opt.on_head('-h', '--help', 'show this message') do |v|
214
+ puts opt.help
215
+ exit
216
+ end
217
+ opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v}
218
+ opt.on('--config=CONFIGFILE', 'Config file') {|v| opts[:c] = v }
219
+ opt.parse!(argv)
220
+ config = load_yaml(opts[:c])
221
+ option = SearchOption.new(opts, argv, config)
222
+ begin
223
+ command = SearchCommand.new(option)
224
+ command.run
225
+ rescue => e
226
+ puts e.message
227
+ if option.debug
228
+ p e.backtrace
229
+ end
230
+ puts opt.help
231
+ end
232
+ end
233
+
234
+ def initialize(option)
235
+ @opt = option
236
+ end
237
+
238
+ def run
239
+ if @opt.list
240
+ list
241
+ else
242
+ search
243
+ end
244
+ end
245
+
246
+ def search
247
+ system("#{SEARCH_CMD} #{@opt.search} #{@opt.catalogdir}")
248
+ end
249
+ end
142
250
  end
Binary file
Binary file
Binary file
data/run_dcatc.cmd ADDED
@@ -0,0 +1,5 @@
1
+ @echo off
2
+
3
+ call uru 305p211
4
+
5
+ bundle exec ruby exe/dcatc %*
data/run_dcatc.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ curdir=$(dirname $0)
4
+ bundle exec ruby $curdir/exe/dcatc "$@"
5
+
data/run_dcats.cmd ADDED
@@ -0,0 +1,5 @@
1
+ @echo off
2
+
3
+ call uru 305p211
4
+
5
+ bundle exec ruby exe/dcats %*
data/run_dcats.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ curdir=$(dirname $0)
4
+ bundle exec ruby $curdir/exe/dcats "$@"
5
+
metadata CHANGED
@@ -1,42 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskcatalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.9.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-08-02 00:00:00.000000000 Z
11
+ date: 2023-08-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create disk catalog.
14
14
  email:
15
15
  - src@srcw.net
16
16
  executables:
17
17
  - catalogsearch.cmd
18
- - diskcatalog
19
- - mkcat
18
+ - dcatc
19
+ - dcats
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
+ - ".idea/.gitignore"
24
+ - ".idea/misc.xml"
25
+ - ".idea/vcs.xml"
23
26
  - CODE_OF_CONDUCT.md
24
27
  - Gemfile
25
28
  - Gemfile.lock
26
29
  - LICENSE.txt
27
30
  - README.md
28
31
  - Rakefile
32
+ - build.cmd
29
33
  - build.sh
30
34
  - catalogrc
35
+ - data/.gitignore
36
+ - data/ext.files
31
37
  - diskcatalog.gemspec
38
+ - diskcatalog.iml
32
39
  - exe/catalogsearch.cmd
33
- - exe/diskcatalog
34
- - exe/mkcat
40
+ - exe/dcatc
41
+ - exe/dcats
35
42
  - lib/diskcatalog.rb
43
+ - lib/diskcatalog/my_find.rb
36
44
  - lib/diskcatalog/version.rb
37
- - run_mkcat.cmd
38
- - run_mkcat.sh
45
+ - pkg/diskcatalog-0.1.0.gem
46
+ - pkg/diskcatalog-0.2.0.gem
47
+ - pkg/diskcatalog-0.3.0.gem
48
+ - run_dcatc.cmd
49
+ - run_dcatc.sh
50
+ - run_dcats.cmd
51
+ - run_dcats.sh
39
52
  - sig/diskcatalog.rbs
53
+ - test_diskcatalog.cmd
40
54
  homepage: https://github.com/src256
41
55
  licenses:
42
56
  - MIT
data/run_mkcat.sh DELETED
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
-
3
- curdir=$(dirname $0)
4
- bundle exec ruby $curdir/exe/mkcat "$@"
5
-
File without changes