vyatta-utils 0.0.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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vyatta-utils.gemspec
4
+ gemspec
5
+ gem "racc"
@@ -0,0 +1,43 @@
1
+ Vyatta utils
2
+ ============
3
+
4
+ 仮想ルータVyattaのユーティリティ
5
+
6
+ 現在ある機能
7
+ ----------
8
+
9
+ - コンフィグファイルをコマンドライン形式へのコンバート
10
+
11
+
12
+ インストール手順
13
+ ---------------
14
+
15
+ ### githubから
16
+
17
+ $ git clone git://github.com/tumf/vyatta-utils.git
18
+ $ cd vyatta-utils
19
+ $ bundle install
20
+
21
+ ### RubyGemsから
22
+
23
+ $ gem install vyatta-utils
24
+
25
+
26
+ config->command 変換
27
+ --------------------
28
+
29
+ Vyattaのconfigをコマンドライン形式に変換する。
30
+
31
+ $ vyatta-config2command 変換したいコンフィグファイル -o 出力先コマンドファイル
32
+
33
+ 入力先ファイルの指定を省略した場合は標準入力から入力する。
34
+ 出力先ファイルの指定を省略した場合は標準出力に出力する。
35
+
36
+ config解析用のパーサ生成
37
+ ----------------------
38
+
39
+ `lib/vyatta-utils/config.y`を修正したときには以下のコマンドでパーサを更新する。
40
+
41
+ $ racc lib/vyatta-utils/config.y -o lib/vyatta-utils/config_parser.rb
42
+
43
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','lib')))
4
+ require 'optparse'
5
+ require 'vyatta-utils'
6
+ require 'vyatta-utils/config_parser'
7
+
8
+ def walk_statements(stmts,prefix="")
9
+ res = ""
10
+ stmts.compact.each{|stmt|
11
+ if stmt.has_key?("group")
12
+ res += walk_statements(stmt["group"],prefix+" "+stmt["values"].join(" "))
13
+ else
14
+ res += "set "+prefix+" "+stmt["values"].join(" ")+"\n"
15
+ end
16
+ }
17
+ res
18
+ end
19
+ def exit_with_show_usage
20
+ puts "Vyatta config to command converter #{Vyatta::Utils::VERSION}"
21
+ puts "Usage: #{$0} [infile] [-o outfile]"
22
+ exit
23
+ end
24
+
25
+ opt=OptionParser.new
26
+ infile = nil
27
+ outfile = nil
28
+ # opt.on('-i VAL'){|v| infile=v}
29
+ opt.on('-o VAL'){|v| outfile=v}
30
+ opt.on('-v'){ exit_with_show_usage }
31
+ opt.on('-h'){ exit_with_show_usage }
32
+
33
+ opt.parse!(ARGV)
34
+
35
+ stmts = nil
36
+ parser = Vyatta::Utils::ConfigParser.new()
37
+
38
+ inf = ARGF
39
+ infile = ARGV.shift
40
+ inf = open(infile) if infile
41
+
42
+ stmts = parser.parse(inf.read)
43
+ res = walk_statements(stmts)
44
+
45
+ if outfile
46
+ open(outfile,"w"){|f|
47
+ f.write(res)
48
+ }
49
+ else
50
+ puts res
51
+ end
52
+ exit 0
@@ -0,0 +1,7 @@
1
+ require "vyatta-utils/version"
2
+
3
+ module Vyatta
4
+ module Utils
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,79 @@
1
+ class Vyatta::Utils::ConfigParser
2
+ rule
3
+ stmts: stmt stmts
4
+ {
5
+ result = val[1].unshift(val[0])
6
+ }
7
+ |
8
+ {
9
+ result = []
10
+ }
11
+
12
+ stmt: exprss CR #グループ化なし
13
+ {
14
+ result = {
15
+ "values"=>val[0]
16
+ }
17
+ }
18
+ | exprss group CR #グループ化あり
19
+ {
20
+ result = {
21
+ "values"=>val[0],
22
+ "group"=>val[1]
23
+ }
24
+ }
25
+ | CR #空文。改行挟まるところ考えるのめんどい
26
+ {
27
+ result = nil
28
+ }
29
+
30
+ exprss: expr exprs #1個以上の式
31
+ {
32
+ result = val[1].unshift(val[0])
33
+ }
34
+ exprs: expr exprs #0個以上の式
35
+ {
36
+ result = val[1].unshift(val[0])
37
+ }
38
+ |
39
+ {
40
+ result = []
41
+ }
42
+
43
+ expr: VAL {result = val[0]}
44
+
45
+ group: '{' stmts '}'
46
+ {
47
+ result = val[1]
48
+ }
49
+
50
+ end
51
+ ---- inner
52
+ def parse(str)
53
+ @yydebug=true
54
+ @tokens = str.split(/([\t \n\{\}])/).delete_if{|c|
55
+ #空白は削除
56
+ c==" " || c=="\t"
57
+ }.select{|c|
58
+ !c.nil? && c!=""
59
+ }
60
+ #p @tokens
61
+ do_parse()
62
+ end
63
+
64
+ def next_token()
65
+ token = @tokens.shift()
66
+ #p token
67
+ case token
68
+ when "\n"
69
+ return [:CR,nil]
70
+ when nil
71
+ return nil
72
+ when "{"
73
+ return ["{",nil]
74
+ when "}"
75
+ return ["}",nil]
76
+ else
77
+ return [:VAL,token]
78
+ end
79
+ end
@@ -0,0 +1,230 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.7
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+ module Vyatta
9
+ module Utils
10
+ class ConfigParser < Racc::Parser
11
+
12
+ module_eval(<<'...end config.y/module_eval...', 'config.y', 52)
13
+ def parse(str)
14
+ @yydebug=true
15
+ @tokens = str.split(/([\t \n\{\}])/).delete_if{|c|
16
+ #空白は削除
17
+ c==" " || c=="\t"
18
+ }.select{|c|
19
+ !c.nil? && c!=""
20
+ }
21
+ #p @tokens
22
+ do_parse()
23
+ end
24
+
25
+ def next_token()
26
+ token = @tokens.shift()
27
+ #p token
28
+ case token
29
+ when "\n"
30
+ return [:CR,nil]
31
+ when nil
32
+ return nil
33
+ when "{"
34
+ return ["{",nil]
35
+ when "}"
36
+ return ["}",nil]
37
+ else
38
+ return [:VAL,token]
39
+ end
40
+ end
41
+ ...end config.y/module_eval...
42
+ ##### State transition tables begin ###
43
+
44
+ racc_action_table = [
45
+ 11, 3, 12, 2, 3, 2, 3, 2, 3, 9,
46
+ 15, 3, 17, 18 ]
47
+
48
+ racc_action_check = [
49
+ 6, 7, 6, 0, 0, 12, 12, 5, 5, 4,
50
+ 9, 1, 13, 16 ]
51
+
52
+ racc_action_pointer = [
53
+ 1, 8, nil, nil, 9, 5, -2, -2, nil, 10,
54
+ nil, nil, 3, 10, nil, nil, 8, nil, nil ]
55
+
56
+ racc_action_default = [
57
+ -2, -8, -5, -9, -11, -2, -11, -8, -6, -11,
58
+ -1, -3, -2, -11, -7, 19, -11, -4, -10 ]
59
+
60
+ racc_goto_table = [
61
+ 4, 7, 8, 13, nil, 10, nil, 7, 14, nil,
62
+ nil, nil, 16 ]
63
+
64
+ racc_goto_check = [
65
+ 1, 5, 6, 4, nil, 1, nil, 5, 6, nil,
66
+ nil, nil, 1 ]
67
+
68
+ racc_goto_pointer = [
69
+ nil, 0, nil, nil, -3, 0, 1 ]
70
+
71
+ racc_goto_default = [
72
+ nil, nil, 5, 6, nil, 1, nil ]
73
+
74
+ racc_reduce_table = [
75
+ 0, 0, :racc_error,
76
+ 2, 7, :_reduce_1,
77
+ 0, 7, :_reduce_2,
78
+ 2, 8, :_reduce_3,
79
+ 3, 8, :_reduce_4,
80
+ 1, 8, :_reduce_5,
81
+ 2, 9, :_reduce_6,
82
+ 2, 12, :_reduce_7,
83
+ 0, 12, :_reduce_8,
84
+ 1, 11, :_reduce_9,
85
+ 3, 10, :_reduce_10 ]
86
+
87
+ racc_reduce_n = 11
88
+
89
+ racc_shift_n = 19
90
+
91
+ racc_token_table = {
92
+ false => 0,
93
+ :error => 1,
94
+ :CR => 2,
95
+ :VAL => 3,
96
+ "{" => 4,
97
+ "}" => 5 }
98
+
99
+ racc_nt_base = 6
100
+
101
+ racc_use_result_var = true
102
+
103
+ Racc_arg = [
104
+ racc_action_table,
105
+ racc_action_check,
106
+ racc_action_default,
107
+ racc_action_pointer,
108
+ racc_goto_table,
109
+ racc_goto_check,
110
+ racc_goto_default,
111
+ racc_goto_pointer,
112
+ racc_nt_base,
113
+ racc_reduce_table,
114
+ racc_token_table,
115
+ racc_shift_n,
116
+ racc_reduce_n,
117
+ racc_use_result_var ]
118
+
119
+ Racc_token_to_s_table = [
120
+ "$end",
121
+ "error",
122
+ "CR",
123
+ "VAL",
124
+ "\"{\"",
125
+ "\"}\"",
126
+ "$start",
127
+ "stmts",
128
+ "stmt",
129
+ "exprss",
130
+ "group",
131
+ "expr",
132
+ "exprs" ]
133
+
134
+ Racc_debug_parser = false
135
+
136
+ ##### State transition tables end #####
137
+
138
+ # reduce 0 omitted
139
+
140
+ module_eval(<<'.,.,', 'config.y', 4)
141
+ def _reduce_1(val, _values, result)
142
+ result = val[1].unshift(val[0])
143
+
144
+ result
145
+ end
146
+ .,.,
147
+
148
+ module_eval(<<'.,.,', 'config.y', 8)
149
+ def _reduce_2(val, _values, result)
150
+ result = []
151
+
152
+ result
153
+ end
154
+ .,.,
155
+
156
+ module_eval(<<'.,.,', 'config.y', 13)
157
+ def _reduce_3(val, _values, result)
158
+ result = {
159
+ "values"=>val[0]
160
+ }
161
+
162
+ result
163
+ end
164
+ .,.,
165
+
166
+ module_eval(<<'.,.,', 'config.y', 19)
167
+ def _reduce_4(val, _values, result)
168
+ result = {
169
+ "values"=>val[0],
170
+ "group"=>val[1]
171
+ }
172
+
173
+ result
174
+ end
175
+ .,.,
176
+
177
+ module_eval(<<'.,.,', 'config.y', 26)
178
+ def _reduce_5(val, _values, result)
179
+ result = nil
180
+
181
+ result
182
+ end
183
+ .,.,
184
+
185
+ module_eval(<<'.,.,', 'config.y', 31)
186
+ def _reduce_6(val, _values, result)
187
+ result = val[1].unshift(val[0])
188
+
189
+ result
190
+ end
191
+ .,.,
192
+
193
+ module_eval(<<'.,.,', 'config.y', 35)
194
+ def _reduce_7(val, _values, result)
195
+ result = val[1].unshift(val[0])
196
+
197
+ result
198
+ end
199
+ .,.,
200
+
201
+ module_eval(<<'.,.,', 'config.y', 39)
202
+ def _reduce_8(val, _values, result)
203
+ result = []
204
+
205
+ result
206
+ end
207
+ .,.,
208
+
209
+ module_eval(<<'.,.,', 'config.y', 42)
210
+ def _reduce_9(val, _values, result)
211
+ result = val[0]
212
+ result
213
+ end
214
+ .,.,
215
+
216
+ module_eval(<<'.,.,', 'config.y', 46)
217
+ def _reduce_10(val, _values, result)
218
+ result = val[1]
219
+
220
+ result
221
+ end
222
+ .,.,
223
+
224
+ def _reduce_none(val, _values, result)
225
+ val[0]
226
+ end
227
+
228
+ end # class ConfigParser
229
+ end # module Utils
230
+ end # module Vyatta
@@ -0,0 +1,5 @@
1
+ module Vyatta
2
+ module Utils
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,226 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.7
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+ class VyattaParser < Racc::Parser
9
+
10
+ module_eval(<<'...end parse.y/module_eval...', 'parse.y', 52)
11
+ def parse(str)
12
+ @yydebug=true
13
+ @tokens = str.split(/([\t \n\{\}])/).delete_if{|c|
14
+ #空白は削除
15
+ c==" " || c=="\t"
16
+ }.select{|c|
17
+ !c.nil? && c!=""
18
+ }
19
+ #p @tokens
20
+ do_parse()
21
+ end
22
+
23
+ def next_token()
24
+ token = @tokens.shift()
25
+ #p token
26
+ case token
27
+ when "\n"
28
+ return [:CR,nil]
29
+ when nil
30
+ return nil
31
+ when "{"
32
+ return ["{",nil]
33
+ when "}"
34
+ return ["}",nil]
35
+ else
36
+ return [:VAL,token]
37
+ end
38
+ end
39
+ ...end parse.y/module_eval...
40
+ ##### State transition tables begin ###
41
+
42
+ racc_action_table = [
43
+ 11, 3, 12, 2, 3, 2, 3, 2, 3, 9,
44
+ 15, 3, 17, 18 ]
45
+
46
+ racc_action_check = [
47
+ 6, 7, 6, 0, 0, 12, 12, 5, 5, 4,
48
+ 9, 1, 13, 16 ]
49
+
50
+ racc_action_pointer = [
51
+ 1, 8, nil, nil, 9, 5, -2, -2, nil, 10,
52
+ nil, nil, 3, 10, nil, nil, 8, nil, nil ]
53
+
54
+ racc_action_default = [
55
+ -2, -8, -5, -9, -11, -2, -11, -8, -6, -11,
56
+ -1, -3, -2, -11, -7, 19, -11, -4, -10 ]
57
+
58
+ racc_goto_table = [
59
+ 4, 7, 8, 13, nil, 10, nil, 7, 14, nil,
60
+ nil, nil, 16 ]
61
+
62
+ racc_goto_check = [
63
+ 1, 5, 6, 4, nil, 1, nil, 5, 6, nil,
64
+ nil, nil, 1 ]
65
+
66
+ racc_goto_pointer = [
67
+ nil, 0, nil, nil, -3, 0, 1 ]
68
+
69
+ racc_goto_default = [
70
+ nil, nil, 5, 6, nil, 1, nil ]
71
+
72
+ racc_reduce_table = [
73
+ 0, 0, :racc_error,
74
+ 2, 7, :_reduce_1,
75
+ 0, 7, :_reduce_2,
76
+ 2, 8, :_reduce_3,
77
+ 3, 8, :_reduce_4,
78
+ 1, 8, :_reduce_5,
79
+ 2, 9, :_reduce_6,
80
+ 2, 12, :_reduce_7,
81
+ 0, 12, :_reduce_8,
82
+ 1, 11, :_reduce_9,
83
+ 3, 10, :_reduce_10 ]
84
+
85
+ racc_reduce_n = 11
86
+
87
+ racc_shift_n = 19
88
+
89
+ racc_token_table = {
90
+ false => 0,
91
+ :error => 1,
92
+ :CR => 2,
93
+ :VAL => 3,
94
+ "{" => 4,
95
+ "}" => 5 }
96
+
97
+ racc_nt_base = 6
98
+
99
+ racc_use_result_var = true
100
+
101
+ Racc_arg = [
102
+ racc_action_table,
103
+ racc_action_check,
104
+ racc_action_default,
105
+ racc_action_pointer,
106
+ racc_goto_table,
107
+ racc_goto_check,
108
+ racc_goto_default,
109
+ racc_goto_pointer,
110
+ racc_nt_base,
111
+ racc_reduce_table,
112
+ racc_token_table,
113
+ racc_shift_n,
114
+ racc_reduce_n,
115
+ racc_use_result_var ]
116
+
117
+ Racc_token_to_s_table = [
118
+ "$end",
119
+ "error",
120
+ "CR",
121
+ "VAL",
122
+ "\"{\"",
123
+ "\"}\"",
124
+ "$start",
125
+ "stmts",
126
+ "stmt",
127
+ "exprss",
128
+ "group",
129
+ "expr",
130
+ "exprs" ]
131
+
132
+ Racc_debug_parser = false
133
+
134
+ ##### State transition tables end #####
135
+
136
+ # reduce 0 omitted
137
+
138
+ module_eval(<<'.,.,', 'parse.y', 4)
139
+ def _reduce_1(val, _values, result)
140
+ result = val[1].unshift(val[0])
141
+
142
+ result
143
+ end
144
+ .,.,
145
+
146
+ module_eval(<<'.,.,', 'parse.y', 8)
147
+ def _reduce_2(val, _values, result)
148
+ result = []
149
+
150
+ result
151
+ end
152
+ .,.,
153
+
154
+ module_eval(<<'.,.,', 'parse.y', 13)
155
+ def _reduce_3(val, _values, result)
156
+ result = {
157
+ "values"=>val[0]
158
+ }
159
+
160
+ result
161
+ end
162
+ .,.,
163
+
164
+ module_eval(<<'.,.,', 'parse.y', 19)
165
+ def _reduce_4(val, _values, result)
166
+ result = {
167
+ "values"=>val[0],
168
+ "group"=>val[1]
169
+ }
170
+
171
+ result
172
+ end
173
+ .,.,
174
+
175
+ module_eval(<<'.,.,', 'parse.y', 26)
176
+ def _reduce_5(val, _values, result)
177
+ result = nil
178
+
179
+ result
180
+ end
181
+ .,.,
182
+
183
+ module_eval(<<'.,.,', 'parse.y', 31)
184
+ def _reduce_6(val, _values, result)
185
+ result = val[1].unshift(val[0])
186
+
187
+ result
188
+ end
189
+ .,.,
190
+
191
+ module_eval(<<'.,.,', 'parse.y', 35)
192
+ def _reduce_7(val, _values, result)
193
+ result = val[1].unshift(val[0])
194
+
195
+ result
196
+ end
197
+ .,.,
198
+
199
+ module_eval(<<'.,.,', 'parse.y', 39)
200
+ def _reduce_8(val, _values, result)
201
+ result = []
202
+
203
+ result
204
+ end
205
+ .,.,
206
+
207
+ module_eval(<<'.,.,', 'parse.y', 42)
208
+ def _reduce_9(val, _values, result)
209
+ result = val[0]
210
+ result
211
+ end
212
+ .,.,
213
+
214
+ module_eval(<<'.,.,', 'parse.y', 46)
215
+ def _reduce_10(val, _values, result)
216
+ result = val[1]
217
+
218
+ result
219
+ end
220
+ .,.,
221
+
222
+ def _reduce_none(val, _values, result)
223
+ val[0]
224
+ end
225
+
226
+ end # class VyattaParser
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "vyatta-utils/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "vyatta-utils"
7
+ s.version = Vyatta::Utils::VERSION
8
+ s.authors = ["Yoshihiro TAKAHARA"]
9
+ s.email = ["y.takahara@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Vyatta utilities}
12
+ s.description = %q{include vyatta config to command converter}
13
+
14
+ s.rubyforge_project = "vyatta-utils"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vyatta-utils
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Yoshihiro TAKAHARA
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-20 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: include vyatta config to command converter
22
+ email:
23
+ - y.takahara@gmail.com
24
+ executables:
25
+ - vyatta-config2command
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - bin/vyatta-config2command
36
+ - lib/vyatta-utils.rb
37
+ - lib/vyatta-utils/config.y
38
+ - lib/vyatta-utils/config_parser.rb
39
+ - lib/vyatta-utils/version.rb
40
+ - lib/vyatta-utils/vyattaparser.rb
41
+ - vyatta-utils.gemspec
42
+ homepage: ""
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: vyatta-utils
71
+ rubygems_version: 1.8.12
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Vyatta utilities
75
+ test_files: []
76
+