summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-08-21 09:58:05 +0200
committerChristoph Helma <helma@in-silico.de>2009-08-21 09:58:05 +0200
commit2d935206eacec241a52713d1fe319cc78189d97d (patch)
tree78a375086f81fecbd13bca3c81fd1e757cf2ccb7 /lib
parentd45ceec09ae23bfb8a20af625f216069cefa1b9e (diff)
environment.rb and templates added
Diffstat (limited to 'lib')
-rw-r--r--lib/environment.rb44
-rw-r--r--lib/opentox-ruby-api-wrapper.rb22
-rw-r--r--lib/tasks/opentox.rb29
-rw-r--r--lib/templates/config.yaml13
4 files changed, 82 insertions, 26 deletions
diff --git a/lib/environment.rb b/lib/environment.rb
new file mode 100644
index 0000000..b22e8e5
--- /dev/null
+++ b/lib/environment.rb
@@ -0,0 +1,44 @@
+require 'yaml'
+config_file = File.join(ENV['HOME'], '.opentox/config.yaml')
+
+if File.exist?(config_file)
+ config = YAML.load_file(config_file)
+else
+ FileUtils.mkdir_p File.dirname(config_file)
+ FileUtils.cp(File.join(File.dirname(__FILE__), 'templates/config.yaml'), config_file)
+ puts "Please edit #{config_file} and restart your application."
+ exit
+end
+
+puts config
+
+@environment = "development" unless @environment = ENV['OPENTOX']
+@config = config[@environment]
+
+port = 5000
+@services = {}
+begin
+ `killall thin` if @environment == "development"
+rescue
+end
+config["services"].each do |service|
+ dir = File.join(@config["base_dir"], service)
+ case @environment
+ when "development|test"
+ @services[dir] = "http://localhost:#{port}/"
+ Dir.chdir dir
+ `thin --debug --rackup config.ru start -p #{port} -e #{@environment} &`
+ #pid = fork {`urxvt -title #{service} -e thin --debug --rackup config.ru start -p #{port} -e development`}
+ #Process.detach(pid)
+ port += 1
+ when "production"
+ @services[dir] = "http://#{@config['base_uri']}/#{service}/v#{major_version}/"
+ `touch #{File.join(dir,"tmp/restart.txt")}`
+ else
+ "Puts environment #{ENV['OPENTOX']} not supported."
+ end
+end
+
+def major_version
+ File.open(File.join(File.dirname(__FILE__), '../VERSION')).each_line.first.split(/\./)[0]
+end
diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb
index db46149..4ee6fd3 100644
--- a/lib/opentox-ruby-api-wrapper.rb
+++ b/lib/opentox-ruby-api-wrapper.rb
@@ -1,13 +1,7 @@
-['rubygems', 'rest_client', 'spork' ].each do |lib|
+['rubygems', 'rest_client', 'spork', 'environment'].each do |lib|
require lib
end
-ENV['OPENTOX_COMPOUND'] = 'http://webservices.in-silico.ch/compound/v0/' unless ENV['OPENTOX_COMPOUND']
-ENV['OPENTOX_FEATURE'] = 'http://webservices.in-silico.ch/feature/v0/' unless ENV['OPENTOX_FEATURE']
-ENV['OPENTOX_DATASET'] = 'http://webservices.in-silico.ch/dataset/v0/' unless ENV['OPENTOX_DATASET']
-ENV['OPENTOX_FMINER'] = 'http://webservices.in-silico.ch/fminer/v0/' unless ENV['OPENTOX_FMINER']
-ENV['OPENTOX_LAZAR'] = 'http://webservices.in-silico.ch/lazar/v0/' unless ENV['OPENTOX_LAZAR']
-
module OpenTox
class OpenTox
@@ -42,9 +36,9 @@ module OpenTox
if params[:uri]
@uri = params[:uri].to_s
elsif params[:smiles]
- @uri = RestClient.post ENV['OPENTOX_COMPOUND'] ,:smiles => uri_escape(params[:smiles])
+ @uri = RestClient.post @services['opentox-compound'] ,:smiles => uri_escape(params[:smiles])
elsif params[:name]
- @uri = RestClient.post ENV['OPENTOX_COMPOUND'] ,:name => uri_escape(params[:name])
+ @uri = RestClient.post @services['opentox-compound'] ,:name => uri_escape(params[:name])
end
end
@@ -76,7 +70,7 @@ module OpenTox
if params[:uri]
@uri = params[:uri].to_s
else
- @uri = ENV['OPENTOX_FEATURE'] + uri_escape(params[:name])
+ @uri = @services['opentox-feature']+ uri_escape(params[:name])
params[:values].each do |k,v|
@uri += '/' + k.to_s + '/' + v.to_s
end
@@ -97,9 +91,9 @@ module OpenTox
if params[:uri]
@uri = params[:uri].to_s
elsif params[:name] and params[:filename]
- @uri = `curl -X POST -F file=@#{params[:filename]} -F name="#{params[:name]}" #{ENV['OPENTOX_DATASET']}`
+ @uri = `curl -X POST -F file=@#{params[:filename]} -F name="#{params[:name]}" #{@services['opentox-dataset']}`
elsif params[:name]
- @uri = RestClient.post ENV['OPENTOX_DATASET'], :name => params[:name]
+ @uri = RestClient.post @services['opentox-dataset'], :name => params[:name]
end
end
@@ -139,7 +133,7 @@ module OpenTox
# Create a new dataset with BBRC features
def initialize(training_dataset)
- @dataset_uri = RestClient.post ENV['OPENTOX_FMINER'], :dataset_uri => training_dataset.uri
+ @dataset_uri = RestClient.post @services['opentox-fminer'], :dataset_uri => training_dataset.uri
end
def dataset
@@ -155,7 +149,7 @@ module OpenTox
if params[:uri]
@uri = params[:uri]
elsif params[:dataset_uri]
- @uri = RestClient.post ENV['OPENTOX_LAZAR'] + 'models' , :dataset_uri => params[:dataset_uri]
+ @uri = RestClient.post @services['opentox-lazar']+ 'models' , :dataset_uri => params[:dataset_uri]
end
end
diff --git a/lib/tasks/opentox.rb b/lib/tasks/opentox.rb
index c44ceb6..59fc16c 100644
--- a/lib/tasks/opentox.rb
+++ b/lib/tasks/opentox.rb
@@ -1,15 +1,20 @@
-desc "Install required gems"
-task :install do
- puts `sudo gem install #{@gems}`
-end
+require File.join(File.dirname(__FILE__), '../..', 'test/opentox-ruby-api-wrapper_test.rb')
-desc "Update gems"
-task :update do
- puts `sudo gem update #{@gems}`
-end
+namespace :opentox do
-desc "Run tests"
-task :test do
- load 'test.rb'
-end
+ desc "Install required gems"
+ task :install do
+ puts `sudo gem install #{@gems}`
+ end
+ desc "Update gems"
+ task :update do
+ puts `sudo gem update #{@gems}`
+ end
+
+ desc "Run tests"
+ task :test do
+ load 'test.rb'
+ end
+
+end
diff --git a/lib/templates/config.yaml b/lib/templates/config.yaml
new file mode 100644
index 0000000..bae9dc6
--- /dev/null
+++ b/lib/templates/config.yaml
@@ -0,0 +1,13 @@
+development:
+ base_dir: ~/webservices
+
+production:
+ base_uri: webservices.in-silico.ch
+ base_dir: /var/www/webservices
+
+services:
+ - opentox-feature
+ - opentox-compound
+ - opentox-dataset
+ - opentox-fminer
+ - opentox-lazar