-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding executable to run surveyor from the command line.
Changing surveyor to not recreate survey items for existing items when you run the executable multiple times.
- Loading branch information
1 parent
a100b37
commit 9fc2197
Showing
3 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env ruby | ||
require 'rails' | ||
|
||
require ::File.join(File.dirname(Bundler.default_gemfile), 'config/environment') | ||
|
||
options = {} | ||
|
||
subtext = <<HELP | ||
Commonly used command are: | ||
clean : cleans all Sufia::Migration::Survey::Items from the database | ||
See 'sufia_survey COMMAND --help' for more information on a specific command. | ||
HELP | ||
|
||
args = OptionParser.new do |opts| | ||
opts.banner = "Survey model objects in fedora and store it in an ActiveRecord table. Usage: sufia_survey [options]" | ||
|
||
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| | ||
options[:verbose] = v | ||
end | ||
|
||
opts.on("--limit NUMBER_OF_OBJECTS", Integer, "Survey a maximum number of objects (defaults to all)") do |v| | ||
options[:limit] = v | ||
end | ||
|
||
opts.on("--ids ID_LIST", Array, "Survey only the objects in the list of IDs", | ||
"For example to survey a Collection with the id abc123 and a GenericFile with an id def456:", | ||
" --ids abc123,def456") do |v| | ||
options[:ids] = v | ||
end | ||
|
||
opts.on("--models MODEL_LIST", Array, "Specify the models to be surveyed (defaults to GenericFile,Collection)") do |v| | ||
options[:models] = v | ||
end | ||
|
||
opts.on("--models MODEL_LIST", Array, "Specify the models to be surveyed (defaults to GenericFile,Collection)") do |v| | ||
options[:models] = v | ||
end | ||
|
||
opts.separator "" | ||
opts.separator subtext | ||
end | ||
|
||
subcommands = { | ||
'clean' => OptionParser.new do |opts| | ||
opts.banner = "Usage: sufia_survey clean" | ||
end | ||
} | ||
|
||
begin | ||
args.order! | ||
command = ARGV.shift | ||
if command | ||
raise "Bad subcommand: #{command}" unless subcommands[command] | ||
subcommands[command].order! | ||
end | ||
args.parse! | ||
rescue => error | ||
$stderr.puts "ERROR: #{error}\n" | ||
$stderr.puts args.help | ||
exit 1 | ||
end | ||
|
||
if command == 'clean' | ||
$stderr.puts "cleaning Sufia::Migration::Survey::Item" | ||
Sufia::Migration::Survey::Item.delete_all | ||
exit 0 | ||
end | ||
|
||
verbose = options[:verbose] | ||
|
||
$stdout.puts "running with #{options}" if verbose | ||
id_service = Sufia::Migration::Survey::FedoraIdService.new | ||
|
||
if options[:models] | ||
model_options = options.delete(:models) | ||
$stdout.puts "processing models #{model_options}" if verbose | ||
model_options.each do |model_str| | ||
model_class = Object.const_get(model_str) | ||
id_service.register_model(model_class) unless id_service.model_registry.keys.include?(model_class) | ||
end | ||
end | ||
|
||
if options[:ids] | ||
ids = options[:ids] | ||
else | ||
$stdout.puts "Sending fedora_id with #{id_service.model_registry} and #{options}" if verbose | ||
ids = id_service.call(options[:limit] || :all) | ||
end | ||
|
||
$stdout.puts "Sending call with ids: #{ids}" if verbose | ||
Sufia::Migration::Survey::Surveyor.call(ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters