contestify 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -7,13 +7,19 @@ Usage
7
7
  ---
8
8
 
9
9
  ```
10
- contestify coci_problems_url judge_upload_url judge_password
10
+ contestify coci_problems_url judge_upload_url judge_password
11
11
  ```
12
12
 
13
13
  This will get the .zip file from the `coci_problems_url` and add the problems to the DOM Judge on the server. This **will not** create a new contest. Just add problems to the current one.
14
14
 
15
15
  It is assumed that the admin username is `admin`.
16
16
 
17
+ ### Example
18
+
19
+ ```
20
+ contestify http://hsin.hr/coci/contest1_testdata.zip http://juez.factorcomun.org/jury/problem.php p4ssw0rd
21
+ ```
22
+
17
23
  Contributions
18
24
  ---
19
25
 
@@ -1,10 +1,29 @@
1
1
  module Contestify
2
+ # <tt>Contestify::Configuration</tt> is in charge of renaming files and
3
+ # adding DOMJudge specific configuration files to each problem.
2
4
  class Configuration
3
5
 
6
+ # <tt>Contestify::Configuration.configure!</tt> is *the only* method you
7
+ # should call from the contest interface. All the other methods should be
8
+ # called from here. This is the only method needed for future strategies
9
+ # for other judges.
10
+ #
11
+ # This should be called in a directory structure such that you have a
12
+ # `base_folder` with one folder for each problem you want to upload to the
13
+ # server. Each of these problems folders should have all the input/output
14
+ # files you want to use as test cases.
15
+ #
16
+ # This method **must** return the absolute paths of the problem folders in
17
+ # an array. This return value will be used in Contestify::Uploader.upload!
18
+ #
19
+ # ==== Parameters
20
+ # base_folder<String>:: The base folder where all the problems folders are
21
+ # stored.
22
+ #
4
23
  def self.configure!(base_folder)
5
24
  puts green "=> Configuring problems"
6
25
  problem_index = 0
7
- Dir.glob("*").select { |f| File.directory?(f) }.each do |dir|
26
+ Dir.glob("*").select { |f| File.directory?(f) }.map do |dir|
8
27
  Dir.chdir File.join(base_folder, dir)
9
28
  dirid = Dir.pwd.split('/').last[0...8]
10
29
  puts green "==> #{dirid.upcase}"
@@ -12,9 +31,26 @@ module Contestify
12
31
  add_problem_config(dirid, problem_index)
13
32
  problem_index += 1
14
33
  puts green "==> All the work for #{dirid.upcase} is done"
34
+ Dir.pwd # Return the absolute path for this problem
15
35
  end
16
36
  end
17
37
 
38
+ # <tt>Contestify::Configuration.rename_data_files</tt> is in charge of
39
+ # giving each input/output file a standard name that DOMJudge understands.
40
+ #
41
+ # This method should be overriden in future strategies.
42
+ #
43
+ # After this method is called, every different input/output file **must**
44
+ # have the following structure:
45
+ #
46
+ # `problemid`.`number`.in
47
+ # `problemid`.`number`.out
48
+ #
49
+ # where:
50
+ #
51
+ # `problemid` is at most 8 letters long and it's the id for the judge and
52
+ # `number` is the test case number. The .in and .out will determine the
53
+ # input and compare file the judge will run/diff.
18
54
  def self.rename_data_files
19
55
  puts blue "===> Renaming input/output files"
20
56
  Dir.glob("*").select { |f| f =~ /\.in.[0-9]+/ }.each do |f|
@@ -33,6 +69,16 @@ module Contestify
33
69
  end
34
70
  end
35
71
 
72
+ # <tt>Contestify::Configuration.add_problem_config</tt> will add the
73
+ # configuration file needed for DOMJudge to understand the problem.
74
+ #
75
+ # ==== Parameters
76
+ # probid<String>:: The problem id for DOMJudge. This **must** be at most
77
+ # 8 letters long.
78
+ #
79
+ # problem_index<Integer>:: This is the problem number. This is only used
80
+ # to choose the problem ballon color.
81
+
36
82
  def self.add_problem_config(probid, problem_index)
37
83
  puts blue "===> Adding DOM Judge configuration #{probid}"
38
84
  file_content = <<-TEXT
@@ -17,8 +17,8 @@ module Contestify
17
17
  get_problems
18
18
  unzip_problems
19
19
  @base_dir = Dir.pwd
20
- Contestify::Configuration.configure!(@base_dir)
21
- Contestify::Uploader.upload!(@judge_url, @judge_password, @base_dir)
20
+ problems_path = Contestify::Configuration.configure!(@base_dir)
21
+ Contestify::Uploader.upload!(@judge_url, @judge_password, problems_path)
22
22
  clean_dir!
23
23
  end
24
24
 
@@ -1,11 +1,24 @@
1
1
  module Contestify
2
+ # <tt>Contestify::Uploader</tt> is a simple class that will habdle the
3
+ # uploading part to the server.
2
4
  class Uploader
3
- def self.upload!(server_url, admin_pwd, base_dir)
5
+ # <tt>Contestify::Uploader.upload!</tt> is *the only* method you should call
6
+ # to upload the problems to the server. It will receive 3 params.
7
+ #
8
+ # ==== Parameters
9
+ # server_url<String>:: The **upload** URL in the server. E.g http://your-dom-judge.com/jury/problem.php
10
+ #
11
+ # admin_pwd<String>:: This is the `admin` password needed to authenticate in the server
12
+ #
13
+ # problems_path<Array>:: An array having all the paths where the problems input/output are.
14
+ # This *should* be the return array from a <tt>Contestify::Configuration</tt> call.
15
+ # The paths here **must** be absolute paths.
16
+ #
17
+ def self.upload!(server_url, admin_pwd, problems_path)
4
18
  puts green "\n\n=> Uploading problems to the server"
5
-
6
- Dir.chdir base_dir # Ensure you're on the `root` dir
7
- Dir.glob("*").select { |f| File.directory?(f) }.each do |dir|
8
- Dir.chdir File.join(base_dir, dir)
19
+
20
+ for dir in problems_path do
21
+ Dir.chdir dir
9
22
 
10
23
  unless File.exists?("domjudge-problem.ini")
11
24
  puts cyan "domjudge-problem.ini not found. Skipping #{dir}."
@@ -21,6 +34,7 @@ module Contestify
21
34
  curl_output = system("curl -vv -F upload=Upload -F problem_archive=@bundle.zip --user admin:#{admin_pwd} #{server_url}")
22
35
  puts blue "===> Upload done\n"
23
36
  end
37
+
24
38
  puts green "\n\n=> All problems have been uploaded"
25
39
  end
26
40
  end
@@ -1,3 +1,3 @@
1
1
  module Contestify
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contestify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-05 00:00:00.000000000 Z
12
+ date: 2011-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70178592865120 !ruby/object:Gem::Requirement
16
+ requirement: &70289636072180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70178592865120
24
+ version_requirements: *70289636072180
25
25
  description: Gem to prepare internal programming contests taking problems from the
26
26
  COCI contests.
27
27
  email:
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  segments:
62
62
  - 0
63
- hash: -1661828008444752765
63
+ hash: 3991357628571573628
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  segments:
71
71
  - 0
72
- hash: -1661828008444752765
72
+ hash: 3991357628571573628
73
73
  requirements: []
74
74
  rubyforge_project:
75
75
  rubygems_version: 1.8.10