import-ontologies revision 49f4112620975dae84bcd13f02667b00f16a3448
#!/usr/bin/env ruby
require 'getoptlong'
def usage_message
$stderr << "#{File.basename( $0 )} [options] [dirs]
Imports ontology files from several directories into Ontohub.
-h This help.
-r Do not use redis for parsing jobs.
-u <uid> ID of user which should own imported objects.
"
exit 1
end
options = GetoptLong.new(
[ '-h', GetoptLong::NO_ARGUMENT ],
[ '-r', GetoptLong::NO_ARGUMENT ],
[ '-u', GetoptLong::REQUIRED_ARGUMENT ],
)
redis = true
uid = 1
allowed_extensions = %w(clif clf owl)
options.each do |option, argument|
case option
when '-h'
usage_message
when '-r'
redis = false
when '-u'
uid = argument.to_i
end
end
require File.expand_path('../../config/environment', __FILE__)
user = User.find(uid)
ARGV.each do |dir|
allowed_extensions.each do |ext|
Dir.glob("#{dir}/**/*.#{ext}").each do |file|
puts file
o = Ontology.new
o.iri = "file://#{file}"
o.name = File.basename(file, ".#{ext}")
o.save!
ov = OntologyVersion.new
ov.user = user
ov.raw_file = File.open(file)
ov.ontology = o
ov.save!
if redis
OntologyParsingWorker.perform_async(ov.id, :parse_full)
else
ov.parse
end
end
end
end