diff options
Diffstat (limited to 'lib/environment.rb')
-rw-r--r-- | lib/environment.rb | 84 |
1 files changed, 45 insertions, 39 deletions
diff --git a/lib/environment.rb b/lib/environment.rb index cfc875d..59578c1 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -1,4 +1,3 @@ -require "ot-logger" # set default environment ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV'] @@ -12,8 +11,8 @@ TMP_DIR = File.join(basedir, "tmp") LOG_DIR = File.join(basedir, "log") if File.exist?(config_file) - @@config = YAML.load_file(config_file) - raise "could not load config, config file: "+config_file.to_s unless @@config + CONFIG = YAML.load_file(config_file) + raise "could not load config, config file: "+config_file.to_s unless CONFIG else FileUtils.mkdir_p TMP_DIR FileUtils.mkdir_p LOG_DIR @@ -24,54 +23,61 @@ else end # database -if @@config[:database] - ['dm-core', 'dm-serializer', 'dm-timestamps', 'dm-types', 'dm-migrations', 'dm-validations' ].each{|lib| require lib } - case @@config[:database][:adapter] - when /sqlite/i - db_dir = File.join(basedir, "db") - FileUtils.mkdir_p db_dir - DataMapper::setup(:default, "sqlite3://#{db_dir}/opentox.sqlite3") - else - DataMapper.setup(:default, { - :adapter => @@config[:database][:adapter], - :database => @@config[:database][:database], - :username => @@config[:database][:username], - :password => @@config[:database][:password], - :host => @@config[:database][:host]}) - end -end +`redis-server /opt/redis/redis.conf` unless File.exists? "/var/run/redis.pid" +Ohm.connect :thread_safe => true # load mail settings for error messages load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.rb") logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log" -#LOGGER = MyLogger.new(logfile,'daily') # daily rotation -LOGGER = MyLogger.new(logfile) # no rotation +#LOGGER = OTLogger.new(logfile,'daily') # daily rotation +LOGGER = OTLogger.new(logfile) # no rotation LOGGER.formatter = Logger::Formatter.new #this is neccessary to restore the formating in case active-record is loaded -if @@config[:logger] and @@config[:logger] == "debug" +if CONFIG[:logger] and CONFIG[:logger] == "debug" LOGGER.level = Logger::DEBUG else LOGGER.level = Logger::WARN end -if File.exist?(user_file) - @@users = YAML.load_file(user_file) -else - FileUtils.cp(File.join(File.dirname(__FILE__), 'templates/users.yaml'), user_file) - puts "Please edit #{user_file} and restart your application." - exit -end +# Regular expressions for parsing classification data +TRUE_REGEXP = /^(true|active|1|1.0|tox)$/i +FALSE_REGEXP = /^(false|inactive|0|0.0|low tox)$/i + +# Task durations +DEFAULT_TASK_MAX_DURATION = 36000 +#EXTERNAL_TASK_MAX_DURATION = 36000 + +# OWL Namespaces +class OwlNamespace + + attr_accessor :uri + def initialize(uri) + @uri = uri + end + + def [](property) + @uri+property.to_s + end + + def type # for RDF.type + "#{@uri}type" + end + + def method_missing(property) + @uri+property.to_s + end -begin - 0 < @@users[:users].keys.length -rescue - raise "Please edit #{user_file} and restart your application. Create at least one user with password." end -# Regular expressions for parsing classification data -TRUE_REGEXP = /^(true|active|1|1.0)$/i -FALSE_REGEXP = /^(false|inactive|0|0.0)$/i +AA_SERVER = CONFIG[:authorization] ? (CONFIG[:authorization][:server] ? CONFIG[:authorization][:server] : nil) : nil +CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorization][:authenticate_request] +CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request] +CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] + +RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' +OWL = OwlNamespace.new 'http://www.w3.org/2002/07/owl#' +DC = OwlNamespace.new 'http://purl.org/dc/elements/1.1/' +OT = OwlNamespace.new 'http://www.opentox.org/api/1.1#' +OTA = OwlNamespace.new 'http://www.opentox.org/algorithmTypes.owl#' +XSD = OwlNamespace.new 'http://www.w3.org/2001/XMLSchema#' -# Task durations -DEFAULT_TASK_MAX_DURATION = 3600 -EXTERNAL_TASK_MAX_DURATION = 3600 |