junoser 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -4
- data/Gemfile.lock +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/junoser/display/config_store.rb +2 -2
- data/lib/junoser/squash.rb +53 -57
- data/lib/junoser/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a3ba4fa96e3b50240e889334a924403ae8cf4f508c1e86120450aa0760fe75f
|
4
|
+
data.tar.gz: 6f034ac0b34aff7aed1f7aed0d87b902996ae1cdbbc0d0f6ed2896f50caaf939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef0675b148025de1a36a95ec7bcd0ea92863a6740c6122ba6c675e02400ae7ab0cc59237083a4d01c11a56b8c070285b4817d7067fd702f7cd07990d4616cd19
|
7
|
+
data.tar.gz: c5cb5388660e8dd1605e39e7f1a02a2f7b118841d60927865e86ceea1d53c7a92b92390c552f60d3f33ea7d6dd8c7df94151e70a26a26bd0fe48e1d49029abb9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## [0.3.10] - 2020-01-09
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Experimentally support "insert" statement
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* junoser-squash unexpectedly kept statements intact due to tokenization bug
|
10
|
+
* junoser-squash unexpectedly removed "deactivate" statements
|
11
|
+
* "deactivate" to "inactive:" translation during "junoser -s"
|
12
|
+
|
1
13
|
## [0.3.9] - 2019-11-17
|
2
14
|
|
3
15
|
### Fixed
|
@@ -15,14 +27,14 @@
|
|
15
27
|
|
16
28
|
## [0.3.7] - 2019-09-03
|
17
29
|
|
18
|
-
### Fixed
|
19
|
-
|
20
|
-
* "apply-groups" translation between "display set" and structured form
|
21
|
-
|
22
30
|
### Added
|
23
31
|
|
24
32
|
* Support "deactivate ... apply-groups"
|
25
33
|
|
34
|
+
### Fixed
|
35
|
+
|
36
|
+
* "apply-groups" translation between "display set" and structured form
|
37
|
+
|
26
38
|
|
27
39
|
## [0.3.6] - 2019-08-25
|
28
40
|
|
data/Gemfile.lock
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -78,7 +78,7 @@ module Junoser
|
|
78
78
|
def match(str)
|
79
79
|
each do |statement, store|
|
80
80
|
# NOTE: return the first object
|
81
|
-
return [statement, store] if str =~ /^#{Regexp.escape(statement)}(
|
81
|
+
return [statement, store] if str =~ /^#{Regexp.escape(statement)}((?= )|$)/
|
82
82
|
end
|
83
83
|
|
84
84
|
[]
|
@@ -87,7 +87,7 @@ module Junoser
|
|
87
87
|
def inverse_match(str)
|
88
88
|
each do |statement, store|
|
89
89
|
# NOTE: return the first object
|
90
|
-
return [statement, store] if statement =~ /^#{str}
|
90
|
+
return [statement, store] if statement =~ /^#{str}(?= )/
|
91
91
|
end
|
92
92
|
|
93
93
|
[]
|
data/lib/junoser/squash.rb
CHANGED
@@ -2,62 +2,12 @@ require 'junoser'
|
|
2
2
|
require 'parslet'
|
3
3
|
|
4
4
|
module Junoser
|
5
|
-
class DeleteTransformer < Parslet::Transform
|
6
|
-
rule(config: simple(:config)) do
|
7
|
-
"(#{config.to_s} .*"
|
8
|
-
end
|
9
|
-
|
10
|
-
rule(config: sequence(:configs)) do
|
11
|
-
configs.join("\n")
|
12
|
-
end
|
13
|
-
|
14
|
-
rule(arg: simple(:arg)) do
|
15
|
-
arg
|
16
|
-
end
|
17
|
-
|
18
|
-
rule(label: simple(:label)) do
|
19
|
-
")#{Regexp.escape(label.to_s)}"
|
20
|
-
end
|
21
|
-
|
22
|
-
rule(label: simple(:label), child: simple(:child)) do
|
23
|
-
"#{Regexp.escape(label.to_s)} #{child}"
|
24
|
-
end
|
25
|
-
|
26
|
-
rule(label: simple(:label), child: sequence(:children)) do
|
27
|
-
%[#{Regexp.escape(label.to_s)} #{children.join(' ')}]
|
28
|
-
end
|
29
|
-
|
30
|
-
rule(statement: simple(:statement), argument: simple(:argument)) do
|
31
|
-
"#{statement} #{argument}"
|
32
|
-
end
|
33
|
-
|
34
|
-
rule(statement: simple(:statement), argument: sequence(:arguments)) do
|
35
|
-
%[#{statement} #{arguments.join(' ')}]
|
36
|
-
end
|
37
|
-
|
38
|
-
rule(oneline: simple(:str)) do
|
39
|
-
str
|
40
|
-
end
|
41
|
-
|
42
|
-
rule(oneline: sequence(:strs)) do
|
43
|
-
strs.join(' ')
|
44
|
-
end
|
45
|
-
|
46
|
-
rule(enum: simple(:str)) do
|
47
|
-
str
|
48
|
-
end
|
49
|
-
|
50
|
-
rule(enum: sequence(:strs)) do
|
51
|
-
strs.join(' ')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
5
|
class Squash
|
56
6
|
def initialize(io_or_string)
|
57
7
|
@input = io_or_string
|
58
8
|
@lines = []
|
59
9
|
@parser = Junoser::Parser.new
|
60
|
-
@transformer =
|
10
|
+
@transformer = Junoser::Transformer.new
|
61
11
|
end
|
62
12
|
|
63
13
|
def transform
|
@@ -65,11 +15,14 @@ module Junoser
|
|
65
15
|
config.each do |l|
|
66
16
|
l.strip!
|
67
17
|
case l
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
18
|
+
when /^(set|deactivate) /
|
19
|
+
@lines << l
|
20
|
+
when /^delete /
|
21
|
+
delete_lines delete_pattern(l.gsub(/^delete /, 'set '))
|
22
|
+
when /^insert (.*) before (.*)/
|
23
|
+
insert_before insert_pattern("set #{$1}"), $2
|
24
|
+
when /^insert (.*) after (.*)/
|
25
|
+
insert_after insert_pattern("set #{$1}"), $2
|
73
26
|
end
|
74
27
|
end
|
75
28
|
|
@@ -80,7 +33,7 @@ module Junoser
|
|
80
33
|
private
|
81
34
|
|
82
35
|
def remove_subcommand(lines)
|
83
|
-
lines.each_with_index do |l,i|
|
36
|
+
lines.each_with_index do |l, i|
|
84
37
|
lines[i..-1].each do |l2|
|
85
38
|
if l.include?(l2) and l != l2
|
86
39
|
lines.delete(l2)
|
@@ -94,5 +47,48 @@ module Junoser
|
|
94
47
|
l.sub!(/#{pattern}/) { $1 }
|
95
48
|
end
|
96
49
|
end
|
50
|
+
|
51
|
+
def split_last_token(line)
|
52
|
+
tokens = join_arg(@transformer.apply(@parser.parse(line))).split("\n")
|
53
|
+
tokens.map! { |t|
|
54
|
+
t.gsub!(/arg\((.*)\)/) { "#$1" } # Strip arg
|
55
|
+
Regexp.escape(t.strip)
|
56
|
+
}
|
57
|
+
|
58
|
+
[tokens[0..-2].join(' '), tokens.last]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Ported from lib/junoser/display/config_store.rb
|
62
|
+
def join_arg(str)
|
63
|
+
str.gsub!(/\narg\((.*)\)$/) { " #$1" }
|
64
|
+
str.gsub!(/arg\((.*)\)/) { "#$1" }
|
65
|
+
str
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_pattern(line)
|
69
|
+
line, last_token = split_last_token(line)
|
70
|
+
"(#{line}\s+)#{last_token}.*"
|
71
|
+
end
|
72
|
+
|
73
|
+
def insert_pattern(line)
|
74
|
+
line, last_token = split_last_token(line)
|
75
|
+
"(#{line})\s+#{last_token}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def insert_before(pattern_to_insert, key_token)
|
79
|
+
key_pattern = pattern_to_insert.sub(/\).*/) { ") #{key_token}" }
|
80
|
+
|
81
|
+
lines_to_insert = @lines.select { |l| l =~ /#{pattern_to_insert}/ }
|
82
|
+
@lines.reject! { |l| l =~ /#{pattern_to_insert}/ }
|
83
|
+
|
84
|
+
key_index = @lines.index { |l| l =~ /#{key_pattern}/ }
|
85
|
+
@lines.insert(key_index, lines_to_insert).flatten!
|
86
|
+
end
|
87
|
+
|
88
|
+
def insert_after(pattern_to_insert, key_token)
|
89
|
+
@lines.reverse!
|
90
|
+
insert_before pattern_to_insert, key_token
|
91
|
+
@lines.reverse!
|
92
|
+
end
|
97
93
|
end
|
98
94
|
end
|
data/lib/junoser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: junoser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shintaro Kojima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.1.2
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: PEG parser for JUNOS configuration.
|