From a368d3ad8015a905c0aee873c5c10c2fad4afbdb Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 17 Aug 2011 14:06:03 +0200 Subject: move data directory to folder data for A&A reasons --- application.rb | 10 ++++++---- data/.gitignore | 3 +++ lazar.rb | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 data/.gitignore diff --git a/application.rb b/application.rb index 7d3de38..96287c3 100644 --- a/application.rb +++ b/application.rb @@ -4,6 +4,8 @@ require 'opentox-ruby' set :lock, true +@@datadir = "data" + class PredictionCache < Ohm::Model attribute :compound_uri attribute :model_uri @@ -22,7 +24,7 @@ before do @id = @id.to_s.sub(/\//,'').to_i @uri = uri @id - @yaml_file = "public/#{@id}.yaml" + @yaml_file = "#{@@datadir}/#{@id}.yaml" raise OpenTox::NotFoundError.new "Model #{@id} not found." unless File.exists? @yaml_file end @@ -35,7 +37,7 @@ require 'lazar.rb' helpers do def next_id - id = Dir["./public/*yaml"].collect{|f| File.basename(f.sub(/.yaml/,'')).to_i}.sort.last + id = Dir["./#{@@datadir}/*yaml"].collect{|f| File.basename(f.sub(/.yaml/,'')).to_i}.sort.last id = 0 if id.nil? id + 1 end @@ -59,7 +61,7 @@ end get '/?' do # get index of models response['Content-Type'] = 'text/uri-list' - Dir["./public/*yaml"].collect{|f| File.basename(f.sub(/.yaml/,'')).to_i}.sort.collect{|n| uri n}.join("\n") + "\n" + Dir["./#{@@datadir}/*yaml"].collect{|f| File.basename(f.sub(/.yaml/,'')).to_i}.sort.collect{|n| uri n}.join("\n") + "\n" end delete '/:id/?' do @@ -84,7 +86,7 @@ end delete '/?' do # TODO delete datasets - FileUtils.rm Dir["public/*.yaml"] + FileUtils.rm Dir["#{@@datadir}/*.yaml"] PredictionCache.all.each {|cache| cache.delete } response['Content-Type'] = 'text/plain' "All models and cached predictions deleted." diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..59e3edd --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,3 @@ +*.rdfxml +*.xls +*.yaml diff --git a/lazar.rb b/lazar.rb index 08efcf8..89f3423 100644 --- a/lazar.rb +++ b/lazar.rb @@ -104,7 +104,7 @@ post '/?' do # create model raise OpenTox::BadRequestError.new "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/) @id = next_id @uri = uri @id - @yaml_file = "public/#{@id}.yaml" + @yaml_file = "#{@@datadir}/#{@id}.yaml" lazar = YAML.load request.env["rack.input"].read lazar.uri = @uri value_feature_uri = File.join( @uri, "predicted", "value") -- cgit v1.2.3