junoser 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5bbbf4cbf8b352da5a17d9ad7892d3fa06841ec9
4
- data.tar.gz: fc30976c13fd9d3d4f87369f4494b4e0561d353c
2
+ SHA256:
3
+ metadata.gz: c57ce175272ab8d4f63ed240702c73a709a70103f27f8cf0a6fd77165b08f2fc
4
+ data.tar.gz: b9cfb28b26ae82b90d3cf2d2609f7d522893e31d3f9f860a09a10f02764896e5
5
5
  SHA512:
6
- metadata.gz: 594422e8d706bed8b741216bdb2628a004505ebcd5fd277695877e63e5230e2ecd5898f0f47fe12491a5473042a017bda7029940f57352d03b53fe08d34dde7f
7
- data.tar.gz: 63d495c8afc1fbd706039429b1f603bfa9644e8976556677926aebfbe99d560be83bacdb1670da27ef15a20df804c2bf290e8b2e35ab1ef7a044f30aa9902116
6
+ metadata.gz: bfa6f43c77d796fae64975faa7163d3f10accf8068bfb4efd736b5acb89ccc1ce20827848a9fba6dc96aa3899b632970cd403abb7c8a0ce7e8f852a7a22a0559
7
+ data.tar.gz: 25192747b57063c0a77752ebccd7470b944150f8413a75d1c84854385357e6b41a0e5587d5505daa97227d16eb4023367580f67e36d17be19a156cd19402154d
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Shintaro Kojima
3
+ Copyright (c) 2018 Shintaro Kojima
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -67,4 +67,4 @@ Or send a pull request to fix.
67
67
 
68
68
  ## Copyright and License
69
69
 
70
- Copyright (c) 2017 Shintaro Kojima. Code released under the [MIT license](LICENSE.txt).
70
+ Copyright (c) 2018 Shintaro Kojima. Code released under the [MIT license](LICENSE.txt).
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'pathname'
4
+
5
+ $: << File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
6
+ require 'junoser/squash'
7
+
8
+ command = :squash
9
+ opts = OptionParser.new do |opts|
10
+ opts.banner = 'junoser-squash: squash config file.'
11
+ opts.define_head 'Usage: junoser-squash [path]'
12
+
13
+ opts.on_tail '-h', '--help', 'Show this message' do
14
+ puts opts
15
+ exit
16
+ end
17
+ end
18
+ opts.parse!
19
+ case command
20
+ when :squash
21
+ puts Junoser::Squash.new($<).transform
22
+ else
23
+ puts opts
24
+ abort
25
+ end
@@ -89563,11 +89563,7 @@ module Junoser
89563
89563
  end
89564
89564
 
89565
89565
  rule(:server_group_type) do
89566
- c(
89567
- c(
89568
- arg
89569
- )
89570
- )
89566
+ s(arg, arg)
89571
89567
  end
89572
89568
 
89573
89569
  rule(:server_leasequery_type) do
data/lib/junoser/ruler.rb CHANGED
@@ -134,6 +134,7 @@ module Junoser
134
134
  str.gsub!(/(rule\(:control_source_address_filter_type\) do\s*)s\(\s*arg,/) { "#{$1}b(" }
135
135
  str.gsub!(/^(rule\(:trace_file_type\) do\s*)c\(\s*arg,/) { "#{$1}sca(" }
136
136
  str.gsub!(/^(rule\(:archive_object\) do\s*)c\(/) { "#{$1}sc(" }
137
+ str.gsub!(/^(rule\(:server_group_type\) do\s*)c\(\s*c\(\s*arg\s*\)\s*\)/) { "#{$1}s(arg, arg)" }
137
138
  str.gsub!(/^(rule\(:rib_group_inet_type\) do)\s*c\(\s*arg/) do
138
139
  format([$1,
139
140
  ' ca(',
@@ -0,0 +1,90 @@
1
+ require 'junoser'
2
+ require 'parslet'
3
+
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
+ end
46
+
47
+ class Squash
48
+ def initialize(io_or_string)
49
+ @input = io_or_string
50
+ @lines = []
51
+ @parser = Junoser::Parser.new
52
+ @transformer = DeleteTransformer.new
53
+ end
54
+
55
+ def transform
56
+ config = Junoser::Input.new(@input).read.split("\n")
57
+ config.each do |l|
58
+ l.strip!
59
+ case l
60
+ when /^set /
61
+ @lines << l
62
+ when /^delete /
63
+ to_delete = @parser.parse(l.gsub(/^delete /, 'set '))
64
+ delete_lines @transformer.apply(to_delete)
65
+ end
66
+ end
67
+
68
+ @lines.uniq!
69
+ remove_subcommand(@lines).map(&:strip).join("\n")
70
+ end
71
+
72
+ private
73
+
74
+ def remove_subcommand(lines)
75
+ lines.each_with_index do |l,i|
76
+ lines[i..-1].each do |l2|
77
+ if l.include?(l2) and l != l2
78
+ lines.delete(l2)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ def delete_lines(pattern)
85
+ @lines.each do |l|
86
+ l.sub!(/#{pattern}/) { $1 }
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module Junoser
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shintaro Kojima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -85,6 +85,7 @@ email:
85
85
  - goodies@codeout.net
86
86
  executables:
87
87
  - junoser
88
+ - junoser-squash
88
89
  extensions: []
89
90
  extra_rdoc_files: []
90
91
  files:
@@ -100,6 +101,7 @@ files:
100
101
  - example/vmx-17.2R1.13.rb
101
102
  - example/vsrx-12.1.x47.rb
102
103
  - exe/junoser
104
+ - exe/junoser-squash
103
105
  - junoser.gemspec
104
106
  - lib/junoser.rb
105
107
  - lib/junoser/cli.rb
@@ -111,6 +113,7 @@ files:
111
113
  - lib/junoser/input.rb
112
114
  - lib/junoser/parser.rb
113
115
  - lib/junoser/ruler.rb
116
+ - lib/junoser/squash.rb
114
117
  - lib/junoser/transformer.rb
115
118
  - lib/junoser/version.rb
116
119
  - lib/junoser/xsd/base.rb
@@ -144,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
147
  version: '0'
145
148
  requirements: []
146
149
  rubyforge_project:
147
- rubygems_version: 2.6.13
150
+ rubygems_version: 2.7.3
148
151
  signing_key:
149
152
  specification_version: 4
150
153
  summary: PEG parser for JUNOS configuration.