git-contest 0.1.3 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmRhNmY5NTUwYzdlZDUzNGU3NzNhOWIzYjYwYWMzNjcxN2Y3MWY0NQ==
4
+ OGQzNWFlY2NkYTVhZjgzZTEwN2VjMWFjY2RiNjNkMTMyOGU5YWMzMQ==
5
5
  data.tar.gz: !binary |-
6
- MDg1N2I0N2QzMDIxNTcyNGQyZWRhNGMyZjU5ZGU4OGM3M2U2MDgwNg==
6
+ NTZlM2EyYjMyYmVlODYzMjc2OTczNTFiOTYzODBhMzQyMjhiNTA0Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWEzNzAwM2NkMjUzMTJkYzY4NDc0ZTM2MzQ5MGIyOTQ5OWEyZmNkOTRjMTVk
10
- NDUyOWMzMTE5ZmQ2ZWJmZmJjYmZkOTcyOGM1ZDY4ODBmNmMxZmJiYzMyOWNi
11
- NjY0ZmMzZGJkZDEzZWRiMDg3OTM3YWM4NGI1ZDIxYzdiNjNmYjc=
9
+ NGQwYjQyNzEzYjQxNTgwYzlhZjllMjBhMWY4ZTc2MTA0NjkxODIxOTE3NzVk
10
+ MjZlOTZkOWNjZDZhZTBlNGQwMTk4ZmQyNGNhMTAwMmRmMzg5YmEwNmYyZGI0
11
+ YWY1NDU2Nzg4YzBlNjcyMjc2ODI0MzIzYjhlMzBjYjMzZGQ1YWI=
12
12
  data.tar.gz: !binary |-
13
- ODc1MGY0NzVlYjQyY2Q2OTk0MzA0NWQ3MTZkNjY0NmM5YzRiOWQxNDc4NzQ0
14
- NzAwMDQ0NmRkYTI5OTRkYWYyMzQ5NzBjODI0ODdjNDE1NWRkMDg2ZGM1NTNh
15
- YWMzZWJlMmVhZmVhM2U1NWFlOTcwZWQwZmRlZTgyNzRlM2Y4ODQ=
13
+ YTM3YzFhNjdkMzE3N2MxZTQyMGFhZGQ3MDNhZTdiNTUwMWIwOGRmZmU4ZjBm
14
+ ZGRmOTM0NTE5ZmIyYTRlNTk1YTcxNTM5YWFiZDAxNWU0N2ZjNDU5MjE2YTk3
15
+ MDkxZTEzNjFhYzlmODc2NTU3YWE4NThhYzAyZTNhZDQ3YjRmMzM=
@@ -20,13 +20,15 @@ def usage
20
20
  puts " %-12s Start a new feature branch." % ["start"]
21
21
  puts " %-12s Finish a feature branch." % ["finish"]
22
22
  puts " %-12s Submit a solution." % ["submit"]
23
+ puts " %-12s Show information (sites, drivers)." % ["list"]
24
+ puts " %-12s Get/Set a config value." % ["config"]
23
25
  puts ""
24
26
  puts "Try 'git contest <subcommand> help' for details."
25
27
  end
26
28
 
27
29
  init
28
30
 
29
- sub_commands = %w(init start finish submit rebase)
31
+ sub_commands = %w(init start finish submit rebase list config)
30
32
  global_opts = Trollop::options do
31
33
  version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
32
34
  stop_on sub_commands
@@ -34,7 +36,7 @@ end
34
36
 
35
37
  cmd = ARGV.shift
36
38
  case cmd
37
- when "init", "start", "finish", "submit", "rebase"
39
+ when "init", "start", "finish", "submit", "rebase", "list", "config"
38
40
  load File.expand_path("../git-contest-#{cmd}", __FILE__)
39
41
  else
40
42
  usage
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # git-contest-config
5
+ # https://github.com/sh19910711/git-contest
6
+ #
7
+ # Copyright (c) 2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
+ # Licensed under the MIT-License.
9
+ #
10
+
11
+ $:.unshift File.expand_path('../../lib', __FILE__)
12
+ require 'git/contest/common'
13
+ require 'trollop'
14
+ require 'highline/import'
15
+ require 'active_support/core_ext/hash'
16
+
17
+
18
+ # Show Banner
19
+ def usage
20
+ puts get_banner
21
+ return 0
22
+ end
23
+
24
+ def show_get_usage
25
+ res = ""
26
+ res += "usage: git contest config get [key]\n"
27
+ res += "\n"
28
+ res += "Example Usage:\n"
29
+ res += " $ git contest config get key1\n"
30
+ res += " $ git contest config get namespace1.key1\n"
31
+ res += " $ git contest config get sites.some_judge.user\n"
32
+ res += " \n"
33
+ puts res
34
+ end
35
+
36
+ def show_set_usage
37
+ res = ""
38
+ res += "usage: git contest config set [key] <value>\n"
39
+ res += "\n"
40
+ res += "Example Usage:\n"
41
+ res += " $ git contest config set key1 value1\n"
42
+ res += " -> key1 = value1\n"
43
+ res += " $ git contest config set key1\n"
44
+ res += " -> set value from command-line\n"
45
+ res += " $ git contest config set namespace1.key1 value1\n"
46
+ res += " $ git contest config set sites.some_judge.user username\n"
47
+ res += " \n"
48
+ puts res
49
+ end
50
+
51
+ def show_site_usage
52
+ res = ""
53
+ res += "usage: git contest config site <type>\n"
54
+ res += "\n"
55
+ res += "Available types are:\n"
56
+ res += " %-8s: add site\n" % "add"
57
+ res += " \n"
58
+ puts res
59
+ end
60
+
61
+ def show_site_add_usage
62
+ res = ""
63
+ res += "usage: git contest config site add <site-name>\n"
64
+ res += "\n"
65
+ res += "Example Usage:\n"
66
+ res += " $ git contest config site add site1\n"
67
+ res += " -> input information\n"
68
+ res += " \n"
69
+ puts res
70
+ end
71
+
72
+ def show_site_rm_usage
73
+ res = ""
74
+ res += "usage: git contest config site rm <site-name>\n"
75
+ res += "\n"
76
+ res += "Example Usage:\n"
77
+ res += " $ git contest config site rm site1\n"
78
+ res += " \n"
79
+ puts res
80
+ end
81
+
82
+ # Get Banner Text
83
+ def get_banner
84
+ res = ""
85
+ res += "usage: git contest config [type]\n"
86
+ res += "\n"
87
+ res += "Available types are:\n"
88
+ res += " %-8s: set value\n" % "set"
89
+ res += " %-8s: get value\n" % "get"
90
+ res += " %-8s: set site info\n" % "site"
91
+ res += " \n"
92
+ return res
93
+ end
94
+
95
+ init
96
+
97
+ sub_commands = %w(sites)
98
+ $options = Trollop::options do
99
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
100
+ banner get_banner
101
+ stop_on sub_commands
102
+ end
103
+
104
+ type = ARGV.shift.to_s.strip
105
+
106
+ case type
107
+
108
+ when "site"
109
+ if ARGV.length >= 1
110
+ type = ARGV.shift.to_s.strip
111
+ case type
112
+ when "add"
113
+ # git-contest-config site add
114
+ if ARGV.length == 1
115
+ puts "# input site config (password will be hidden)"
116
+
117
+ # read info
118
+ site_name = ARGV.shift.to_s.strip
119
+ config = get_config
120
+
121
+ # init config
122
+ config["sites"][site_name] = {}
123
+
124
+ # input site info
125
+ # TODO: to check not found
126
+ config["sites"][site_name]["driver"] = ask("%10s > " % "driver").to_s
127
+ # TODO: to depend on above driver
128
+ config["sites"][site_name]["user"] = ask("%10s > " % "user id").to_s
129
+ config["sites"][site_name]["password"] = ask("%10s > " % "password") do |q|
130
+ q.echo = false
131
+ end.to_s
132
+
133
+ # set config
134
+ File.open($GIT_CONTEST_CONFIG, 'w') {|f| f.write config.to_yaml }
135
+
136
+ puts ""
137
+ puts "updated successfully!!"
138
+ puts ""
139
+ else
140
+ show_site_add_usage
141
+ end
142
+
143
+ when "rm"
144
+ # git-contest-config site rm
145
+ if ARGV.length == 1
146
+ # TODO: to check not found
147
+ site_name = ARGV.shift.to_s.strip
148
+
149
+ puts "Are you sure you want to remove `#{site_name}`?"
150
+ this_is_yes = ask("when you remove the site, type `yes` > ").to_s
151
+
152
+ if this_is_yes == "yes"
153
+ # update config
154
+ config = get_config
155
+ config["sites"].delete site_name
156
+ # save config
157
+ File.open($GIT_CONTEST_CONFIG, 'w') {|f| f.write config.to_yaml }
158
+ puts ""
159
+ puts "updated successfully!!"
160
+ puts ""
161
+ else
162
+ puts ""
163
+ puts "operation cancelled"
164
+ puts ""
165
+ end
166
+ else
167
+ show_site_rm_usage
168
+ end
169
+
170
+ else
171
+ show_site_usage
172
+ end
173
+ else
174
+ show_site_usage
175
+ end
176
+
177
+ when "get"
178
+ if ARGV.length == 1
179
+ # read key
180
+ config = get_config
181
+ cur = config
182
+ keys = ARGV.shift.to_s.strip.split('.')
183
+ while ! keys.empty?
184
+ key = keys.shift
185
+ if cur.has_key? key
186
+ cur = cur[key]
187
+ else
188
+ abort "ERROR: Not Found"
189
+ end
190
+ end
191
+ # output
192
+ if cur.is_a? Hash
193
+ puts "keys = #{cur.keys.join(', ')}"
194
+ else
195
+ puts cur
196
+ end
197
+ else
198
+ show_get_usage
199
+ end
200
+
201
+ when "set"
202
+ if ARGV.length == 1
203
+ # read values
204
+ keys = ARGV.shift.to_s.strip.split('.')
205
+ puts "input value"
206
+ value = gets.strip
207
+
208
+ # update yaml value
209
+ config = get_config
210
+ new_config = {}
211
+ cur = new_config
212
+ while ! keys.empty?
213
+ key = keys.shift
214
+ if keys.empty?
215
+ cur[key] = value
216
+ else
217
+ cur[key] = {}
218
+ cur = cur[key]
219
+ end
220
+ end
221
+ config.deep_merge! new_config
222
+
223
+ # save file
224
+ File.open($GIT_CONTEST_CONFIG, 'w') {|f| f.write config.to_yaml }
225
+ elsif ARGV.length == 2
226
+ # read values from command args
227
+ keys = ARGV.shift.to_s.strip.split('.')
228
+ value = ARGV.shift.to_s.strip
229
+
230
+ # update yaml value
231
+ config = get_config
232
+ new_config = {}
233
+ cur = new_config
234
+ while ! keys.empty?
235
+ key = keys.shift
236
+ if keys.empty?
237
+ cur[key] = value
238
+ else
239
+ cur[key] = {}
240
+ cur = cur[key]
241
+ end
242
+ end
243
+ config.deep_merge! new_config
244
+
245
+ # save file
246
+ File.open($GIT_CONTEST_CONFIG, 'w') {|f| f.write config.to_yaml }
247
+ else
248
+ show_set_usage
249
+ end
250
+
251
+ else
252
+ usage
253
+ end
254
+
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # git-contest-list
5
+ # https://github.com/sh19910711/git-contest
6
+ #
7
+ # Copyright (c) 2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
+ # Licensed under the MIT-License.
9
+ #
10
+
11
+ $:.unshift File.expand_path('../../lib', __FILE__)
12
+ require 'git/contest/common'
13
+ require 'trollop'
14
+
15
+ # Show Banner
16
+ def usage
17
+ puts get_banner
18
+ return 0
19
+ end
20
+
21
+ # Get Banner Text
22
+ def get_banner
23
+ res = ""
24
+ res += "usage: git contest list <type>\n"
25
+ res += "\n"
26
+ res += "Available types are:\n"
27
+ res += " %-8s: show sites\n" % "sites"
28
+ res += " %-8s: show drivers\n" % "drivers"
29
+ res += " \n"
30
+ return res
31
+ end
32
+
33
+ init
34
+ Contest::Driver::Utils.load_plugins
35
+
36
+ $config = get_config() || {}
37
+ $sites = {}
38
+ if $config.has_key? 'sites'
39
+ $sites = $config["sites"]
40
+ end
41
+
42
+ sub_commands = %w(sites drivers)
43
+ $options = Trollop::options do
44
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
45
+ banner get_banner
46
+ stop_on sub_commands
47
+ end
48
+
49
+ type = ARGV.shift.to_s.strip
50
+
51
+ case type
52
+ when "drivers"
53
+ # show all drivers
54
+ puts "#"
55
+ puts "# Available Drivers"
56
+ puts "#"
57
+ puts ""
58
+ drivers = Contest::Driver::Utils.get_all_drivers
59
+ drivers.each {|driver_info|
60
+ puts " #{driver_info[:class_name]}"
61
+ puts " #{driver_info[:site_info][:desc]}"
62
+ puts ""
63
+ }
64
+ when "sites"
65
+ # show all sites
66
+ $sites.keys.each do |site_name|
67
+ puts "# #{site_name}"
68
+ keys = ["driver", "user"]
69
+ keys.each {|key| puts " %-8s: %s" % [ key, $sites[site_name][key] ] }
70
+ puts " \n"
71
+ end
72
+ else
73
+ usage
74
+ end
75
+
@@ -12,16 +12,6 @@ $:.unshift File.expand_path('../../lib', __FILE__)
12
12
  require 'git/contest/common'
13
13
  require 'trollop'
14
14
 
15
- #
16
- # Load Plugins
17
- #
18
- def load_plugins
19
- # load drivers
20
- Dir.glob("#{$GIT_CONTEST_HOME}/plugins/**") do |path|
21
- require path if /\/driver_.*\.rb$/.match path
22
- end
23
- end
24
-
25
15
  #
26
16
  # Load Drivers
27
17
  #
@@ -31,7 +21,7 @@ def load_drivers
31
21
  class_name = driver_name.clone
32
22
  class_name.gsub!(/^[a-z]/) {|c| c.upcase }
33
23
  class_name.gsub!(/(_)([a-z])/) {|c, b| $2.upcase }
34
- $drivers[driver_name] = Contest::Driver.const_get "#{class_name}"
24
+ $drivers[driver_name] = Contest::Driver.const_get "#{class_name}Driver"
35
25
  end
36
26
  end
37
27
 
@@ -75,7 +65,7 @@ if $config.has_key? 'sites'
75
65
  $sites = $config["sites"]
76
66
  end
77
67
 
78
- load_plugins
68
+ Contest::Driver::Utils.load_plugins
79
69
 
80
70
  $drivers = {}
81
71
  load_drivers
@@ -192,6 +182,7 @@ driver.on(
192
182
 
193
183
  # global config
194
184
  $config["submit_rules"] ||= {}
185
+ $config["file"] ||= {}
195
186
 
196
187
  # set config
197
188
  driver.config = $sites[site]
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "nokogiri"
25
25
  spec.add_dependency "trollop"
26
26
  spec.add_dependency "highline"
27
+ spec.add_dependency "active_support"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.3"
29
30
  spec.add_development_dependency "rake"
@@ -6,13 +6,13 @@
6
6
  #
7
7
 
8
8
  # http://judge.u-aizu.ac.jp/onlinejudge/
9
- require 'contest/driver/aizu_online_judge'
9
+ require 'contest/driver/aizu_online_judge_driver'
10
10
 
11
11
  # http://codeforces.com/
12
- require 'contest/driver/codeforces'
12
+ require 'contest/driver/codeforces_driver'
13
13
 
14
14
  # http://uva.onlinejudge.org/
15
- require 'contest/driver/uva_online_judge'
15
+ require 'contest/driver/uva_online_judge_driver'
16
16
 
17
17
  # https://open.kattis.com/
18
- require 'contest/driver/kattis'
18
+ require 'contest/driver/kattis_driver'
@@ -10,7 +10,7 @@ require 'rexml/document'
10
10
 
11
11
  module Contest
12
12
  module Driver
13
- class AizuOnlineJudge < DriverBase
13
+ class AizuOnlineJudgeDriver < DriverBase
14
14
  def initialize_ext
15
15
  @client = Mechanize.new {|agent|
16
16
  agent.user_agent_alias = 'Windows IE 7'
@@ -22,6 +22,7 @@ module Contest
22
22
  @options ||= {}
23
23
  # site config
24
24
  @config ||= {}
25
+ @config["file"] ||= {}
25
26
  @config["submit_rules"] ||= {}
26
27
  # call DriverEvent#initialize
27
28
  super
@@ -123,7 +124,11 @@ module Contest
123
124
  @options[:source] = Utils.resolve_path(
124
125
  @options[:source] || @config["submit_rules"]["source"] || DEFAULT_SOURCE_PATH
125
126
  )
126
- @options[:language] ||= Utils.resolve_language(@options[:source])
127
+ if Utils.check_file_map(@options[:source], @config["file"]["ext"])
128
+ @options[:language] ||= Utils.resolve_file_map(@options[:source], @config["file"]["ext"])
129
+ else
130
+ @options[:language] ||= Utils.resolve_language(@options[:source])
131
+ end
127
132
  @options[:language] = resolve_language Utils.normalize_language(@options[:language])
128
133
 
129
134
  submit_ext()
@@ -9,7 +9,7 @@ require 'contest/driver/common'
9
9
 
10
10
  module Contest
11
11
  module Driver
12
- class Codeforces < DriverBase
12
+ class CodeforcesDriver < DriverBase
13
13
  def initialize_ext
14
14
  @client = Mechanize.new {|agent|
15
15
  agent.user_agent_alias = 'Windows IE 7'
@@ -13,6 +13,33 @@ require 'contest/driver/base'
13
13
  module Contest
14
14
  module Driver
15
15
  module Utils
16
+ # find all driver
17
+ def self.get_all_drivers
18
+ return [] unless defined? Contest::Driver
19
+ Contest::Driver.constants.select {|class_name|
20
+ /.*Driver$/ =~ class_name.to_s
21
+ }.map {|driver_class_name|
22
+ driver = Contest::Driver.const_get(driver_class_name).new
23
+ {
24
+ :class_name => driver_class_name,
25
+ :site_info => {
26
+ :name => driver.get_site_name(),
27
+ :desc => driver.get_desc(),
28
+ },
29
+ }
30
+ }
31
+ end
32
+
33
+ #
34
+ # Load Plugins
35
+ #
36
+ def self.load_plugins
37
+ # load drivers
38
+ Dir.glob("#{$GIT_CONTEST_HOME}/plugins/**") do |path|
39
+ require path if /\/.*_driver\.rb$/.match path
40
+ end
41
+ end
42
+
16
43
  def self.resolve_wild_card path
17
44
  `ls #{path} | cat | head -n 1`.strip
18
45
  end
@@ -41,6 +68,24 @@ module Contest
41
68
  end
42
69
  end
43
70
 
71
+ def self.get_file_ext filename
72
+ File.extname(filename)[1..-1]
73
+ end
74
+
75
+ def self.check_file_map label, ext_map
76
+ if ext_map.is_a? Hash
77
+ ext = get_file_ext(label)
78
+ ext_map.has_key?(ext)
79
+ else
80
+ false
81
+ end
82
+ end
83
+
84
+ def self.resolve_file_map label, ext_map
85
+ ext = get_file_ext(label)
86
+ ext_map[ext]
87
+ end
88
+
44
89
  def self.normalize_language label
45
90
  case label
46
91
  when "c", "C"
@@ -18,7 +18,7 @@ require 'contest/driver/common'
18
18
 
19
19
  module Contest
20
20
  module Driver
21
- class Kattis < DriverBase
21
+ class KattisDriver < DriverBase
22
22
  def initialize_ext
23
23
  @client = Mechanize.new {|agent|
24
24
  agent.user_agent_alias = 'Windows IE 7'
@@ -9,7 +9,7 @@ require 'contest/driver/common'
9
9
 
10
10
  module Contest
11
11
  module Driver
12
- class UvaOnlineJudge < DriverBase
12
+ class UvaOnlineJudgeDriver < DriverBase
13
13
  def initialize_ext
14
14
  @client = Mechanize.new {|agent|
15
15
  agent.user_agent_alias = 'Windows IE 7'
@@ -7,6 +7,6 @@
7
7
 
8
8
  module Git
9
9
  module Contest
10
- VERSION = "0.1.3"
10
+ VERSION = "0.2.0"
11
11
  end
12
12
  end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe "T012: git-contest-list" do
4
+ before do
5
+ ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/config.yml"
6
+ ENV['GIT_CONTEST_HOME'] = @temp_dir
7
+ end
8
+
9
+ context "git-contest-list sites" do
10
+ before do
11
+ # create config
12
+ File.open "#{@temp_dir}/config.yml", 'w' do |file|
13
+ file.write <<EOF
14
+ sites:
15
+ test_site1:
16
+ driver: test_driver1
17
+ user: test_user1
18
+ password: test_password1
19
+ test_site2:
20
+ driver: test_driver2
21
+ user: test_user2
22
+ password: test_password2
23
+ test_site3:
24
+ driver: test_driver3
25
+ user: test_user3
26
+ password: test_password3
27
+ EOF
28
+ end
29
+ end
30
+
31
+ it "should include site name" do
32
+ ret = bin_exec "list sites"
33
+ (1..3).each {|x| expect(ret).to include "test_site#{x}" }
34
+ end
35
+
36
+ it "should include user name" do
37
+ ret = bin_exec "list sites"
38
+ (1..3).each {|x| expect(ret).to include "test_user#{x}" }
39
+ end
40
+
41
+ it "should include driver name" do
42
+ ret = bin_exec "list sites"
43
+ (1..3).each {|x| expect(ret).to include "test_driver#{x}" }
44
+ end
45
+
46
+ it "should NOT include password" do
47
+ ret = bin_exec "list sites"
48
+ (1..3).each {|x| expect(ret).not_to include "test_password#{x}" }
49
+ end
50
+ end
51
+
52
+ context "git-contest-list drivers" do
53
+ before do
54
+ # prepare drivers
55
+ FileUtils.mkdir "#{@temp_dir}/plugins"
56
+ File.open "#{@temp_dir}/plugins/test01_driver.rb", "w" do |f|
57
+ f.write <<EOF
58
+ module Contest
59
+ module Driver
60
+ class Test01Driver < DriverBase
61
+ def get_site_name
62
+ "test01_site_name"
63
+ end
64
+ def get_desc
65
+ "test01_desc"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ EOF
71
+ end
72
+ File.open "#{@temp_dir}/plugins/test02_driver.rb", "w" do |f|
73
+ f.write <<EOF
74
+ module Contest
75
+ module Driver
76
+ class Test02Driver < DriverBase
77
+ def get_site_name
78
+ "test02_site_name"
79
+ end
80
+ def get_desc
81
+ "test02_desc"
82
+ end
83
+ end
84
+ end
85
+ end
86
+ EOF
87
+ end
88
+ end
89
+
90
+ it "contains plugins" do
91
+ ret = bin_exec "list drivers"
92
+ expect(ret).to include "Test01Driver"
93
+ expect(ret).to include "test01_desc"
94
+ expect(ret).to include "Test02Driver"
95
+ expect(ret).to include "test02_desc"
96
+ end
97
+ end
98
+
99
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe "T013: git-contest-config" do
5
+ before do
6
+ ENV['GIT_CONTEST_CONFIG'] = "#{@temp_dir}/config.yml"
7
+ end
8
+
9
+ context "git contest config set" do
10
+ before(:each) do
11
+ # create config file
12
+ File.open "#{@temp_dir}/config.yml", 'w' do |file|
13
+ file.write <<EOF
14
+ key1: value1
15
+ sites:
16
+ test_site1:
17
+ driver: test_driver1
18
+ user: test_user1
19
+ password: test_password1
20
+ EOF
21
+ end
22
+ end
23
+
24
+ it "git contest config set key value" do
25
+ bin_exec "config set key1 value2"
26
+ ret2 = YAML.load_file "#{@temp_dir}/config.yml"
27
+ expect(ret2["key1"]).to eq "value2"
28
+ end
29
+
30
+ it "git contest config set key (input from pipe)" do
31
+ bin_exec "config set key1", "value2"
32
+ ret2 = YAML.load_file "#{@temp_dir}/config.yml"
33
+ expect(ret2["key1"]).to eq "value2"
34
+ end
35
+
36
+ it "git contest config set sites.test_site1.driver test_driver2" do
37
+ bin_exec "config set sites.test_site1.driver test_driver2"
38
+ ret1 = YAML.load_file "#{@temp_dir}/config.yml"
39
+ expect(ret1["sites"]["test_site1"]["driver"]).to eq "test_driver2"
40
+ end
41
+ end
42
+
43
+ context "git contest config get" do
44
+ before(:each) do
45
+ # create config file
46
+ File.open "#{@temp_dir}/config.yml", 'w' do |file|
47
+ file.write <<EOF
48
+ key1: value1
49
+ sites:
50
+ test_site1:
51
+ driver: test_driver1
52
+ user: test_user1
53
+ password: test_password1
54
+ EOF
55
+ end
56
+ end
57
+
58
+ it "git contest config get key1" do
59
+ ret = bin_exec "config get key1"
60
+ expect(ret.strip).to eq "value1"
61
+ end
62
+
63
+ it "git contest config get sites.test_site1.user" do
64
+ ret = bin_exec "config get sites.test_site1.user"
65
+ expect(ret.strip).to eq "test_user1"
66
+ end
67
+
68
+ it "return keys" do
69
+ ret = bin_exec "config get sites.test_site1"
70
+ expect(ret).to include "driver"
71
+ expect(ret).to include "user"
72
+ expect(ret).to include "password"
73
+ expect(ret).not_to include "test_driver1"
74
+ expect(ret).not_to include "test_user1"
75
+ expect(ret).not_to include "test_password1"
76
+ end
77
+
78
+ it "raise error: not found" do
79
+ ret = bin_exec("config get foo.bar")
80
+ expect(ret).to include "ERROR"
81
+ end
82
+ end
83
+
84
+ context "git contest config site add" do
85
+ before(:each) do
86
+ # create config
87
+ File.open "#{@temp_dir}/config.yml", "w" do |file|
88
+ file.write <<EOF
89
+ sites:
90
+ test_site1:
91
+ driver: test_driver1
92
+ user: test_user1
93
+ password: test_password1
94
+ EOF
95
+ end
96
+ end
97
+
98
+ it "add site" do
99
+ bin_exec "config site add test_site2", "test_driver2\ntest_user2\ntest_password2"
100
+ ret1 = YAML.load_file "#{@temp_dir}/config.yml"
101
+ expect(ret1["sites"]["test_site1"]["driver"]).to eq "test_driver1"
102
+ expect(ret1["sites"]["test_site1"]["user"]).to eq "test_user1"
103
+ expect(ret1["sites"]["test_site1"]["password"]).to eq "test_password1"
104
+ expect(ret1["sites"]["test_site2"]["driver"]).to eq "test_driver2"
105
+ expect(ret1["sites"]["test_site2"]["user"]).to eq "test_user2"
106
+ expect(ret1["sites"]["test_site2"]["password"]).to eq "test_password2"
107
+ end
108
+ end
109
+
110
+ context "git contest config site rm" do
111
+ before(:each) do
112
+ # create config
113
+ File.open "#{@temp_dir}/config.yml", "w" do |file|
114
+ file.write <<EOF
115
+ sites:
116
+ test_site1:
117
+ driver: test_driver1
118
+ user: test_user1
119
+ password: test_password1
120
+ test_site2:
121
+ driver: test_driver2
122
+ user: test_user2
123
+ password: test_password2
124
+ EOF
125
+ end
126
+ end
127
+
128
+ it "remove site: input yes" do
129
+ bin_exec "config site rm test_site1", "yes"
130
+ ret1 = YAML.load_file "#{@temp_dir}/config.yml"
131
+ expect(ret1["sites"]["test_site1"]).to be_nil
132
+ expect(ret1["sites"]["test_site2"]["driver"]).to eq "test_driver2"
133
+ expect(ret1["sites"]["test_site2"]["user"]).to eq "test_user2"
134
+ expect(ret1["sites"]["test_site2"]["password"]).to eq "test_password2"
135
+ end
136
+
137
+ it "remove site: input no" do
138
+ bin_exec "config site rm test_site1", "no"
139
+ ret1 = YAML.load_file "#{@temp_dir}/config.yml"
140
+ expect(ret1["sites"]["test_site1"]["driver"]).to eq "test_driver1"
141
+ expect(ret1["sites"]["test_site1"]["user"]).to eq "test_user1"
142
+ expect(ret1["sites"]["test_site1"]["password"]).to eq "test_password1"
143
+ expect(ret1["sites"]["test_site2"]["driver"]).to eq "test_driver2"
144
+ expect(ret1["sites"]["test_site2"]["user"]).to eq "test_user2"
145
+ expect(ret1["sites"]["test_site2"]["password"]).to eq "test_password2"
146
+ end
147
+ end
148
+
149
+ end
@@ -1,11 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'contest/driver/aizu_online_judge'
4
-
5
3
  describe "T001: AizuOnlineJudge Driver" do
6
4
  before do
7
5
  # setup driver
8
- @driver = Contest::Driver::AizuOnlineJudge.new
6
+ @driver = Contest::Driver::AizuOnlineJudgeDriver.new
9
7
  @driver.stub(:sleep).and_return(0)
10
8
  ENV['GIT_CONTEST_CONFIG'] = get_path('/mock/t001/config.yml')
11
9
  init
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'contest/driver/codeforces'
4
-
5
3
  describe "T002: Codeforces Driver" do
6
4
  before(:each) do
7
- @driver = Contest::Driver::Codeforces.new
5
+ @driver = Contest::Driver::CodeforcesDriver.new
8
6
  @driver.stub(:sleep).and_return(0)
9
7
  end
10
8
 
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'contest/driver/codeforces'
4
-
5
3
  describe "T003: UvaOnlineJudge Driver" do
6
4
  before(:each) do
7
- @driver = Contest::Driver::UvaOnlineJudge.new
5
+ @driver = Contest::Driver::UvaOnlineJudgeDriver.new
8
6
  @driver.stub(:sleep).and_return(0)
9
7
  end
10
8
 
@@ -1,9 +1,8 @@
1
1
  require "spec_helper"
2
- require "contest/driver/kattis"
3
2
 
4
3
  describe "T010: Kattis Driver" do
5
4
  before do
6
- @driver = Contest::Driver::Kattis.new
5
+ @driver = Contest::Driver::KattisDriver.new
7
6
  @driver.stub(:sleep).and_return(0)
8
7
  end
9
8
 
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+ require "contest/driver/common"
3
+
4
+ describe "T011: Common" do
5
+ before do
6
+ ENV['GIT_CONTEST_HOME'] = @temp_dir
7
+ init
8
+ end
9
+
10
+ context "A001: Utils" do
11
+ context "check_file_map" do
12
+ it "test.cpp -> cpp11: normal" do
13
+ ret = Contest::Driver::Utils.check_file_map "test.cpp", {
14
+ "cpp" => "cpp11"
15
+ }
16
+ expect(ret).to eq true
17
+ end
18
+ it "test.cpp -> cpp11: no map" do
19
+ ret = Contest::Driver::Utils.check_file_map "test.cpp", {
20
+ }
21
+ expect(ret).to eq false
22
+ end
23
+ it "test.cpp -> cpp11: map is nil" do
24
+ ret = Contest::Driver::Utils.check_file_map "test.cpp", nil
25
+ expect(ret).to eq false
26
+ end
27
+ it "test.cpp: no map" do
28
+ ret = Contest::Driver::Utils.check_file_map "test.cpp", {
29
+ "py" => "python2"
30
+ }
31
+ expect(ret).to eq false
32
+ end
33
+ it "test.py: python2" do
34
+ ret = Contest::Driver::Utils.check_file_map "test.py", {
35
+ "py" => "python2"
36
+ }
37
+ expect(ret).to eq true
38
+ end
39
+ end
40
+
41
+ context "resolve_file_map" do
42
+ it "cpp -> cpp11" do
43
+ ret = Contest::Driver::Utils.resolve_file_map "test.cpp", {
44
+ "cpp" => "cpp11"
45
+ }
46
+ expect(ret).to eq "cpp11"
47
+ end
48
+ end
49
+
50
+ context "get_all_drivers" do
51
+ before(:each) do
52
+ FileUtils.mkdir "#{@temp_dir}/plugins"
53
+ File.open "#{@temp_dir}/plugins/test01_driver.rb", "w" do |f|
54
+ f.write <<EOF
55
+ module Contest
56
+ module Driver
57
+ class Test01Driver < DriverBase
58
+ def get_site_name
59
+ "test01_site_name"
60
+ end
61
+ def get_desc
62
+ "test01_desc"
63
+ end
64
+ end
65
+ end
66
+ end
67
+ EOF
68
+ end
69
+ File.open "#{@temp_dir}/plugins/test02_driver.rb", "w" do |f|
70
+ f.write <<EOF
71
+ module Contest
72
+ module Driver
73
+ class Test02Driver < DriverBase
74
+ def get_site_name
75
+ "test02_site_name"
76
+ end
77
+ def get_desc
78
+ "test02_desc"
79
+ end
80
+ end
81
+ end
82
+ end
83
+ EOF
84
+ end
85
+ end
86
+
87
+ it "contains plugins" do
88
+ Contest::Driver::Utils.load_plugins
89
+ ret1 = Contest::Driver::Utils.get_all_drivers.map {|driver| driver[:class_name] }
90
+ expect(ret1).to include :Test01Driver
91
+ expect(ret1).to include :Test02Driver
92
+ end
93
+ end
94
+ end
95
+ end
96
+
@@ -3,7 +3,7 @@ require 'rexml/document'
3
3
 
4
4
  module Contest
5
5
  module Driver
6
- class Dummy < DriverBase
6
+ class DummyDriver < DriverBase
7
7
  def get_opts_ext
8
8
  define_options do
9
9
  opt(
@@ -1,6 +1,8 @@
1
1
  require 'webmock'
2
+
2
3
  $:.unshift File.expand_path('../../lib', __FILE__)
3
4
  require 'git/contest/common'
5
+ require 'contest/driver'
4
6
 
5
7
  module SpecHelpers
6
8
  def read_file path
@@ -31,9 +33,11 @@ module SpecHelpers
31
33
  ENV['GIT_CONTEST_DEBUG'] = 'ON'
32
34
  end
33
35
 
34
- def bin_exec(args)
36
+ def bin_exec(args, input=nil)
35
37
  puts "Commmand: #{bin_path('git-contest')} #{args}" if ENV['GIT_CONTEST_DEBUG'] == 'ON'
36
- ret = `#{bin_path('git-contest')} #{args} 2>&1`
38
+ pipe_cmd = ""
39
+ pipe_cmd = "printf \" #{input}\" | " unless input.nil?
40
+ ret = `#{pipe_cmd}#{bin_path('git-contest')} #{args} 2>&1`
37
41
  ret
38
42
  end
39
43
 
@@ -203,5 +203,67 @@ EOF
203
203
  end
204
204
  end
205
205
  end
206
+
207
+ context "A002: file" do
208
+ context "B001: ext" do
209
+ before do
210
+ File.open "test1.dummy", "w" do |f|
211
+ f.write "wa-code"
212
+ end
213
+ File.open "test2.cpp", "w" do |f|
214
+ f.write "wa-code"
215
+ end
216
+ end
217
+
218
+ it "dummy -> c++11" do
219
+ set_git_contest_config <<EOF
220
+ file:
221
+ ext:
222
+ dummy: c++11
223
+ sites:
224
+ test_dummy:
225
+ driver: dummy
226
+ user: dummy
227
+ password: dummy
228
+ EOF
229
+
230
+ ret1 = bin_exec "submit test_dummy -c 100 -p A -s test1.dummy"
231
+ expect(ret1).not_to include "unknown language"
232
+ end
233
+
234
+ it "cpp -> dummy" do
235
+ set_git_contest_config <<EOF
236
+ file:
237
+ ext:
238
+ cpp: dummy
239
+ sites:
240
+ test_dummy:
241
+ driver: dummy
242
+ user: dummy
243
+ password: dummy
244
+ EOF
245
+
246
+ ret1 = bin_exec "submit test_dummy -c 100 -p A -s test2.cpp"
247
+ expect(ret1).to include "unknown language"
248
+ end
249
+
250
+ it "cpp -> cpp11" do
251
+ set_git_contest_config <<EOF
252
+ file:
253
+ ext:
254
+ cpp: dummy
255
+ sites:
256
+ test_dummy:
257
+ driver: dummy
258
+ user: dummy
259
+ password: dummy
260
+ EOF
261
+
262
+ ret1 = bin_exec "submit test_dummy -c 100 -p A -s test2.cpp"
263
+ expect(ret1).to include "unknown language"
264
+ end
265
+ end
266
+ end
267
+
206
268
  end
207
269
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-contest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: active_support
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -141,8 +155,10 @@ email:
141
155
  - sh19910711@gmail.com
142
156
  executables:
143
157
  - git-contest
158
+ - git-contest-config
144
159
  - git-contest-finish
145
160
  - git-contest-init
161
+ - git-contest-list
146
162
  - git-contest-rebase
147
163
  - git-contest-start
148
164
  - git-contest-submit
@@ -157,20 +173,22 @@ files:
157
173
  - README.md
158
174
  - Rakefile
159
175
  - bin/git-contest
176
+ - bin/git-contest-config
160
177
  - bin/git-contest-finish
161
178
  - bin/git-contest-init
179
+ - bin/git-contest-list
162
180
  - bin/git-contest-rebase
163
181
  - bin/git-contest-start
164
182
  - bin/git-contest-submit
165
183
  - git-contest.gemspec
166
184
  - lib/contest/driver.rb
167
- - lib/contest/driver/aizu_online_judge.rb
185
+ - lib/contest/driver/aizu_online_judge_driver.rb
168
186
  - lib/contest/driver/base.rb
169
- - lib/contest/driver/codeforces.rb
187
+ - lib/contest/driver/codeforces_driver.rb
170
188
  - lib/contest/driver/common.rb
171
189
  - lib/contest/driver/driver_event.rb
172
- - lib/contest/driver/kattis.rb
173
- - lib/contest/driver/uva_online_judge.rb
190
+ - lib/contest/driver/kattis_driver.rb
191
+ - lib/contest/driver/uva_online_judge_driver.rb
174
192
  - lib/git/contest.rb
175
193
  - lib/git/contest/common.rb
176
194
  - lib/git/contest/git.rb
@@ -181,12 +199,15 @@ files:
181
199
  - spec/bin/t007_git_contest_start_spec.rb
182
200
  - spec/bin/t008_git_contest_finish_spec.rb
183
201
  - spec/bin/t009_git_contest_init_spec.rb
202
+ - spec/bin/t012_git_contest_list_spec.rb
203
+ - spec/bin/t013_git_contest_config_spec.rb
184
204
  - spec/lib/contest/driver/t001_aizu_online_judge_spec.rb
185
205
  - spec/lib/contest/driver/t002_codeforces_spec.rb
186
206
  - spec/lib/contest/driver/t003_uva_online_judge_spec.rb
187
207
  - spec/lib/contest/driver/t010_kattis_spec.rb
208
+ - spec/lib/contest/driver/t011_utils_spec.rb
188
209
  - spec/mock/default_config/config.yml
189
- - spec/mock/default_config/plugins/driver_dummy.rb
210
+ - spec/mock/default_config/plugins/dummy_driver.rb
190
211
  - spec/mock/t001/002.status_log.xml
191
212
  - spec/mock/t001/config.yml
192
213
  - spec/mock/t001/description.html
@@ -243,12 +264,15 @@ test_files:
243
264
  - spec/bin/t007_git_contest_start_spec.rb
244
265
  - spec/bin/t008_git_contest_finish_spec.rb
245
266
  - spec/bin/t009_git_contest_init_spec.rb
267
+ - spec/bin/t012_git_contest_list_spec.rb
268
+ - spec/bin/t013_git_contest_config_spec.rb
246
269
  - spec/lib/contest/driver/t001_aizu_online_judge_spec.rb
247
270
  - spec/lib/contest/driver/t002_codeforces_spec.rb
248
271
  - spec/lib/contest/driver/t003_uva_online_judge_spec.rb
249
272
  - spec/lib/contest/driver/t010_kattis_spec.rb
273
+ - spec/lib/contest/driver/t011_utils_spec.rb
250
274
  - spec/mock/default_config/config.yml
251
- - spec/mock/default_config/plugins/driver_dummy.rb
275
+ - spec/mock/default_config/plugins/dummy_driver.rb
252
276
  - spec/mock/t001/002.status_log.xml
253
277
  - spec/mock/t001/config.yml
254
278
  - spec/mock/t001/description.html