summaryrefslogtreecommitdiff
path: root/lib/environment.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/environment.rb')
-rw-r--r--lib/environment.rb95
1 files changed, 13 insertions, 82 deletions
diff --git a/lib/environment.rb b/lib/environment.rb
index 312eec4..46f8933 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -1,6 +1,6 @@
require 'logger'
# set default environment
-ENV['RACK_ENV'] = 'test' unless ENV['RACK_ENV']
+ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV']
# load/setup configuration
basedir = File.join(ENV['HOME'], ".opentox")
@@ -12,8 +12,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,91 +24,30 @@ else
end
# database
-if @@config[:database]
+if CONFIG[:database]
['dm-core', 'dm-serializer', 'dm-timestamps', 'dm-types', 'dm-migrations' ].each{|lib| require lib }
- case @@config[:database][:adapter]
+ 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]})
+ :adapter => CONFIG[:database][:adapter],
+ :database => CONFIG[:database][:database],
+ :username => CONFIG[:database][:username],
+ :password => CONFIG[:database][:password],
+ :host => CONFIG[:database][:host]})
end
end
# load mail settings for error messages
load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.rb")
-# hack: store sinatra in global var to make url_for and halt methods accessible
-before{ $sinatra = self unless $sinatra }
-
-class Sinatra::Base
- # overwriting halt to log halts (!= 202)
- def halt(*response)
- LOGGER.error "halt "+response.first.to_s+" "+(response.size>1 ? response[1].to_s : "") if response and response.first and response.first >= 300
- # orig sinatra code:
- response = response.first if response.length == 1
- throw :halt, response
- end
-end
-
-# logging
-class MyLogger < Logger
-
- def pwd
- path = Dir.pwd.to_s
- index = path.rindex(/\//)
- return path if index==nil
- path[(index+1)..-1]
- end
-
- def trace()
- lines = caller(0)
- n = 2
- line = lines[n]
-
- while (line =~ /spork.rb/ or line =~ /as_task/ or line =~ /environment.rb/)
- n += 1
- line = lines[n]
- end
-
- index = line.rindex(/\/.*\.rb/)
- return line if index==nil
- line[index..-1]
- end
-
- def format(msg)
- pwd.ljust(18)+" :: "+msg.to_s+" :: "+trace+" :: "+($sinatra ? $sinatra.request.env['REMOTE_ADDR'] : nil).to_s
- end
-
- def debug(msg)
- super format(msg)
- end
-
- def info(msg)
- super format(msg)
- end
-
- def warn(msg)
- super format(msg)
- end
-
- def error(msg)
- super format(msg)
- end
-
-end
-
-
logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log"
LOGGER = MyLogger.new(logfile,'daily') # daily 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
@@ -128,18 +67,10 @@ rescue
raise "Please edit #{user_file} and restart your application. Create at least one user with password."
end
-# RDF namespaces
-RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
-OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
-DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
-OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
-#OT = Redland::Namespace.new 'http://ortona.informatik.uni-freiburg.de/opentox.owl#'
-XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
-
# Regular expressions for parsing classification data
TRUE_REGEXP = /^(true|active|1|1.0)$/i
FALSE_REGEXP = /^(false|inactive|0|0.0)$/i
# Task durations
-DEFAULT_TASK_MAX_DURATION = @@config[:default_task_max_duration]
-EXTERNAL_TASK_MAX_DURATION = @@config[:external_task_max_duration]
+DEFAULT_TASK_MAX_DURATION = CONFIG[:default_task_max_duration]
+EXTERNAL_TASK_MAX_DURATION = CONFIG[:external_task_max_duration]