libis-rosetta_checker 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ module Libis
2
+ module RosettaChecker
3
+ class FilesToIngestCleanupOptions
4
+ attr_accessor :command, :quiet, :log_file, :recursive, :report, :report_file, :delete, :dburl, :dbuser, :dbpass
5
+
6
+ def initialize(command)
7
+ self.command = command
8
+ self.delete = false
9
+ self.quiet = false
10
+ self.log_file = nil
11
+ self.recursive = false
12
+ self.report = true
13
+ default_report_file = "#{command.split(' ').last}-#{DateTime.now.strftime('%Y%m%d-%H%M%S')}.csv"
14
+ self.report_file = default_report_file
15
+ self.dburl = '//libis-db-rosetta:1551/ROSETTAP.kuleuven.be'
16
+ self.dbuser = 'V2KU_REP00'
17
+ self.dbpass = 'V2KU_REP00'
18
+ end
19
+
20
+ # @param [OptionParser] parser
21
+ def define(parser)
22
+ parser.banner = "Usage: #{command} [options] [[r_options] [directory|[@]file] ...]"
23
+ parser.separator ''
24
+ parser.separator 'This tool will scan directories for files that are/are not ingested in Rosetta.'
25
+ parser.separator ''
26
+ parser.separator 'If a file name preceded with a \'@\' is given as an argument, the file is expected to be a'
27
+ parser.separator 'text file with directory names - one directory per line.'
28
+ parser.separator ''
29
+
30
+ parser.separator 'The tool will compare the file sizes, MD5 checksums and file names with the information in the'
31
+ parser.separator 'Rosetta database to determine if a possible match is found.'
32
+ parser.separator 'with [r_options] (can be repeated in between directory/file inputs):'
33
+ define_quiet parser
34
+ define_logfile parser
35
+ define_recursive parser
36
+ parser.separator ''
37
+
38
+ parser.separator 'with [options]:'
39
+ define_report parser
40
+ define_report_file parser
41
+ # define_delete parser
42
+ define_dbparams parser
43
+ end
44
+
45
+ # @param [OptionParser] parser
46
+ def define_quiet(parser)
47
+ parser.on '-q', '--[no-]quiet', "Be quiet - no logging output on screen [#{self.quiet}]" do |flag|
48
+ self.quiet = flag
49
+ end
50
+ end
51
+
52
+ # @param [OptionParser] parser
53
+ def define_logfile(parser)
54
+ parser.on '-l', '--logfile [FILE]',
55
+ "Send logging output to file - appends to existing file [#{self.log_file}]",
56
+ '(re)set to empty string for no logging to file' do |file|
57
+ self.log_file = file
58
+ end
59
+ end
60
+
61
+ # @param [OptionParser] parser
62
+ def define_recursive(parser)
63
+ parser.on '-R', '--[no-]recursive', "Parse through subdirectories [#{self.recursive}]" do |flag|
64
+ self.recursive = flag
65
+ end
66
+ end
67
+
68
+ # @param [OptionParser] parser
69
+ def define_report(parser)
70
+ parser.on '--[no-]report', "Create a report file - overwrites existing file [#{self.report}]" do |flag|
71
+ self.report = flag
72
+ end
73
+ end
74
+
75
+ # @param [OptionParser] parser
76
+ def define_report_file(parser)
77
+ parser.on '-o', '--output-file [FILE]',
78
+ "File name for the report, if enabled [#{self.report_file}]" do |file|
79
+ self.report_file = file
80
+ end
81
+ end
82
+
83
+ # @param [OptionParser] parser
84
+ def define_delete(parser)
85
+ parser.on '-D', '--[no-]delete',
86
+ "Perform file deletes when file is ingested [#{self.delete}]" do |flag|
87
+ self.delete = flag
88
+ end
89
+ end
90
+
91
+ # @param [OptionParser] parser
92
+ def define_dbparams(parser)
93
+ parser.on '--db-url [URL]', "Database connection URL [#{self.dburl}]" do |url|
94
+ self.dburl = url
95
+ end
96
+ parser.on '--db-user [USER]', "Database user name [#{self.dbuser}]" do |user|
97
+ self.dbuser = user
98
+ end
99
+ parser.on '--db-pass [PASSWORD]', "Database password [#{self.dbpass}" do |pass|
100
+ self.dbpass = pass
101
+ end
102
+ end
103
+
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,60 @@
1
+ require 'optionparser'
2
+
3
+ module Libis
4
+ module RosettaChecker
5
+ class SubCommand
6
+ def self.short_desc
7
+ raise RuntimeError, 'Method should be overwritten'
8
+ end
9
+
10
+ def self.command
11
+ raise RuntimeError, 'Method should be overwritten'
12
+ end
13
+
14
+ def self.options_class
15
+ raise RuntimeError, 'Method should be overwritten'
16
+ end
17
+
18
+ def self.help
19
+ self.options('-h')
20
+ end
21
+
22
+ def self.options(*argv)
23
+ argv = ARGV if argv.empty?
24
+ @config ||= self.options_class.new "#{RosettaChecker.main_command} #{self.command}"
25
+ parse_options(argv)
26
+ end
27
+
28
+ def self.parse_options(argv)
29
+ OptionParser.new do |opts|
30
+ @config.define opts
31
+ opts.on '-h', '--help', 'Show this help' do
32
+ puts opts
33
+ exit
34
+ end
35
+ end.order!(argv)
36
+ end
37
+
38
+ def self.run
39
+ self.options
40
+ instance = self.new(@config)
41
+ instance.run(ARGV)
42
+ rescue OptionParser::ParseError => e
43
+ puts "ERROR: #{e.message}"
44
+ puts ''
45
+ self.help
46
+ rescue StandardError => e
47
+ $stderr.puts "ERROR: #{e.message} @ #{e.backtrace.first}"
48
+ ap e.backtrace
49
+ rescue Interrupt
50
+ $stderr.puts "ERROR: Interrupted."
51
+ ensure
52
+ instance.finalize if instance
53
+ end
54
+
55
+ def self.subcommands
56
+ Hash[ObjectSpace.each_object(Class).select {|klass| klass < self}.map {|klass| [klass.command, klass]}]
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module Libis
2
+ module RosettaChecker
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require "libis/rosetta_checker/version"
2
+ require 'optionparser'
3
+ require 'awesome_print'
4
+
5
+ require_relative 'rosetta_checker/sub_command'
6
+ require_relative 'rosetta_checker/files_to_ingest_cleanup'
7
+
8
+ module Libis
9
+ module RosettaChecker
10
+
11
+ def self.main_command
12
+ @main_command ||= File.basename($0)
13
+ end
14
+
15
+ def self.subcommands
16
+ @subcommands ||= SubCommand.subcommands
17
+ end
18
+
19
+ def self.help
20
+ puts "Usage: #{main_command} [command [cmd_options]]"
21
+ puts ''
22
+ puts 'Commands are:'
23
+ puts ' help : Show more help for a specific command'
24
+ subcommands.each do |k,v|
25
+ puts " #{k.to_s} : #{v.short_desc}"
26
+ end
27
+ puts ''
28
+ puts "See '#{main_command} help COMMAND' or '#{main_command} COMMAND --help' for more information."
29
+ puts "A more detailed discussion on the toolkit is available on-line on the LIBIS teamwork" +
30
+ " (https://libis.teamwork.com/#/notebooks/168158)."
31
+ exit
32
+ end
33
+
34
+ def self.run
35
+
36
+ first_command = command = ARGV.shift
37
+ help if command.nil?
38
+ command = ARGV.shift if command == 'help'
39
+ cmd_class = subcommands[command]
40
+ help if cmd_class.nil?
41
+ cmd_class.help if first_command == 'help'
42
+ cmd_class.run
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "libis/rosetta_checker/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "libis-rosetta_checker"
8
+ spec.version = Libis::RosettaChecker::VERSION
9
+ spec.authors = ["Kris Dekeyser"]
10
+ spec.email = ["kris.dekeyser@libis.be"]
11
+
12
+ spec.summary = %q{Rosetta checker toolkit.}
13
+ spec.description = %q{A set of command-line tools to check the consistency of the Rosetta preservation system.}
14
+ spec.homepage = "https://github.com/libis/rosetta_checker.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+ ''
32
+ spec.add_runtime_dependency "ruby-oci8", "~> 2.2"
33
+ spec.add_runtime_dependency "ruby-progressbar", "~> 1.9"
34
+ spec.add_runtime_dependency "awesome_print", "~> 1.8"
35
+ spec.add_runtime_dependency 'bzip2-ffi', '~> 1.0'
36
+ spec.add_runtime_dependency 'rubyzip', '~> 1.2'
37
+ spec.add_runtime_dependency 'logging', '~> 2.2'
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libis-rosetta_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kris Dekeyser
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-oci8
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-progressbar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bzip2-ffi
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubyzip
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: logging
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description: A set of command-line tools to check the consistency of the Rosetta preservation
140
+ system.
141
+ email:
142
+ - kris.dekeyser@libis.be
143
+ executables:
144
+ - rosetta_checker
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".idea/libis-rosetta_checker.iml"
150
+ - ".idea/misc.xml"
151
+ - ".idea/modules.xml"
152
+ - ".idea/workspace.xml"
153
+ - ".rspec"
154
+ - ".travis.yml"
155
+ - CODE_OF_CONDUCT.md
156
+ - Gemfile
157
+ - LICENSE.txt
158
+ - README.md
159
+ - Rakefile
160
+ - bin/console
161
+ - bin/setup
162
+ - exe/rosetta_checker
163
+ - lib/libis/rosetta_checker.rb
164
+ - lib/libis/rosetta_checker/files_to_ingest_cleanup.rb
165
+ - lib/libis/rosetta_checker/options/files_to_ingest_cleanup.rb
166
+ - lib/libis/rosetta_checker/sub_command.rb
167
+ - lib/libis/rosetta_checker/version.rb
168
+ - libis-rosetta_checker.gemspec
169
+ homepage: https://github.com/libis/rosetta_checker.git
170
+ licenses:
171
+ - MIT
172
+ metadata:
173
+ allowed_push_host: https://rubygems.org
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.6.14
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Rosetta checker toolkit.
194
+ test_files: []