class Lolcommits::Lolsrv

Constants

SERVER

Public Class Methods

new(runner) click to toggle source
Calls superclass method Lolcommits::Plugin::new
# File lib/lolcommits/plugins/lolsrv.rb, line 12
def initialize(runner)
  super
  self.name    = 'lolsrv'
  self.default = false
  self.options << SERVER

end

Public Instance Methods

get_existing_lols() click to toggle source
# File lib/lolcommits/plugins/lolsrv.rb, line 49
def get_existing_lols
  begin
    lols = JSON.parse(
    RestClient.get(configuration[SERVER] + '/commits'))
    puts "lols #{lols}"

    lols["commits"].map { |lol| lol["sha"] }
  rescue => error
    @logger.info "Existing commits could not be retrieved with Error " + error.message
    @logger.info error.backtrace
    return nil
  end
end
run() click to toggle source
# File lib/lolcommits/plugins/lolsrv.rb, line 20
def run

  log_file = File.new(self.runner.config.loldir + "/lolsrv.log", "a+")
  @logger = Logger.new(log_file)

  if configuration[SERVER].nil?
    puts "Missing server configuration. Use lolcommits --config -p lolsrv"
    return
  end

  fork do
    sync()
  end
end
sync() click to toggle source
# File lib/lolcommits/plugins/lolsrv.rb, line 35
def sync
  existing = get_existing_lols
  unless existing.nil?
    Dir.glob(self.runner.config.loldir + "/*.jpg") do |item|
      next if item == '.' or item == '..'
      # do work on real items
      sha = File.basename(item, '.*')
      unless existing.include?(sha) || sha == 'tmp_snapshot'
        upload(item, sha)
      end
    end
  end
end
upload(file, sha) click to toggle source
# File lib/lolcommits/plugins/lolsrv.rb, line 63
def upload(file, sha)
  begin
    RestClient.post(
    configuration[SERVER] + '/upload',
    :lol => File.new(file),
    :sha => sha)
  rescue => error
    @logger.info "Upload of LOL "+ sha + " failed with Error " + error.message
    return
  end
end