atcoder_greedy 0.3.1 → 0.4.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 +4 -4
- data/README.md +49 -19
- data/atcoder_greedy.gemspec +2 -2
- data/{bin → exe}/atcoder_greedy +0 -0
- data/lib/atcoder_greedy.rb +30 -23
- data/lib/atcoder_greedy/command.rb +1 -0
- data/lib/atcoder_greedy/command/config.rb +2 -2
- data/lib/atcoder_greedy/command/create.rb +21 -3
- data/lib/atcoder_greedy/command/template.rb +26 -0
- data/lib/atcoder_greedy/lib/contest.rb +88 -40
- data/lib/atcoder_greedy/lib/greedy_template.rb +93 -0
- data/lib/atcoder_greedy/lib/test_case.rb +1 -0
- data/lib/atcoder_greedy/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c615d8f8d5392732a0823c7ca87250e7f85fb7eb
|
4
|
+
data.tar.gz: 0977f4aa39c014bd11a8b7621bcc72b5c183dc23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0550d84633c1740b05e459c324caec19fc15897d42066979360af402e2cf084a3f0b4d796a12cf1cc2ec98b1bccf1d51dd2c682e12fb4dbb5e31fb90d8af93b
|
7
|
+
data.tar.gz: 6a92836715a6a1633ce91aea0d99589667e4574035ea7458f9f36ce244692f878bb839b58991b38667c4a1c5cc472a3e803063d1d438f10fa7fd51fef634bece
|
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# AtcoderGreedy
|
2
|
-
楽にatcoderを使いたい.
|
3
|
-
|
2
|
+
楽にatcoderを使いたい. Atcoderで行われるコンテストにおいて, 自動でテンプレートやインプットを生成するGemです.
|
3
|
+
何かありましたらtwitter: @brook_bachまでお願いします.
|
4
|
+
|
5
|
+
## 実装した機能
|
6
|
+
- コンテストフォルダ, 問題ファイルの生成
|
7
|
+
- サンプルインプット、アウトプットを用いたテストファイルの生成, テスト実行
|
8
|
+
- ユーザーテンプレート機能
|
9
|
+
- ruby, c/c++ に対応
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -11,7 +17,7 @@
|
|
11
17
|
configコマンドを使用してデフォルト言語の設定をしてください。
|
12
18
|
```
|
13
19
|
$ atcoder_greedy config
|
14
|
-
Choose default language from: ["rb", "cpp"]
|
20
|
+
Choose default language from: ["rb", "cpp", "c"]
|
15
21
|
Input languages: cpp
|
16
22
|
Update Your default language to [cpp].
|
17
23
|
$
|
@@ -19,22 +25,50 @@ $
|
|
19
25
|
|
20
26
|
## Usage
|
21
27
|
|
22
|
-
###
|
28
|
+
### Createコマンド
|
29
|
+
コンテスト用のフォルダ, ファイルを作成します.
|
23
30
|
```
|
24
|
-
$ atcoder_greedy create
|
31
|
+
$ atcoder_greedy create CONTEST_URL OPTION
|
25
32
|
```
|
26
|
-
|
27
|
-
|
33
|
+
作成時に使用できるオプション
|
34
|
+
|
35
|
+
| option name ARGUMENT | alias | detail |
|
36
|
+
| ------------------------------------ | ----- | ------- |
|
37
|
+
| --no-templates | --nt | テンプレートファイルを生成しません. |
|
38
|
+
| --no-input | --ni | 入力ファイルを生成しません. |
|
39
|
+
| --select-problem PROBLEM_NAMES | -p | 指定した問題のみ生成します. 複数の問題を指定する場合は'A B' のように''で囲ってください. |
|
40
|
+
| --select-directory DIR_PATH | -d | 指定したディレクトリに生成します. |
|
41
|
+
| --select-language LANGUAGE | -l | 指定した言語でテンプレートを生成します. |
|
42
|
+
| --select-template TEMP_NAME | -t | 指定したテンプレートで生成します. |
|
43
|
+
|
44
|
+
### testコマンド
|
45
|
+
テストを実行します. 入力ファイルが生成されている必要があります.
|
28
46
|
```
|
29
47
|
$ cd CONTESTNAME
|
30
48
|
$ atcoder_greedy test PROBLEM_FILE_NAME
|
31
49
|
```
|
32
50
|
|
51
|
+
### templateコマンド
|
52
|
+
テンプレートの設定を行います. テンプレートは複数保存でき, 言語毎に一つデフォルトテンプレートを設定することができます.
|
53
|
+
デフォルトに設定されたテンプレートは, createコマンドで作成するときに使用されます.
|
54
|
+
```
|
55
|
+
$ atcoder_greedy template OPTION
|
56
|
+
```
|
57
|
+
使用できるオプション
|
58
|
+
|
59
|
+
| option name | alias | detail |
|
60
|
+
| ------------------------| ----- | ------- |
|
61
|
+
| --add FILE_PATH | -a | FILE_PATHで指定されたファイルをテンプレートに追加します. |
|
62
|
+
| --list | -l | テンプレート一覧を表示します. |
|
63
|
+
| --set-default FILE_NAME | -s | FILE_NAMEで指定されたテンプレートをその言語のデフォルトに設定します. |
|
64
|
+
| --delete FILE_NAME | -d | FILE_NAMEで指定されたテンプレートを削除します. |
|
65
|
+
|
33
66
|
## 使用例
|
34
|
-
|
67
|
+
### 例1
|
68
|
+
ARC014の場合
|
35
69
|
|
36
70
|
```
|
37
|
-
$ atcoder_greedy create
|
71
|
+
$ atcoder_greedy create http://arc014.contest.atcoder.jp
|
38
72
|
```
|
39
73
|
|
40
74
|
とすると、以下のようなファイルが生成される。
|
@@ -82,21 +116,19 @@ Correct Answer:
|
|
82
116
|
Test done.
|
83
117
|
```
|
84
118
|
|
85
|
-
|
86
|
-
|
87
|
-
- サンプルインプット、アウトプットを用いたテストファイルの生成
|
88
|
-
- テスト実行コマンド
|
89
|
-
- ruby, c++ に対応
|
119
|
+
### 例2
|
120
|
+
ARC015にて, カレントディレクトリにA問題のインプットファイルのみ生成したい場合
|
90
121
|
|
122
|
+
```
|
123
|
+
$ atcoder_greedy create http://arc015.contest.atcoder.jp --nt -p A -d ./
|
124
|
+
```
|
91
125
|
|
92
126
|
## TODO,実装したい機能
|
93
|
-
|
94
|
-
- ユーザーテンプレート機能
|
127
|
+
|
95
128
|
- 提出機能
|
96
129
|
- 言語対応の拡大
|
97
130
|
- gemのテスト作成
|
98
131
|
|
99
|
-
|
100
132
|
## Development
|
101
133
|
|
102
134
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -106,8 +138,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
106
138
|
## Contributing
|
107
139
|
|
108
140
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/atcoder_greedy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
109
|
-
|
110
|
-
|
111
141
|
## License
|
112
142
|
|
113
143
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/atcoder_greedy.gemspec
CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "
|
27
|
-
spec.executables = spec.files.grep(%r{^
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.11"
|
data/{bin → exe}/atcoder_greedy
RENAMED
File without changes
|
data/lib/atcoder_greedy.rb
CHANGED
@@ -2,7 +2,6 @@ require 'open-uri'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'yaml'
|
5
|
-
require 'psych'
|
6
5
|
|
7
6
|
require "atcoder_greedy/version"
|
8
7
|
require 'atcoder_greedy/command'
|
@@ -12,50 +11,58 @@ module AtcoderGreedy
|
|
12
11
|
@config = {
|
13
12
|
user_id: '',
|
14
13
|
password: '',
|
15
|
-
language: '
|
14
|
+
language: '',
|
15
|
+
default_template: {
|
16
|
+
rb: '',
|
17
|
+
cpp: '',
|
18
|
+
c: '',
|
19
|
+
py: ''
|
20
|
+
}
|
16
21
|
}
|
17
22
|
|
23
|
+
@valid_languages = %w(rb cpp c py)
|
18
24
|
@valid_config_keys = @config.keys
|
19
25
|
|
20
26
|
# Configure through hash
|
21
27
|
def self.configure(opts = {})
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
rescue Psych::SyntaxError
|
32
|
-
puts "YAML configuration file contains invalid syntax. Using defaults."; return
|
28
|
+
self.config
|
29
|
+
opts.each do |k, v|
|
30
|
+
if v.is_a?(Hash)
|
31
|
+
v.each do |ck, cv|
|
32
|
+
@config[k.to_sym][ck.to_sym] = cv if @valid_languages.include?(ck.to_s)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
@config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
|
36
|
+
end
|
33
37
|
end
|
34
|
-
|
35
|
-
configure(config)
|
38
|
+
self.save_config
|
36
39
|
end
|
37
40
|
|
38
41
|
def self.get_config_path
|
39
42
|
config_path = Dir.home + '/.atcoder_greedy'
|
40
43
|
if Dir.exists?(config_path)
|
41
|
-
# use user settings
|
42
44
|
config_path
|
43
45
|
else
|
44
|
-
|
45
|
-
File.join(File.dirname(__dir__), '/lib/atcoder_greedy')
|
46
|
+
raise "Can't find config directory. please init by command: 'atcoder_greedy config'.'"
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
50
|
def self.config
|
50
51
|
yml_path = get_config_path + '/settings.yml'
|
51
|
-
|
52
|
-
|
52
|
+
yml_file = YAML.load_file(yml_path)
|
53
|
+
if yml_file
|
54
|
+
@config = yml_file
|
55
|
+
else
|
56
|
+
File.open(yml_path, 'w') { |f| YAML.dump(@config, f) }
|
57
|
+
end
|
53
58
|
end
|
54
59
|
|
55
60
|
def self.save_config
|
56
61
|
yml_path = get_config_path + '/settings.yml'
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
if File.exists?(yml_path)
|
63
|
+
File.open(yml_path, 'w') { |f| YAML.dump(@config, f) }
|
64
|
+
else
|
65
|
+
raise "Can't find #{yml_path}. please set configure."
|
66
|
+
end
|
60
67
|
end
|
61
68
|
end
|
@@ -12,7 +12,8 @@ module AtcoderGreedy
|
|
12
12
|
puts "Your current language is [#{AtcoderGreedy.config[:language]}]."
|
13
13
|
else
|
14
14
|
Dir.mkdir(config_path)
|
15
|
-
|
15
|
+
yml_path = AtcoderGreedy.get_config_path + '/settings.yml'
|
16
|
+
File.open(yml_path, 'w').close
|
16
17
|
end
|
17
18
|
puts "Choose default language from: #{languages}"
|
18
19
|
print "Input languages: "
|
@@ -27,7 +28,6 @@ module AtcoderGreedy
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
AtcoderGreedy.save_config
|
31
31
|
puts "Update Your default language to [#{AtcoderGreedy.config[:language]}]."
|
32
32
|
end
|
33
33
|
end
|
@@ -4,10 +4,28 @@ require 'atcoder_greedy/lib/contest'
|
|
4
4
|
|
5
5
|
module AtcoderGreedy
|
6
6
|
class Command < Thor
|
7
|
-
desc 'create [
|
7
|
+
desc 'create [CONTESTURL] [OPTION]', 'create contest templates for [CONTESTURL]'
|
8
|
+
option :no_templates, type: :boolean, default: false, aliases: "\--nt"
|
9
|
+
option :no_input, type: :boolean, default: false, aliases: "\--ni"
|
10
|
+
option :select_problem, aliases: '-p', default: nil, desc: 'create only select problem'
|
11
|
+
option :select_directory, aliases: '-d', default: '', desc: 'select target directory'
|
12
|
+
option :select_language, aliases: '-l', default: '', desc: 'select language'
|
13
|
+
option :select_template, aliases: '-t', default: '', desc: 'select generate template'
|
8
14
|
|
9
|
-
def create(
|
10
|
-
|
15
|
+
def create(contest_url)
|
16
|
+
user_options = {
|
17
|
+
without: {input: false, template: false},
|
18
|
+
problems: [],
|
19
|
+
directory: options[:select_directory],
|
20
|
+
language: options[:select_language],
|
21
|
+
template: options[:select_template]
|
22
|
+
}
|
23
|
+
|
24
|
+
user_options[:without][:input] = true if options[:no_input]
|
25
|
+
user_options[:without][:template] = true if options[:no_templates]
|
26
|
+
user_options[:problems] = options[:select_problem].split unless options[:select_problem].nil?
|
27
|
+
|
28
|
+
Contest.new(contest_url, user_options)
|
11
29
|
end
|
12
30
|
end
|
13
31
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'atcoder_greedy'
|
2
|
+
require 'atcoder_greedy/command'
|
3
|
+
require 'atcoder_greedy/lib/greedy_template'
|
4
|
+
|
5
|
+
module AtcoderGreedy
|
6
|
+
class Command < Thor
|
7
|
+
desc 'template [OPTION]', 'set template'
|
8
|
+
option :add, aliases: '-a'
|
9
|
+
option :list, aliases: '-l'
|
10
|
+
option :set_default, aliases: '-s'
|
11
|
+
option :delete, aliases: '-d'
|
12
|
+
def template
|
13
|
+
temp = GreedyTemplate.new
|
14
|
+
if options[:add]
|
15
|
+
temp.add(options[:add])
|
16
|
+
elsif options[:list]
|
17
|
+
temp.list
|
18
|
+
elsif options[:set_default]
|
19
|
+
temp.set_default(options[:set_default])
|
20
|
+
elsif options[:delete]
|
21
|
+
temp.delete(options[:delete])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -1,52 +1,66 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'atcoder_greedy'
|
3
|
+
require 'atcoder_greedy/lib/greedy_template'
|
4
|
+
|
1
5
|
class Contest
|
2
6
|
attr_accessor :name, :url
|
3
7
|
|
4
|
-
def initialize(
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
create_templates
|
17
|
-
puts 'Set up done.'
|
18
|
-
end
|
8
|
+
def initialize(url, **options)
|
9
|
+
if options[:language] != ''
|
10
|
+
@language = options[:language]
|
11
|
+
else
|
12
|
+
@language = AtcoderGreedy.config[:language]
|
13
|
+
end
|
14
|
+
@url = url
|
15
|
+
set_contest_info(options[:problems])
|
16
|
+
set_directories(options[:directory])
|
17
|
+
|
18
|
+
create_inputs unless options[:without][:input]
|
19
|
+
create_templates(options[:template]) unless options[:without][:template]
|
19
20
|
|
20
|
-
|
21
|
-
'http://' + contest_name + '.contest.atcoder.jp'
|
21
|
+
puts 'Set up done. Go for it!'
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def set_contest_info(option_problems)
|
25
|
+
print 'Set contest info ... '
|
26
|
+
@name = URI.parse(@url).host.split('.').first
|
27
|
+
charset = nil
|
28
|
+
html = open(@url + '/assignments') do |f|
|
29
|
+
charset = f.charset
|
30
|
+
f.read
|
31
31
|
end
|
32
|
+
doc = Nokogiri::HTML.parse(html, nil, charset)
|
32
33
|
|
33
|
-
|
34
|
-
|
34
|
+
all_problems = nil
|
35
|
+
doc.xpath('//tbody').each do |tbody|
|
36
|
+
all_problems = tbody.xpath('.//a[@class="linkwrapper"]')
|
35
37
|
end
|
36
|
-
|
38
|
+
|
39
|
+
@problems = []
|
40
|
+
until all_problems.empty?
|
41
|
+
path = all_problems[0].attributes['href'].value
|
42
|
+
pro = all_problems.select { |l| l.attributes['href'].value == path }
|
43
|
+
all_problems = all_problems.reject { |l| l.attributes['href'].value == path }
|
44
|
+
name = pro[0].inner_text
|
45
|
+
if option_problems.empty? || (!option_problems.empty? && option_problems.include?(name))
|
46
|
+
@problems.push(name: pro[0].inner_text, path: path)
|
47
|
+
print "#{name} "
|
48
|
+
end
|
49
|
+
end
|
50
|
+
puts 'Done!'
|
37
51
|
end
|
38
52
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
# url
|
53
|
+
def create_inputs
|
54
|
+
print 'Create inputs ... '
|
55
|
+
@problems.each do |problem|
|
56
|
+
# take input and output params from url and save to file
|
43
57
|
charset = nil
|
44
|
-
html = open(url[:path]) do |f|
|
58
|
+
html = open(@url + problem[:path]) do |f|
|
45
59
|
charset = f.charset
|
46
60
|
f.read
|
47
61
|
end
|
48
62
|
doc = Nokogiri::HTML.parse(html, nil, charset)
|
49
|
-
in_file = File.new(
|
63
|
+
in_file = File.new(@dir + "/input_#{problem[:name]}.txt", 'w')
|
50
64
|
|
51
65
|
params = doc.xpath('//pre')
|
52
66
|
params.shift
|
@@ -61,19 +75,53 @@ class Contest
|
|
61
75
|
end
|
62
76
|
|
63
77
|
in_file.close
|
78
|
+
end
|
79
|
+
puts 'Done!'
|
80
|
+
end
|
64
81
|
|
65
|
-
|
82
|
+
def create_templates(option_template)
|
83
|
+
print 'Create Templates ... '
|
84
|
+
if option_template == ''
|
85
|
+
# use user default or system default template
|
86
|
+
if AtcoderGreedy.config[:default_template][:"#{@language}"] != ''
|
87
|
+
solve_template = open(AtcoderGreedy.config[:default_template][:"#{@language}"], &:read)
|
88
|
+
else
|
89
|
+
solve_template = open(File.dirname(__dir__) + '/templates' + "/#{@language}/solve.#{@language}", &:read)
|
90
|
+
end
|
91
|
+
else
|
92
|
+
# use option_template
|
93
|
+
template_path = GreedyTemplate.get_template_path(option_template)
|
94
|
+
if template_path.nil?
|
95
|
+
raise "ERROR: Template #{option_template} doesn't found"
|
96
|
+
else
|
97
|
+
solve_template = open(template_path, &:read)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
@problems.each_with_index do |problem|
|
102
|
+
solve_file_content = solve_template.clone
|
66
103
|
solve_file_content.gsub!(/DATE/, Time.now.strftime('%F'))
|
67
104
|
solve_file_content.gsub!(/CONTEST/, @name.upcase)
|
68
|
-
solve_file_content.gsub!(/PROBLEM/,
|
69
|
-
solve_file = File.new(
|
105
|
+
solve_file_content.gsub!(/PROBLEM/, problem[:name])
|
106
|
+
solve_file = File.new(@dir + "/#{problem[:name]}.#{@language}", 'w')
|
70
107
|
solve_file.print solve_file_content
|
71
108
|
solve_file.close
|
72
109
|
end
|
110
|
+
puts 'Done!'
|
73
111
|
end
|
74
112
|
|
75
|
-
def
|
76
|
-
|
77
|
-
|
113
|
+
def set_directories(directory)
|
114
|
+
print 'Set contest directory ... '
|
115
|
+
if directory == ''
|
116
|
+
FileUtils.mkdir(@name)
|
117
|
+
@dir = "./#{@name}"
|
118
|
+
else
|
119
|
+
if Dir.exists?(directory)
|
120
|
+
@dir = directory
|
121
|
+
else
|
122
|
+
raise "ERROR: Directory doesn't exists:#{@dir}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
puts 'Done!'
|
78
126
|
end
|
79
|
-
end
|
127
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# require 'FileUtils'
|
2
|
+
require 'atcoder_greedy'
|
3
|
+
|
4
|
+
class GreedyTemplate
|
5
|
+
def initialize
|
6
|
+
@dir = AtcoderGreedy::get_config_path + '/templates'
|
7
|
+
Dir.mkdir(@dir) unless Dir.exists?(@dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(file_path)
|
11
|
+
# save template to language directory
|
12
|
+
file = File.open(file_path)
|
13
|
+
file_name = File.basename(file_path)
|
14
|
+
type_dir = @dir + '/' + File.extname(file_path).delete('.')
|
15
|
+
Dir.mkdir(type_dir) unless Dir.exists?(type_dir)
|
16
|
+
if File.exists?(type_dir + '/' + file_name)
|
17
|
+
print "Template [#{file_name}] is already exists. Do you update?[y/N]:"
|
18
|
+
s = $stdin.gets.chomp
|
19
|
+
if s == 'y' || s == 'yes'
|
20
|
+
FileUtils.cp(file, type_dir)
|
21
|
+
puts 'Template file is updated.'
|
22
|
+
puts "if you want to use this file as a default, please run 'atcoder_greedy template -s #{file_name}'"
|
23
|
+
end
|
24
|
+
else
|
25
|
+
FileUtils.cp(file, type_dir)
|
26
|
+
puts 'Template file is added.'
|
27
|
+
puts "if you want to use this file as a default, please run 'atcoder_greedy template -s #{file_name}'"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def list
|
32
|
+
puts "Show Template file lists. [d] is this language default. ---------------------"
|
33
|
+
Dir::glob(@dir + '/*').each do |l|
|
34
|
+
puts "#{File.basename(l)}:"
|
35
|
+
Dir::glob("#{l}/*").each do |f|
|
36
|
+
default = get_default(File.basename(l))
|
37
|
+
if default != nil && File.basename(f) == default
|
38
|
+
print ' [d] '
|
39
|
+
else
|
40
|
+
print ' - '
|
41
|
+
end
|
42
|
+
puts "#{File.basename(f)}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_default(file_name)
|
48
|
+
type = File.extname(file_name).delete('.')
|
49
|
+
type_dir = @dir + '/' + type
|
50
|
+
file = type_dir + '/' + File.basename(file_name)
|
51
|
+
if File.exists?(file)
|
52
|
+
AtcoderGreedy.configure(default_template: {"#{type}": file})
|
53
|
+
puts 'Set new default template.'
|
54
|
+
else
|
55
|
+
puts "File [#{file_name}] doesn't exists. confirm input name."
|
56
|
+
self.list
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def delete(file_name)
|
61
|
+
type = File.extname(file_name).delete('.')
|
62
|
+
type_dir = @dir + '/' + type
|
63
|
+
file = type_dir + '/' + File.basename(file_name)
|
64
|
+
if File.exists?(file)
|
65
|
+
print "Do you delete [#{file_name}]?[y/N]:"
|
66
|
+
s = $stdin.gets.chomp
|
67
|
+
if s == 'y' || s == 'yes'
|
68
|
+
if File.basename(file_name) == get_default(type)
|
69
|
+
AtcoderGreedy.configure(default_template: {"#{type}": ''})
|
70
|
+
end
|
71
|
+
FileUtils.remove_file(file)
|
72
|
+
puts 'Template file is deleted.'
|
73
|
+
end
|
74
|
+
else
|
75
|
+
puts "File [#{file_name}] doesn't exists. confirm input name."
|
76
|
+
self.list
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.get_template_path(file_name)
|
81
|
+
type = File.extname(file_name).delete('.')
|
82
|
+
type_dir = AtcoderGreedy::get_config_path + '/templates' + '/' + type
|
83
|
+
file = type_dir + '/' + File.basename(file_name)
|
84
|
+
File.exists?(file) ? file : nil
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def get_default(language)
|
89
|
+
unless AtcoderGreedy.config[:default_template][:"#{language}"].nil?
|
90
|
+
File.basename(AtcoderGreedy.config[:default_template][:"#{language}"])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atcoder_greedy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- keigo-brook
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,8 +85,6 @@ email:
|
|
85
85
|
- goog@brookbach.com
|
86
86
|
executables:
|
87
87
|
- atcoder_greedy
|
88
|
-
- console
|
89
|
-
- setup
|
90
88
|
extensions: []
|
91
89
|
extra_rdoc_files: []
|
92
90
|
files:
|
@@ -98,16 +96,18 @@ files:
|
|
98
96
|
- README.md
|
99
97
|
- Rakefile
|
100
98
|
- atcoder_greedy.gemspec
|
101
|
-
- bin/atcoder_greedy
|
102
99
|
- bin/console
|
103
100
|
- bin/setup
|
101
|
+
- exe/atcoder_greedy
|
104
102
|
- lib/atcoder_greedy.rb
|
105
103
|
- lib/atcoder_greedy/command.rb
|
106
104
|
- lib/atcoder_greedy/command/config.rb
|
107
105
|
- lib/atcoder_greedy/command/create.rb
|
108
106
|
- lib/atcoder_greedy/command/destroy.rb
|
107
|
+
- lib/atcoder_greedy/command/template.rb
|
109
108
|
- lib/atcoder_greedy/command/test.rb
|
110
109
|
- lib/atcoder_greedy/lib/contest.rb
|
110
|
+
- lib/atcoder_greedy/lib/greedy_template.rb
|
111
111
|
- lib/atcoder_greedy/lib/languages.rb
|
112
112
|
- lib/atcoder_greedy/lib/test_case.rb
|
113
113
|
- lib/atcoder_greedy/settings.yml
|