Syntax highlighting

July 23, 2012, Arne

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

class AutomaticSeleniumExtractor < SeleniumExtractor
  def init list
    @list = list
  end
  
  def extract
    rd, wr = IO.pipe
    
    pid = fork do
      Process::Sys::setuid(ENV["SUDO_UID"].to_i)
      rd.close
      profile = "Selenium #{@@tor ? "Tor" : "Default"}"
      driver = Selenium::WebDriver.for :ff, :profile => profile
      
      Signal.trap("USR1") do
        @continue = true
      end
      
      IO.foreach(@list) do |line|
        website = line[0...-1]

        # Send label to parent process to indicate we are going to 
        # access another website and to pass it to the capture process 
        wr.puts website
        sleep(1) until @continue
        @continue = false
        driver.navigate.to "http://#{website}/"
        wr.puts "done"
      end
      
      wr.close
      driver.quit
    end
    
    wr.close
    
    until rd.eof?
      @label = rd.gets[0...-1]
      thread = capture_thread
      sleep(1) until thread[:capturing]
      Process.kill("USR1", pid)
      rd.gets # Wait for process to finish
      thread[:stop] = true
      thread.join 
    end
    
    rd.close
  end
end