rubyang 0.1.2.1 → 0.1.3
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 +5 -5
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -3
- data/lib/rubyang.rb +5 -6
- data/lib/rubyang/cli.rb +114 -114
- data/lib/rubyang/cli/parser.rb +56 -56
- data/lib/rubyang/compat.rb +14 -0
- data/lib/rubyang/component/base.rb +21 -21
- data/lib/rubyang/component/example.rb +8 -7
- data/lib/rubyang/database.rb +45 -34
- data/lib/rubyang/database/component_manager.rb +64 -64
- data/lib/rubyang/database/data_tree.rb +1110 -1077
- data/lib/rubyang/database/helper.rb +31 -30
- data/lib/rubyang/database/logger.rb +58 -0
- data/lib/rubyang/database/schema_tree.rb +1198 -1298
- data/lib/rubyang/model.rb +1139 -923
- data/lib/rubyang/model/logger.rb +58 -0
- data/lib/rubyang/model/parser.rb +197 -195
- data/lib/rubyang/model/parser/parser.tab.rb +1373 -1263
- data/lib/rubyang/model/parser/parser.y +393 -215
- data/lib/rubyang/restapi.rb +4 -3
- data/lib/rubyang/restapi/app.rb +52 -53
- data/lib/rubyang/server.rb +4 -3
- data/lib/rubyang/server/base.rb +20 -20
- data/lib/rubyang/server/example.rb +2 -1
- data/lib/rubyang/version.rb +4 -1
- data/lib/rubyang/webui.rb +4 -3
- data/lib/rubyang/webui/app.rb +62 -63
- data/lib/rubyang/webui/make_json_schema.rb +49 -48
- data/lib/rubyang/xpath.rb +458 -456
- data/lib/rubyang/xpath/logger.rb +58 -0
- data/lib/rubyang/xpath/parser.rb +134 -144
- data/lib/rubyang/xpath/parser/parser.tab.rb +373 -616
- data/lib/rubyang/xpath/parser/parser.y +249 -492
- data/rubyang.gemspec +11 -15
- metadata +49 -32
- data/lib/rubyang/logger.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1077d7b202071724495876ca2ac2a0d0c94291b
|
4
|
+
data.tar.gz: 8a5a8311e3ee8b649f1600450f8fbac074bb3780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be32311e6fa9a114418aba7fa9ed57e69502488ae433b22906bcfaf49e9e05809181792c636707bb82d243b28a16148c595c9023b48ff742ac216a15801b24c1
|
7
|
+
data.tar.gz: 21b3d0ef30a342af19317e540cb397ef8894075ae437c5838a92c0e78af35dcdb0c8971fb6803ccb9b04df87a034c965e9508fdeee0b9982cf398228be344167
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -4,7 +4,12 @@ env:
|
|
4
4
|
sudo: false
|
5
5
|
language: ruby
|
6
6
|
rvm:
|
7
|
-
- 2.
|
7
|
+
- 2.0
|
8
|
+
- 2.1
|
9
|
+
- 2.2
|
10
|
+
- 2.3
|
11
|
+
- 2.4
|
12
|
+
- 2.5
|
8
13
|
before_install: gem install bundler -v 1.16.1
|
9
14
|
install: bundle install --path vendor/bundle
|
10
15
|
before_script:
|
@@ -13,7 +18,5 @@ before_script:
|
|
13
18
|
- ./cc-test-reporter before-build
|
14
19
|
script:
|
15
20
|
- bundle exec rake spec
|
16
|
-
- bundle exec rake build
|
17
21
|
after_script:
|
18
22
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
19
|
-
|
data/lib/rubyang.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
require_relative 'rubyang/database'
|
3
|
+
require 'rubyang/version'
|
4
|
+
require 'rubyang/compat'
|
5
|
+
require 'rubyang/model'
|
6
|
+
require 'rubyang/xpath'
|
7
|
+
require 'rubyang/database'
|
9
8
|
|
10
9
|
module Rubyang
|
11
10
|
end
|
data/lib/rubyang/cli.rb
CHANGED
@@ -1,131 +1,131 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
require 'drb/drb'
|
4
5
|
require 'readline'
|
5
|
-
|
6
|
-
|
7
|
-
require_relative 'cli/parser'
|
6
|
+
require 'rubyang'
|
7
|
+
require 'rubyang/cli/parser'
|
8
8
|
|
9
9
|
module Rubyang
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
class Cli
|
11
|
+
def initialize
|
12
|
+
@sock_file = "/tmp/rubyang/server/Example.sock"
|
13
|
+
@db = DRbObject.new_with_uri( "drbunix:#{@sock_file}" )
|
14
14
|
|
15
|
-
|
15
|
+
@config_tree = @db.configure
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
@fo = File.open("#{File.dirname(__FILE__)}/cli/log.txt", 'w')
|
18
|
+
@fo.sync = true
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
20
|
+
#Readline.basic_word_break_characters = ""
|
21
|
+
#Readline.completer_word_break_characters = ""
|
22
|
+
Readline.completion_append_character = " "
|
23
|
+
Readline.completion_proc = proc { |buf|
|
24
|
+
@fo.puts "line_buffer: #{Readline.line_buffer}"
|
25
|
+
begin
|
26
|
+
tokens = Rubyang::Cli::Parser.parse( Readline.line_buffer )
|
27
|
+
rescue
|
28
|
+
next
|
29
|
+
end
|
30
|
+
command_type = tokens.shift
|
31
|
+
case command_type
|
32
|
+
when /^set$/
|
33
|
+
if tokens.size == 0
|
34
|
+
all_candidates = ['set']
|
35
|
+
candidates = all_candidates
|
36
|
+
else
|
37
|
+
value = tokens.last.to_s
|
38
|
+
all_candidates = get_candidates( @config_tree, tokens )
|
39
|
+
candidates = all_candidates.grep(/^#{Regexp.escape(value.to_s)}/)
|
40
|
+
end
|
41
|
+
when /^show$/
|
42
|
+
format = tokens[0].to_s
|
43
|
+
all_candidates = ['xml', 'json']
|
44
|
+
candidates = all_candidates.grep(/^#{Regexp.escape(format.to_s)}/)
|
45
|
+
candidates
|
46
|
+
else
|
47
|
+
all_candidates = ['set', 'show']
|
48
|
+
candidates = all_candidates.grep(/^#{Regexp.escape(command_type.to_s)}/)
|
49
|
+
candidates
|
50
|
+
end
|
51
|
+
@fo.puts "tokens = #{tokens.inspect}"
|
52
|
+
@fo.puts "all_candidates = #{all_candidates.inspect}"
|
53
|
+
@fo.puts "candidates = #{candidates.inspect}"
|
54
|
+
@fo.puts
|
55
|
+
@fo.puts
|
56
|
+
candidates
|
57
|
+
}
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
def set config_tree, tokens
|
61
|
+
set_recursive config_tree, tokens
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
64
|
+
def set_recursive config_tree, tokens
|
65
|
+
return config_tree if tokens.size == 0
|
66
|
+
token = tokens[0]
|
67
|
+
case tokens[1..-1].size
|
68
|
+
when 0
|
69
|
+
config_tree.set token
|
70
|
+
else
|
71
|
+
child_tree = config_tree.edit token
|
72
|
+
set_recursive child_tree, tokens[1..-1]
|
73
|
+
end
|
74
|
+
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
76
|
+
def get_candidates config_tree, tokens
|
77
|
+
@fo.puts config_tree.class
|
78
|
+
@fo.puts tokens.inspect
|
79
|
+
token = tokens[0].to_s
|
80
|
+
case config_tree
|
81
|
+
when Rubyang::Database::DataTree::Leaf
|
82
|
+
if tokens.size == 1
|
83
|
+
[config_tree.value]
|
84
|
+
else
|
85
|
+
[]
|
86
|
+
end
|
87
|
+
else
|
88
|
+
if tokens.size > 1 and config_tree.schema.children.map{ |c| c.arg }.include? token
|
89
|
+
child_tree = config_tree.edit token
|
90
|
+
get_candidates child_tree, tokens[1..-1]
|
91
|
+
else
|
92
|
+
config_tree.schema.children.map{ |c| c.arg }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
97
|
+
def run
|
98
|
+
while buf = Readline.readline("> ", true)
|
99
|
+
tokens = Rubyang::Cli::Parser.parse( buf )
|
100
|
+
command_type = tokens.shift
|
101
|
+
case command_type
|
102
|
+
when /^set$/
|
103
|
+
begin
|
104
|
+
set @config_tree, tokens
|
105
|
+
rescue => e
|
106
|
+
puts "Error: #{e}"
|
107
|
+
end
|
108
|
+
when /^show$/
|
109
|
+
show_type = tokens.shift
|
110
|
+
case show_type
|
111
|
+
when /^xml$/
|
112
|
+
puts @config_tree.to_xml( pretty: true )
|
113
|
+
when /^json$/
|
114
|
+
puts @config_tree.to_json( pretty: true )
|
115
|
+
end
|
116
|
+
when /^commit$/
|
117
|
+
begin
|
118
|
+
@config_tree.commit
|
119
|
+
rescue => e
|
120
|
+
puts "Error: #{e}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
126
|
end
|
127
127
|
|
128
128
|
if __FILE__ == $0
|
129
|
-
|
130
|
-
|
129
|
+
cli = Rubyang::Cli.new
|
130
|
+
cli.run
|
131
131
|
end
|
data/lib/rubyang/cli/parser.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# vim: et ts=2 sw=2
|
2
3
|
|
3
4
|
require 'strscan'
|
4
|
-
|
5
|
-
#require_relative 'parser/parser.tab.rb'
|
5
|
+
#require 'rubyang/cli/parser/parser.tab.rb'
|
6
6
|
|
7
7
|
module Rubyang
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
class Cli
|
9
|
+
class Parser
|
10
|
+
def self.parse( str )
|
11
|
+
parser = self.new
|
12
|
+
parser.parse( str )
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
def initialize
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
def parse( str )
|
19
|
+
@tokens = Array.new
|
20
20
|
|
21
|
-
|
21
|
+
s = StringScanner.new( str )
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
keywords = {
|
24
|
+
}
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
scanre_list = [
|
27
|
+
["dqstr", /^"(?:[^"]|\\.)*"/],
|
28
|
+
["sqstr", /^'(?:[^']|\\.)*'/],
|
29
|
+
["nqstr", /^[a-zA-Z0-9:\/\|\.=_-]+/],
|
30
|
+
["wsp", /^[ \t]+/],
|
31
|
+
]
|
32
|
+
scanres = scanre_list.to_h
|
33
33
|
|
34
|
-
|
34
|
+
scanre = Regexp.union( scanre_list.map{ |scanre| scanre[1] } )
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
36
|
+
last = ''
|
37
|
+
until s.eos?
|
38
|
+
token = s.scan( scanre )
|
39
|
+
case token
|
40
|
+
when scanres["dqstr"] then
|
41
|
+
token_ = token.gsub(/^"/,'').gsub(/"$/,'').gsub(/\\n/,"\n").gsub(/\\t/,"\t").gsub(/\\"/,"\"").gsub(/\\\\/,"\\")
|
42
|
+
@tokens.push token_
|
43
|
+
last = "dqstr"
|
44
|
+
when scanres["sqstr"] then
|
45
|
+
token_ = token.gsub(/^'/,'').gsub(/'$/,'')
|
46
|
+
@tokens.push token_
|
47
|
+
last = "sqstr"
|
48
|
+
when scanres["nqstr"] then
|
49
|
+
@tokens.push token
|
50
|
+
last = "nqstr"
|
51
|
+
when scanres["wsp"] then
|
52
|
+
last = "wsp"
|
53
|
+
else raise "token not match to any scanres: #{token.inspect}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
if last == "wsp"
|
57
|
+
@tokens.push ''
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
#result = self.do_parse
|
61
|
+
return @tokens
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
def next_token
|
65
|
+
#p @tokens.first
|
66
|
+
@tokens.shift
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
70
|
end
|
71
71
|
|
72
72
|
if __FILE__ == $0
|
73
|
-
|
73
|
+
p Rubyang::Cli::Parser.parse "set aaa "
|
74
74
|
end
|