revamp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41d21259b91a311de66a19a77acfee5df77ace9c
4
+ data.tar.gz: 9eef3e18a404759071d7cdbe6b59299b08cda2a1
5
+ SHA512:
6
+ metadata.gz: 24d7ff656d8852dc9594339d3aa98d5a13de204231551fba12465f0237506932e115acad6c62da916867d52ec0b84d85bd55fec7fca78b191cc4412e061bfeb5
7
+ data.tar.gz: a56909e5d762d3a5ce6097e40949431f0636eea6e9f5cb303d8b20f104dbc90dd50224f6cda9c72a8bfc3ae7c6e7bdd161a6000f39576ef50fa3b3c3607ce99e
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ log
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format
2
+ d
3
+ --colour
4
+ --order rand
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+ inherit_from: .rubocop_todo.yml
4
+
5
+ AllCops:
6
+ Include:
7
+ - 'lib/**/*.rb'
8
+ - 'bin/*'
9
+ - 'Rakefile'
10
+ - 'Gemfile'
11
+ - '*.gemspec'
12
+ Exclude:
13
+ - '.**/*'
14
+ - 'spec/**/*'
15
+ - 'coverage/**/*'
16
+ - '.vendor/**/*'
17
+ - 'vendor/**/*'
18
+ - '.bundle/**/*'
19
+
20
+ Metrics/LineLength:
21
+ Max: 120
22
+
23
+ Metrics/MethodLength:
24
+ Max: 15
25
+
26
+ Metrics/AbcSize:
27
+ Max: 20
28
+ Style/ClassAndModuleChildren:
29
+ EnforcedStyle: compact
data/.rubocop_todo.yml ADDED
File without changes
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ language: ruby
3
+ sudo: false
4
+ bundler_args: --without development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
5
+ cache: bundler
6
+ script:
7
+ - bundle exec rake test
8
+ before_install: rm -f Gemfile.lock
9
+ rvm:
10
+ - '1.9'
11
+ - '2.0'
12
+ - '2.1'
13
+ - '2.2'
14
+ notifications:
15
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,30 @@
1
+ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rake', '~> 10.4.0', require: false
7
+ gem 'rspec', '~> 3.3.0', require: false
8
+ gem 'rspec-its', '~> 1.2.0', require: false
9
+ gem 'simplecov', '~> 0.10.0', require: false
10
+ gem 'rubocop', '~> 0.34.0', require: false
11
+ gem 'inch', '~> 0.7.0', require: false
12
+ gem 'coveralls', '~> 0.8.9', require: false
13
+ gem 'codeclimate-test-reporter', '~> 0.4.8', require: false
14
+ end
15
+
16
+ group :development do
17
+ gem 'guard', '~> 2.13.0', require: false
18
+ gem 'guard-bundler', '~> 2.1.0', require: false
19
+ gem 'guard-rake', '~> 1.0.0', require: false
20
+ gem 'guard-rubocop', '~> 1.2.0', require: false
21
+ gem 'pry-byebug', '~> 3.2.0', require: false if RUBY_VERSION > '2.0.0'
22
+ end
23
+
24
+ local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.ruby19')
25
+ eval_gemfile local_gemfile if File.exist?(local_gemfile)
26
+
27
+ local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
28
+ eval_gemfile local_gemfile if File.exist?(local_gemfile)
29
+
30
+ # vim:ft=ruby
data/Gemfile.ruby19 ADDED
@@ -0,0 +1 @@
1
+ gem 'tins', '~> 1.6.0', require: false if RUBY_VERSION < '2.0.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright (c) 2015 Centralny Ośrodek Informatyki
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Revamp
2
+
3
+ [![Build Status](https://travis-ci.org/coi-gov-pl/revamp.svg)](https://travis-ci.org/coi-gov-pl/revamp) [![Coverage Status](https://coveralls.io/repos/coi-gov-pl/revamp/badge.svg?branch=develop&service=github)](https://coveralls.io/github/coi-gov-pl/revamp?branch=develop) [![Code Climate](https://codeclimate.com/github/coi-gov-pl/revamp/badges/gpa.svg)](https://codeclimate.com/github/coi-gov-pl/revamp) [![Dependency Status](https://gemnasium.com/coi-gov-pl/revamp.svg)](https://gemnasium.com/coi-gov-pl/revamp)
4
+
5
+ This module can convert standard puppet module file in form of tarball to valid RPM or DEB package with all dependencies as references to other system packages. The dependencies can be packaged inside the final system package or just referenced as dependencies.
6
+
7
+ ## Installation
8
+
9
+ Install it yourself, globally as:
10
+
11
+ $ sudo gem install revamp
12
+
13
+ On Debian/Ubuntu systems to convert to RPM you will need also:
14
+
15
+ $ sudo apt-get install librpm-dev
16
+
17
+ ## Usage
18
+
19
+ The basic usage is really simple:
20
+
21
+ $ revamp -f coi-jboss-1.0.0.tar.gz
22
+ INFO: Converting to RPM package puppetmodule_coi-jboss-1.0.0-0.noarch.rpm...
23
+ INFO: Files successfully converted: 1.
24
+
25
+ Or with extra options:
26
+
27
+ $ revamp --release 42 --outdir /tmp -f coi-jboss-1.0.0.tar.gz
28
+ INFO: Converting to RPM package /tmp/puppetmodule_coi-jboss-1.0.0-42.noarch.rpm...
29
+ INFO: Files successfully converted: 1.
30
+
31
+ More on available options in help:
32
+
33
+ $ revamp --help
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/coi-gov-pl/gem-revamp/fork )
38
+ 2. Create your feature branch (`git checkout -b feature/my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin feature/my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+ require 'rubocop'
5
+ require 'fileutils'
6
+ require 'rainbow'
7
+ require 'inch/rake'
8
+
9
+ namespace :spec do
10
+ desc 'Run all spec tests at once.'
11
+ RSpec::Core::RakeTask.new(:all)
12
+
13
+ desc 'Run unit spec tests.'
14
+ RSpec::Core::RakeTask.new(:unit) do |t|
15
+ t.pattern = [
16
+ 'spec/unit'
17
+ ]
18
+ end
19
+
20
+ desc 'Run integration spec tests.'
21
+ RSpec::Core::RakeTask.new(:integration) do |t|
22
+ t.pattern = [
23
+ 'spec/integration'
24
+ ]
25
+ end
26
+ end
27
+
28
+ Inch::Rake::Suggest.new :inch, '--pedantic'
29
+
30
+ RuboCop::RakeTask.new(:rubocop) do |task|
31
+ # don't abort rake on failure
32
+ task.fail_on_error = true
33
+ end
34
+
35
+ namespace :rubocop do
36
+ namespace :todo do
37
+ desc 'Cleans a rubocop TODO list'
38
+ task :clean do
39
+ File.write('.rubocop_todo.yml', '')
40
+ Rake::Task[:rubocop].execute
41
+ end
42
+
43
+ desc 'Saves actual rubocop state into TODO list'
44
+ task :save do
45
+ rcli = RuboCop::CLI.new
46
+ rcli.run ['--auto-gen-config']
47
+ end
48
+ end
49
+ end
50
+
51
+ tests = [
52
+ :'spec:all',
53
+ :rubocop,
54
+ :inch
55
+ ]
56
+
57
+ desc 'Run lint, and all spec tests.'
58
+ task test: tests
59
+
60
+ desc 'test package'
61
+ task build: [:test]
62
+
63
+ task default: :test
data/bin/revamp ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $0 = 'revamp'
4
+
5
+ begin
6
+ require 'revamp/cli'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'revamp/cli'
10
+ end
11
+
12
+ # Process command line options and run Revamp
13
+ Kernel.exit(Revamp::CLI.new.run!)
@@ -0,0 +1,33 @@
1
+ require 'revamp'
2
+ require 'revamp/persister/rpm'
3
+ require 'revamp/parser/puppet-tarball'
4
+
5
+ # A main application class
6
+ class Revamp::Application
7
+ def initialize(options)
8
+ @options = options
9
+ @filenames = options[:filenames]
10
+ @format = :rpm
11
+ end
12
+
13
+ def run!
14
+ @filenames.each do |file|
15
+ parser = Revamp::Parser::PuppetTarball.new(file)
16
+ model = parser.parse
17
+ persister = build_persister
18
+ persister.persist(model)
19
+ end
20
+ Revamp.logger.info("Files successfully converted: #{@filenames.size}.")
21
+ end
22
+
23
+ protected
24
+
25
+ def build_persister
26
+ persister = case @format
27
+ when :rpm then Revamp::Persister::Rpm.new
28
+ else fail ArgumentError, "Unknown format: #{@format}"
29
+ end
30
+ persister.options = @options
31
+ persister
32
+ end
33
+ end
data/lib/revamp/cli.rb ADDED
@@ -0,0 +1,98 @@
1
+ require 'micro-optparse'
2
+ require 'revamp'
3
+
4
+ # A command line interface class
5
+ class Revamp::CLI
6
+ # Executes an Revamp from CLI
7
+ #
8
+ # @param argv [Array] an argv from CLI
9
+ # @return [Integer] a status code for program
10
+ def run!(argv = ARGV)
11
+ exec = parse_execution(argv)
12
+ return -1 unless exec.success?
13
+ exec = run_execution(exec.value)
14
+ return 1 unless exec.success?
15
+ 0
16
+ end
17
+
18
+ protected
19
+
20
+ # Parse an ARGV command line arguments
21
+ # @param argv [Array] an argv from CLI
22
+ # @return [Hash] options to use by application
23
+ def parse(argv)
24
+ options = parser.process!(argv)
25
+ validate_options(options)
26
+ Revamp.logger.level = Logger::INFO unless options[:verbose]
27
+ options
28
+ end
29
+
30
+ private
31
+
32
+ def validate_options(options)
33
+ filenames = options[:filenames]
34
+ fail ArgumentError, "You must pass filenames with `-f`. See: `#{$PROGRAM_NAME} --help`" if filenames.empty?
35
+ filenames.each do |file|
36
+ fail ArgumentError, "Can't read file given: #{file}" unless File.readable?(file)
37
+ end
38
+
39
+ outdir = options[:outdir]
40
+ fail ArgumentError, "Can't write to output directory: #{@outdir}" unless File.writable?(outdir)
41
+ end
42
+
43
+ def parse_execution(argv)
44
+ Execution.new(true, parse(argv))
45
+ rescue ArgumentError => ex
46
+ Revamp.logger.fatal(ex)
47
+ Execution.new(false)
48
+ end
49
+
50
+ def run_execution(options)
51
+ require 'revamp/application'
52
+ Execution.new(true, Revamp::Application.new(options).run!)
53
+ rescue StandardError => ex
54
+ bug = Revamp.bug(ex)
55
+ Revamp.logger.fatal("Unexpected error occured, mayby a bug?\n\n#{bug[:message]}\n\n#{bug[:help]}")
56
+ Execution.new(false)
57
+ end
58
+
59
+ def banner
60
+ txt = <<-eos
61
+ #{Revamp::NAME} v#{Revamp::VERSION} - #{Revamp::SUMMARY}
62
+
63
+ #{Revamp::DESCRIPTION}
64
+ Usage: #{$PROGRAM_NAME} [options]
65
+ eos
66
+ txt
67
+ end
68
+
69
+ def parser
70
+ Parser.new do |p|
71
+ p.banner = banner
72
+ p.version = Revamp::VERSION
73
+ p.option :release, 'A RPM release number, by default it is equal to \'1\'', default: '1'
74
+ p.option :epoch, 'A RPM epoch number, by default it is equal to \'6\'', default: '6'
75
+ p.option(
76
+ :outdir,
77
+ 'A directory to output converted packages, by default this is current directory: ' + Dir.pwd,
78
+ default: Dir.pwd
79
+ )
80
+ p.option :filenames, 'Files which will be processed', default: []
81
+ p.option :verbose, 'Should print all information, by default: false', default: false
82
+ p.option :cleanup, 'Should temporary files be cleaned up, by default: true', default: true
83
+ end
84
+ end
85
+
86
+ # An execution wrapper
87
+ class Execution
88
+ attr_reader :value
89
+ def initialize(success, value = nil)
90
+ @success = success
91
+ @value = value
92
+ end
93
+
94
+ def success?
95
+ @success == true
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,98 @@
1
+ require 'revamp'
2
+ require 'revamp/mapper/puppet-name-slugger'
3
+
4
+ # A filter that process Puppet dependency into RPM requirements lines
5
+ # More info: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#dependencies-in-metadatajson
6
+ # Even more info: https://robots.thoughtbot.com/rubys-pessimistic-operator
7
+ class Revamp::Filter::PuppetVerToRpmReq
8
+ PUPPETMODULE = 'puppetmodule'
9
+ TWIDDLE_WAKKA = '~>'
10
+
11
+ attr_accessor :slugger, :slug
12
+
13
+ def initialize
14
+ @slugger = Revamp::Mapper::PuppetNameSlugger.new
15
+ end
16
+
17
+ # Filters a Puppet version
18
+ # @param [puppetver] Revamp::Model::PuppetDependency
19
+ # @return String[]
20
+ def filter(puppetver)
21
+ @slug = slugger.map(puppetver.name)
22
+ reqs = []
23
+ requirements = puppetver.version.requirements
24
+ if singular?(requirements)
25
+ reqs += filter_single(requirements.first)
26
+ else
27
+ reqs += filter_many(requirements)
28
+ end
29
+ reqs
30
+ end
31
+
32
+ private
33
+
34
+ def filter_single(requirement)
35
+ reqs = []
36
+ type, version = requirement
37
+ if type == TWIDDLE_WAKKA
38
+ reqs += filter_twiddle_wakka(version)
39
+ elsif semver?(version)
40
+ reqs += filter_semver(version)
41
+ else
42
+ reqs += process(requirement)
43
+ end
44
+ reqs
45
+ end
46
+
47
+ def filter_many(requirements)
48
+ reqs = []
49
+ requirements.each do |tuple|
50
+ reqs += process(tuple)
51
+ end
52
+ reqs
53
+ end
54
+
55
+ def modulename
56
+ "#{PUPPETMODULE}(#{slug})"
57
+ end
58
+
59
+ def process(requirement)
60
+ type, version = requirement
61
+ ["#{modulename} #{type} #{version}"]
62
+ end
63
+
64
+ def filter_twiddle_wakka(version)
65
+ upper_cap = make_upper_cap(version)
66
+ reqs = []
67
+ reqs << "#{modulename} >= #{version}"
68
+ reqs << "#{modulename} < #{upper_cap}"
69
+ reqs
70
+ end
71
+
72
+ def filter_semver(version)
73
+ digital = digitalize(version)
74
+ filter_twiddle_wakka(digital)
75
+ end
76
+
77
+ def make_upper_cap(version)
78
+ # take second from back and add increment
79
+ upper_cap_digit = version.segments[-2] + 1
80
+ segments = version.segments.dup
81
+ segments[-2] = upper_cap_digit
82
+ # zero last digit
83
+ segments[-1] = 0
84
+ Gem::Version.new(segments.join('.'))
85
+ end
86
+
87
+ def digitalize(version)
88
+ Gem::Version.new(version.to_s.tr('x', '0'))
89
+ end
90
+
91
+ def semver?(version)
92
+ version.to_s.include? 'x'
93
+ end
94
+
95
+ def singular?(list)
96
+ list.size == 1
97
+ end
98
+ end
@@ -0,0 +1,8 @@
1
+ require 'revamp'
2
+
3
+ # This class implements slugification of Puppet module name: 'puppetlabs/stdlib' <-> 'puppetlabs-stdlib'
4
+ class Revamp::Mapper::PuppetNameSlugger
5
+ def map(slash_name)
6
+ slash_name.tr('/', '-')
7
+ end
8
+ end