Changeset 205

Show
Ignore:
Timestamp:
17-04-12 11:59:30 (2 years ago)
Author:
kostas.karasavvas@…
Message:

added single image support -- changed tmp dir to be below public_folder

Location:
t2-web/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • t2-web/trunk/bin/config.ru

    r203 r205  
    44set :timeout, 1800 
    55 
    6 run WebT2App 
     6run T2WebApp 
    77 
  • t2-web/trunk/bin/t2_webapp.rb

    r204 r205  
    1010require 'cgi' 
    1111require 'stringio' 
    12 #require "t2-web" TODO: move whole of WebT2App in lib 
    13  
    14 # TODO: add constants.rb file in lib for all constants (e.g. myExp user URL, other URLs 
    15  
    16 class WebT2App < Sinatra::Base 
     12#require "t2-web"  
     13 
     14# TODO: move whole of T2WebApp in lib 
     15# TODO: add constants.rb file in lib for all constants (e.g. myExp user URL,  
     16#       TMP_UPLOAD_PATH, other URLs -- consider adding those in rack config.ru 
     17 
     18class T2WebApp < Sinatra::Base 
    1719 
    1820  WEB_APP_NAME = "t2web" 
    19   # TODO: const for TMP_UPLOAD_PATH ? - need to read from config file? 
    2021 
    2122  set :views, File.dirname(__FILE__) + '/../views' 
    2223  set :public_folder, File.dirname(__FILE__) + '/../public' 
    2324 
    24   # can be used from routes and views (haml) 
     25  # Can be used from routes and views (haml) -- not public methods 
    2526  helpers do 
    2627 
     
    3233    end 
    3334 
    34     # 
    3535    # Deletes last new line of file if it exists! It is needed for t2 workflows that 
    3636    # do not sanitize properly, i.e. via a user-provided beanshell script 
    37     # 
    3837    def chomp_last_newline(file) 
    3938 
     
    4948    # Construct the complete or partial URL as MyExperimentRest lib expects it 
    5049    # TODO: Maybe update myExperimentREST lib to accept only wid and wkf_version 
    51     # Minor for now 
    5250    def get_url_from_wid(wid, wkf_version) 
    5351      if wkf_version == "default" 
     
    110108    end 
    111109 
    112     # TODO: remove 02/04/2012 
    113     # Generates tooltip html text for textarea example 
    114     #def generate_textarea_tooltip(input) 
    115     #  "Example: " << CGI::unescapeHTML(input.examples[0]) 
    116     #end 
    117  
    118110 
    119111    # Generates the contents of the data-navigation frame 
     
    138130 
    139131 
    140     # Takes list as input -- TODO: rdoc methods properly! 
     132    # Takes string list as input and prepares for HTML 
    141133    def generate_html_result(data) 
    142134      data.gsub(/[\n]/, '<br>') 
    143135    end 
    144136 
    145     def generate_image_result(data) 
    146       "<img src=\"#{data}\" />" 
    147     end 
    148  
    149  
    150  
    151     # Check type of data and generate appropriate html for that result! 
    152     # Takes list as input, returns as file stream -- TODO: rdoc methods properly! 
     137    # Takes image url and prepares for HTML 
     138    def generate_image_result(img) 
     139      "<img src=\"#{img}\" />" 
     140    end 
     141 
     142 
     143    # Takes list as input (or single element), returns as file stream  
     144    # TODO: for images it works when not a list! 
    153145    def flatten_list_results(list) 
    154146      data = "" 
     
    167159 
    168160 
    169     # copies output stream to a tmp file in the specified subdir 
    170     # TODO: make proper rdoc 
     161    # Copies output stream to a tmp file in the specified subdir 
    171162    def copy_to_tmp(subdir, filename, out) 
     163 
    172164      # used to copy them at tmp 
    173165      #FileUtils.mkdir_p("/tmp/#{WEB_APP_NAME}/#{subdir}") unless File.exist?("/tmp/#{WEB_APP_NAME}/#{subdir}") 
     
    196188 
    197189    # Get myExperiment workflow object 
    198     # TODO: catch exception -- make custom exceptions? 
     190    # TODO: catch exception 
    199191    @my_exp_wkf = MyExperimentREST::Workflow.from_id_and_version(@wid, @wkf_version) 
    200192 
    201193    # Get myExperiment user object 
    202     # TODO: catch exception -- make custom exceptions? 
     194    # TODO: catch exception 
    203195    @my_exp_usr = MyExperimentREST::User.from_uri(@my_exp_wkf.uploader_uri) 
    204196 
     
    223215    # Get myExperiment user object (TODO: session!, exceptions) 
    224216    @my_exp_usr = MyExperimentREST::User.from_uri(@my_exp_wkf.uploader_uri) 
    225  
    226217 
    227218    # use the uri reference to download the workflow locally 
     
    291282    # TODO: TMP folder constant from config! 
    292283    # TODO: that gets the whole output.. request client lib to support partial 
    293     # download! -- refs could then be used to download the full results! 
     284    #       download if result too large!  
    294285    run.get_output_ports.each do |t2_output| 
    295286      begin 
     
    302293      data_stream = flatten_list_results(data_lists) 
    303294 
    304       # copy results to tmp 
     295      # copy results to our app's tmp 
    305296      copy_to_tmp("outputs/#{@run_uuid}", t2_output, data_stream) 
    306297    end 
     
    312303 
    313304  # Get results for specified run and output (stored locally from tmp) 
    314   # display it in data-display div 
     305  # and display it in data-display div 
    315306  # Cross-domain AJAX to get result from T2 
    316307  get "/#{WEB_APP_NAME}/run/:uuid/output/:out" do 
    317308 
    318     # change public only for this route so that /tmp/t2web can be accessed!!! 
    319     # otherwise we would need to pollute our normal webserver public dir with all tmp outputs? 
    320     # TODO think if it's better to put all tmp files in webserver public dir !!! ... 
     309    # change public only for this route so that /tmp/t2web can be accessed 
     310    # unfortunately contrary to an article the following does not work 
    321311    #set :public_folder, "./tmp/#{WEB_APP_NAME}" 
    322312 
     
    326316    data = File.open("#{settings.public_folder}/#{WEB_APP_NAME}/tmp/outputs/#{run_uuid}/#{t2_output}", "r").read 
    327317 
    328     # add HTML tags to display properly 
    329  
    330     # check what kind of file it is... for now use system 'file' -- note that it will only 
    331     # work with one image.. since flatten_list_results only deals with multi-line strings! 
    332     # ..and single strings or single images (indirectly!) 
     318    # Add HTML tags to display properly 
     319 
     320    # Check what kind of file it is. for now use system 'file' -- note that it will only 
     321    # work with one image since flatten_list_results only deals with multi-line strings 
     322    # and single strings or single images (indirectly!) 
    333323    mime_type = %x( file --mime-type #{settings.public_folder}/#{WEB_APP_NAME}/tmp/outputs/#{run_uuid}/#{t2_output} ) 
    334324    if mime_type.include?("image/") 
    335       #content_type 'image/png' 
    336325      generate_image_result("/#{WEB_APP_NAME}/tmp/outputs/#{run_uuid}/#{t2_output}") 
    337       # not always image/png !! 
    338       #send_file("/tmp/#{WEB_APP_NAME}/outputs/#{run_uuid}/#{t2_output}", :type => 'image/png', :disposition => 'inline') 
    339326    else 
    340327      generate_html_result(data) 
     
    345332  # Used from input's upload-form to upload files without refresh (actually 
    346333  # a hidden iframe is refreshed). 
    347   # TODO: use copy_to_tmp method!! 
    348   # uploads still go to system's tmp and not to our webapp's public tmp 
     334  # TODO: use copy_to_tmp method!! Uploads still go to system's tmp and not  
     335  #       to our webapp's public tmp 
    349336  post "/#{WEB_APP_NAME}/upload" do 
    350337    filename = params[:file][:filename] 
     
    360347 
    361348 
    362 # Start Web App 
     349# Start Web App from the ./bin directory in deamon mode at port 9494 
    363350# $ thin -d -p 9494 
     351 
  • t2-web/trunk/CHANGES

    r204 r205  
    44* Workflow results are now stored in the public_folder 
    55* We now support image results (not list of images in one taverna output yet) 
    6  
    7 == Version 0.1.3 
    86* Added /t2web in route to check the workflow execution status in taverna (was /runs/...) 
    97 
  • t2-web/trunk/Rakefile

    r204 r205  
    2020  s.email = 'kostas.karasavvas@nbic.nl' 
    2121  #s.executables = ['t2_webapp.rb'] 
    22   s.files = %w(LICENSE README CHANGES Rakefile) + Dir.glob("{bin,lib,doc,spec,public,views}/**/*") 
     22  s.files = %w(LICENSE README CHANGES Rakefile Gemfile Gemfile.lock) + Dir.glob("{bin,lib,doc,spec,public,views}/**/*") 
    2323  s.require_path = "lib" 
    2424  s.bindir = "bin" 
  • t2-web/trunk/test/t2_web_test.rb

    r184 r205  
    1919 
    2020  def app 
    21     WebT2App.new 
     21    T2WebApp.new 
    2222  end 
    2323