diskcatalog 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/diskcatalog.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.bindir = "exe"
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
-
32
+ spec.add_dependency "sys-filesystem"
33
33
  # Uncomment to register a new dependency of your gem
34
34
  # spec.add_dependency "example-gem", "~> 1.0"
35
35
 
data/diskcatalog.iml ADDED
@@ -0,0 +1,134 @@
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="ffi (vbundled(1.15.5)) [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/ffi-1.15.5/ext" />
15
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib" />
16
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/rakelib" />
17
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/samples" />
18
+ </CLASSES>
19
+ <JAVADOC />
20
+ <SOURCES>
21
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/ext" />
22
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib" />
23
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/rakelib" />
24
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/samples" />
25
+ </SOURCES>
26
+ <excluded>
27
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/ext" />
28
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/rakelib" />
29
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/samples" />
30
+ </excluded>
31
+ </library>
32
+ </orderEntry>
33
+ <orderEntry type="module-library">
34
+ <library name="minitest (vbundled(5.19.0)) [path][gem]" type="rubylib">
35
+ <properties>
36
+ <option name="version" value="4" />
37
+ </properties>
38
+ <CLASSES>
39
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/lib" />
40
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/test" />
41
+ </CLASSES>
42
+ <JAVADOC />
43
+ <SOURCES>
44
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/lib" />
45
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/test" />
46
+ </SOURCES>
47
+ <excluded>
48
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/minitest-5.19.0/test" />
49
+ </excluded>
50
+ </library>
51
+ </orderEntry>
52
+ <orderEntry type="module-library">
53
+ <library name="rake (vbundled(13.0.6)) [path][gem]" type="rubylib">
54
+ <properties>
55
+ <option name="version" value="4" />
56
+ </properties>
57
+ <CLASSES>
58
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/doc" />
59
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe" />
60
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib" />
61
+ </CLASSES>
62
+ <JAVADOC />
63
+ <SOURCES>
64
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/doc" />
65
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe" />
66
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib" />
67
+ </SOURCES>
68
+ <excluded>
69
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/doc" />
70
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe" />
71
+ </excluded>
72
+ </library>
73
+ </orderEntry>
74
+ <orderEntry type="module-library">
75
+ <library name="sys-filesystem (vbundled(1.4.3)) [path][gem]" type="rubylib">
76
+ <properties>
77
+ <option name="version" value="4" />
78
+ </properties>
79
+ <CLASSES>
80
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/lib" />
81
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/spec" />
82
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/certs" />
83
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/examples" />
84
+ </CLASSES>
85
+ <JAVADOC />
86
+ <SOURCES>
87
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/lib" />
88
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/spec" />
89
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/certs" />
90
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/examples" />
91
+ </SOURCES>
92
+ <excluded>
93
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/spec" />
94
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/certs" />
95
+ <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.1.0/gems/sys-filesystem-1.4.3/examples" />
96
+ </excluded>
97
+ </library>
98
+ </orderEntry>
99
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.10, rbenv: 3.1.4) [gem]" level="application" />
100
+ </component>
101
+ <component name="RakeTasksCache">
102
+ <option name="myRootTask">
103
+ <RakeTaskImpl id="rake">
104
+ <subtasks>
105
+ <RakeTaskImpl description="Build diskcatalog-0.9.0.gem into the pkg directory" fullCommand="build" id="build" />
106
+ <RakeTaskImpl id="build">
107
+ <subtasks>
108
+ <RakeTaskImpl description="Generate SHA512 checksum if diskcatalog-0.9.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
109
+ </subtasks>
110
+ </RakeTaskImpl>
111
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
112
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
113
+ <RakeTaskImpl description="Build and install diskcatalog-0.9.0.gem into system gems" fullCommand="install" id="install" />
114
+ <RakeTaskImpl id="install">
115
+ <subtasks>
116
+ <RakeTaskImpl description="Build and install diskcatalog-0.9.0.gem into system gems without network access" fullCommand="install:local" id="local" />
117
+ </subtasks>
118
+ </RakeTaskImpl>
119
+ <RakeTaskImpl description="Create tag v0.9.0 and build and push diskcatalog-0.9.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
120
+ <RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
121
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
122
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
123
+ <RakeTaskImpl id="release">
124
+ <subtasks>
125
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
126
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
127
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
128
+ </subtasks>
129
+ </RakeTaskImpl>
130
+ </subtasks>
131
+ </RakeTaskImpl>
132
+ </option>
133
+ </component>
134
+ </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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diskcatalog
4
- VERSION = "0.3.0"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/diskcatalog.rb CHANGED
@@ -6,10 +6,12 @@ require_relative "diskcatalog/version"
6
6
  require 'optparse'
7
7
  require 'fileutils'
8
8
  require 'yaml'
9
-
10
-
9
+ require 'sys/filesystem'
11
10
 
12
11
  module Diskcatalog
12
+ DEF_CONFIG = File.expand_path("~/.catalogrc")
13
+ SEARCH_CMD = "rg"
14
+
13
15
  class Error < StandardError; end
14
16
 
15
17
  class Config
@@ -48,22 +50,72 @@ module Diskcatalog
48
50
  attr_accessor :catalogdir
49
51
  end
50
52
 
51
-
52
53
  class Option
53
- def initialize(opts, dirs, config)
54
+ def initialize(opts, argv, config)
54
55
  @opts = opts
55
- @dir = dirs[0] if dirs.size > 0
56
+ @argv = argv
56
57
  @config = config
57
- @debug = @opts[:d]
58
+ @debug = @opts[:d]
59
+ @list = false
60
+ if @opts[:l]
61
+ @list = true
62
+ end
63
+ end
64
+ attr_reader :debug, :list
65
+ def catalogdir
66
+ @config.catalogdir
67
+ end
68
+ end
69
+
70
+ class CreateOption < Option
71
+ def initialize(opts, argv, config)
72
+ super
73
+ @dir = nil
74
+ if argv.size > 0 && FileTest.directory?(argv[0])
75
+ @dir = argv[0]
76
+ end
77
+
58
78
  @output = @opts[:o]
59
- @output_files = File.join(config.catalogdir, @output + '.files')
60
- @output_info = File.join(config.catalogdir, @output + '.info')
61
- @debug = true
79
+ if @output
80
+ @output_files = File.join(catalogdir, @output + '.files')
81
+ @output_info = File.join(catalogdir, @output + '.info')
82
+ end
83
+ end
84
+ attr_reader :dir, :search, :debug, :output, :output_files, :output_info
85
+ end
86
+
87
+ class SearchOption < Option
88
+ def initialize(opts, argv, config)
89
+ super
90
+ @search = nil
91
+ if argv.size > 0
92
+ @search = argv[0]
93
+ end
62
94
  end
63
- attr_reader :dir, :debug, :output, :output_files, :output_info
95
+ attr_reader :search
64
96
  end
65
97
 
66
98
  class Command
99
+ def self.load_yaml(config_file)
100
+ config_file ||= DEF_CONFIG
101
+ config_file = File.expand_path(config_file)
102
+ puts "Config: #{config_file}"
103
+ yaml = nil
104
+ if FileTest.file?(config_file)
105
+ yaml = YAML.load_file(config_file)
106
+ end
107
+ Config.create_from_yaml(yaml)
108
+ end
109
+
110
+ def list
111
+ puts "List catalog in #{@opt.catalogdir}"
112
+ Dir.glob(File.join(@opt.catalogdir, "*.info")).each do |path|
113
+ puts File.basename(path)
114
+ end
115
+ end
116
+ end
117
+
118
+ class CreateCommand < Command
67
119
  def self.run(argv)
68
120
  STDOUT.sync = true
69
121
  opts = {}
@@ -78,30 +130,23 @@ module Diskcatalog
78
130
  opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v}
79
131
  opt.on('-o FILENAME', '--output=FILENAME') {|v| opts[:o] = v}
80
132
  opt.on('--config=CONFIGFILE', 'Config file') {|v| opts[:c] = v }
133
+ opt.on('-l', '--list') {|v| opts[:l] = v}
81
134
  opt.parse!(argv)
82
- if opts[:o].nil?
83
- puts opt.help
84
- exit
85
- end
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)
135
+ # if opts[:o].nil?
136
+ # puts opt.help
137
+ # exit
138
+ # end
139
+ config = load_yaml(opts[:c])
140
+ option = CreateOption.new(opts, argv, config)
95
141
  begin
96
- command = Command.new(option)
142
+ command = CreateCommand.new(option)
97
143
  command.run
98
144
  rescue => e
145
+ puts e.message
99
146
  if option.debug
100
- p e.message
101
- p e.backtrace
147
+ puts e.backtrace
102
148
  end
103
149
  puts opt.help
104
- exit
105
150
  end
106
151
  end
107
152
 
@@ -110,14 +155,20 @@ module Diskcatalog
110
155
  end
111
156
 
112
157
  def run
113
- puts @opt.dir
114
-
115
- make_files
116
- make_info
158
+ if @opt.list
159
+ list
160
+ else
161
+ unless @opt.dir
162
+ raise "directory is not specified"
163
+ end
164
+ make_files
165
+ make_info
166
+ end
117
167
  end
118
168
 
119
169
  private
120
170
  def make_files
171
+ puts "Create catalog for #{@opt.dir}"
121
172
  unless FileTest.directory?(@opt.dir)
122
173
  raise RuntimeError
123
174
  end
@@ -133,17 +184,98 @@ module Diskcatalog
133
184
  end
134
185
  end
135
186
  rescue => e
136
- p e.class
137
187
  puts e.message
138
- end
188
+ if option.debug
189
+ p e.backtrace
190
+ end
191
+ p e.class
192
+ end
139
193
  out.close if out
140
194
  end
141
195
 
142
196
  def make_info
197
+ puts "Create info for #{@opt.dir}"
198
+ unless FileTest.directory?(@opt.dir)
199
+ raise RuntimeError
200
+ end
201
+
202
+ stat = Sys::Filesystem.stat(@opt.dir)
203
+ free_bytes = number_to_human_size(stat.blocks_available * stat.block_size)
204
+ # puts number_to_human_size(free_bytes)
205
+ total_bytes = number_to_human_size(stat.blocks * stat.block_size)
206
+ #puts number_to_human_size(total_bytes)
207
+
143
208
  out = File.open(@opt.output_info, "w:utf-8")
144
209
  created = Time.now.strftime("%Y-%m-%dT%H:%M:%S")
145
210
  out.puts "Created: #{created}"
211
+ out.puts "Total: #{total_bytes}"
212
+ out.puts "Free: #{free_bytes}"
146
213
  out.close if out
147
214
  end
215
+
216
+ def number_to_human_size(size)
217
+ kb = 1024
218
+ mb = 1024**2
219
+ gb = 1024**3
220
+ tb = 1024**4
221
+ case
222
+ when size < 1024
223
+ '%d Bytes' % size
224
+ when size < kb
225
+ '%.1f KB' % (size / kb)
226
+ when size < mb
227
+ '%.1f MB' % (size / mb)
228
+ when size < 1024**4
229
+ '%.1f GB' % (size / gb)
230
+ else
231
+ '%.1f TB' % (size / tb)
232
+ end.sub('.0', '')
233
+ end
234
+ end
235
+
236
+ class SearchCommand < Command
237
+ def self.run(argv)
238
+ STDOUT.sync = true
239
+ opts = {}
240
+ opt = OptionParser.new(argv)
241
+ opt.version = VERSION
242
+ opt.banner = "Usage: #{opt.program_name} [options] <directory>"
243
+ opt.separator('Options')
244
+ opt.on_head('-h', '--help', 'show this message') do |v|
245
+ puts opt.help
246
+ exit
247
+ end
248
+ opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v}
249
+ opt.on('--config=CONFIGFILE', 'Config file') {|v| opts[:c] = v }
250
+ opt.parse!(argv)
251
+ config = load_yaml(opts[:c])
252
+ option = SearchOption.new(opts, argv, config)
253
+ begin
254
+ command = SearchCommand.new(option)
255
+ command.run
256
+ rescue => e
257
+ puts e.message
258
+ if option.debug
259
+ p e.backtrace
260
+ end
261
+ puts opt.help
262
+ end
263
+ end
264
+
265
+ def initialize(option)
266
+ @opt = option
267
+ end
268
+
269
+ def run
270
+ if @opt.list
271
+ list
272
+ else
273
+ search
274
+ end
275
+ end
276
+
277
+ def search
278
+ system("#{SEARCH_CMD} #{@opt.search} #{@opt.catalogdir}")
279
+ end
148
280
  end
149
281
  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,43 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskcatalog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.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
12
- dependencies: []
11
+ date: 2023-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sys-filesystem
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'
13
27
  description: Create disk catalog.
14
28
  email:
15
29
  - src@srcw.net
16
30
  executables:
17
31
  - catalogsearch.cmd
18
- - diskcatalog
19
- - mkcat
32
+ - dcatc
33
+ - dcats
20
34
  extensions: []
21
35
  extra_rdoc_files: []
22
36
  files:
37
+ - ".idea/.gitignore"
38
+ - ".idea/misc.xml"
39
+ - ".idea/vcs.xml"
23
40
  - CODE_OF_CONDUCT.md
24
41
  - Gemfile
25
42
  - Gemfile.lock
26
43
  - LICENSE.txt
27
44
  - README.md
28
45
  - Rakefile
46
+ - build.cmd
29
47
  - build.sh
30
48
  - catalogrc
49
+ - data/.gitignore
50
+ - data/ext.files
31
51
  - diskcatalog.gemspec
52
+ - diskcatalog.iml
32
53
  - exe/catalogsearch.cmd
33
- - exe/diskcatalog
34
- - exe/mkcat
54
+ - exe/dcatc
55
+ - exe/dcats
35
56
  - lib/diskcatalog.rb
36
57
  - lib/diskcatalog/my_find.rb
37
58
  - lib/diskcatalog/version.rb
38
- - run_mkcat.cmd
39
- - run_mkcat.sh
59
+ - pkg/diskcatalog-0.1.0.gem
60
+ - pkg/diskcatalog-0.2.0.gem
61
+ - pkg/diskcatalog-0.3.0.gem
62
+ - run_dcatc.cmd
63
+ - run_dcatc.sh
64
+ - run_dcats.cmd
65
+ - run_dcats.sh
40
66
  - sig/diskcatalog.rbs
67
+ - test_diskcatalog.cmd
41
68
  homepage: https://github.com/src256
42
69
  licenses:
43
70
  - 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