Class: Contestify::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/contestify/uploader.rb

Overview

Contestify::Uploader is a simple class that will habdle the uploading part to the server.

Class Method Summary collapse

Class Method Details

.upload!(server_url, admin_pwd, problems_path) ⇒ Object

Contestify::Uploader.upload! is *the only* method you should call to upload the problems to the server. It will receive 3 params.

Parameters

server_url<String>

The upload URL in the server. E.g your-dom-judge.com/jury/problem.php

admin_pwd<String>

This is the ‘admin` password needed to authenticate in the server

problems_path<Array>

An array having all the paths where the problems input/output are. This should be the return array from a Contestify::Configuration call. The paths here must be absolute paths.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/contestify/uploader.rb', line 17

def self.upload!(server_url, admin_pwd, problems_path)
  puts green "\n\n=> Uploading problems to the server"
  
  for dir in problems_path do
    Dir.chdir dir

    unless File.exists?("domjudge-problem.ini")
      puts cyan "domjudge-problem.ini not found. Skipping #{dir}."
      next
    end

    puts blue "==> Building #{dir}"
    FileUtils.rm_f "bundle.zip"
    zip_output = system("zip bundle.zip *")
    raise Exception.new(red Contestify::ZIP_PROBLEM) unless $?.success?

    puts blue "===> Uploading #{dir}/bundle.zip..."
    curl_output = system("curl -vv -F upload=Upload -F [email protected] --user admin:#{admin_pwd} #{server_url}")
    puts blue "===> Upload done\n"
  end

  puts green "\n\n=> All problems have been uploaded"
end