polisher 0.9.1 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 407eada91bec23c5a2cbd22754e8b726be64a761
4
- data.tar.gz: 0de716cd95ae868f6800743752b59a537aedef9f
3
+ metadata.gz: 5357e407b962cb5b7f70b9c9d6ab2b5f99fa5c89
4
+ data.tar.gz: 4c76786d10e7fe1d61fef4a0f7894ff9d136c5f7
5
5
  SHA512:
6
- metadata.gz: ae609d0fd5197edd33fdef131c8d142f6b0ab5667f823232d457c84a1ab68e7cd99c358a582b45de25d2c95c020889cecf6dc5f005e0fa3b66f8a642006b3111
7
- data.tar.gz: 74548b607ed70c04d835ecf254d7bde099b849f2d54471f12ff88f2737270c725e02ea191b242b62da44716e4d2d99687084ea4122252f24972bc826bfdc0d7a
6
+ metadata.gz: 0d3c78d82e8f5e7bcfe74b5880f4081b039405c79bcb4afba9c195cd0a85d50847b7716b11c0866665cb7515377575638fde0f4dfbbf012843efa92e8e349549
7
+ data.tar.gz: 0d7b15ce8b04c18e291811054e41ec2111173899b4c8459d969360140a640c8ab084c35045fa446062b86a6a6cccc56d33c26d4c6dbeb81c21eebc54b4508cd8
@@ -18,24 +18,26 @@ require 'optparse'
18
18
  require 'colored'
19
19
  require 'polisher/gem'
20
20
  require 'polisher/gemfile'
21
+ require 'polisher/core'
21
22
 
22
23
  ##########################################################
23
24
 
24
- conf = {:format => nil,
25
- :gemfile => './Gemfile',
26
- :gemspec => nil,
27
- :gemname => nil,
28
- :groups => [],
29
- :devel_deps => false,
30
- :highlight_missing => false,
31
- :check_fedora => false,
32
- :check_git => false,
33
- :check_koji => false,
34
- :check_rhn => false,
35
- :check_yum => false,
36
- :check_bugzilla => false,
37
- :check_errata => false,
38
- :check_bodhi => false}
25
+ conf = {:format => nil,
26
+ :log_level => :info,
27
+ :gemfile => './Gemfile',
28
+ :gemspec => nil,
29
+ :gemname => nil,
30
+ :prefix => nil,
31
+ :groups => [],
32
+ :devel_deps => false,
33
+ :check_fedora => false,
34
+ :check_git => false,
35
+ :check_koji => false,
36
+ :check_rhn => false,
37
+ :check_yum => false,
38
+ :check_bugzilla => false,
39
+ :check_errata => false,
40
+ :check_bodhi => false}
39
41
 
40
42
  optparse = OptionParser.new do |opts|
41
43
  opts.on('-h', '--help', 'Display this help screen') do
@@ -47,6 +49,10 @@ optparse = OptionParser.new do |opts|
47
49
  conf[:format] = f
48
50
  end
49
51
 
52
+ opts.on("--log-level level", "Log verbosity") do |l|
53
+ conf[:log_level] = l.to_sym
54
+ end
55
+
50
56
  opts.on('--gemfile file', 'Location of the gemfile to parse') do |g|
51
57
  conf[:gemfile] = g
52
58
  end
@@ -63,12 +69,12 @@ optparse = OptionParser.new do |opts|
63
69
  conf[:gemname] = g
64
70
  end
65
71
 
66
- opts.on('--[no-]devel', 'Include development dependencies') do |d|
67
- conf[:devel_deps] = d
72
+ opts.on('-p', '--prefix prefix', 'Prefix to append to gem name') do |p|
73
+ conf[:prefix] = p
68
74
  end
69
75
 
70
- opts.on('-m', '--[no-]missing', 'Highlight missing packages') do |m|
71
- conf[:highlight_missing] = m
76
+ opts.on('--[no-]devel', 'Include development dependencies') do |d|
77
+ conf[:devel_deps] = d
72
78
  end
73
79
 
74
80
  opts.on('-f', '--[no-]fedora', 'Check fedora for packages') do |f|
@@ -80,7 +86,7 @@ optparse = OptionParser.new do |opts|
80
86
  end
81
87
 
82
88
  opts.on('-k', '--koji [url]', 'Check koji for packages') do |k|
83
- conf[:check_koji] = k || 'koji.fedoraproject.org/kojihub'
89
+ conf[:check_koji] = k || true
84
90
  end
85
91
 
86
92
  opts.on('-t', '--koji-tag tag', 'Koji tag to query') do |t|
@@ -122,6 +128,9 @@ if conf[:gemfile].nil? &&
122
128
  end
123
129
  end
124
130
 
131
+ Polisher::Logging.level = conf[:log_level]
132
+ Polisher::Config.set
133
+
125
134
  targets = []
126
135
  targets << Polisher::VersionChecker::GEM_TARGET if conf[:check_gem]
127
136
  targets << Polisher::VersionChecker::KOJI_TARGET if conf[:check_koji]
@@ -132,6 +141,13 @@ targets << Polisher::VersionChecker::BODHI_TARGET if conf[:check_bodhi]
132
141
  targets = Polisher::VersionChecker::ALL_TARGETS if targets.empty?
133
142
  Polisher::VersionChecker.check targets
134
143
 
144
+ if conf[:check_koji]
145
+ require 'polisher/koji'
146
+ Polisher::Koji.koji_url conf[:check_koji] if conf[:koji_url].is_a?(String)
147
+ Polisher::Koji.koji_tag conf[:koji_tag] if conf[:koji_tag]
148
+ Polisher::Koji.package_prefix conf[:prefix] if conf[:prefix]
149
+ end
150
+
135
151
  @format = conf[:format]
136
152
 
137
153
  def format_dep(dep)
@@ -164,6 +180,14 @@ def format_tgt(tgt)
164
180
  end
165
181
  end
166
182
 
183
+ def format_unknown_tgt(tgt)
184
+ if @format.nil?
185
+ "#{tgt.to_s.red.bold}: " + "unknown".yellow
186
+ else
187
+ format_tgt("#{tgt} (unknown)")
188
+ end
189
+ end
190
+
167
191
  def format_tgt_with_versions(tgt, versions)
168
192
  if @format.nil?
169
193
  "#{tgt.to_s.green.bold}: #{versions.join(', ').yellow} "
@@ -199,9 +223,12 @@ def print_dep(tgt, dep, versions)
199
223
  @last_dep = dep
200
224
  end
201
225
 
202
- if versions.nil? || versions.empty? ||
203
- versions.size == 1 && versions[0].nil?
226
+ if versions.blank? || (versions.size == 1 && versions.first.blank?)
204
227
  print format_tgt(tgt)
228
+
229
+ elsif versions.size == 1 && versions.first == :unknown
230
+ print format_unknown_tgt(tgt)
231
+
205
232
  else
206
233
  print format_tgt_with_versions(tgt, versions)
207
234
  end
@@ -211,13 +238,15 @@ print_header
211
238
 
212
239
  if conf[:gemname]
213
240
  gem = Polisher::Gem.retrieve(conf[:gemname])
214
- gem.versions(:recursive => true, :dev_deps => true) do |tgt, dep, versions|
241
+ gem.versions(:recursive => true,
242
+ :dev_deps => conf[:devel_deps]) do |tgt, dep, versions|
215
243
  print_dep(tgt, dep, versions)
216
244
  end
217
245
 
218
246
  elsif conf[:gemspec]
219
247
  gem = Polisher::Gem.from_gemspec(conf[:gemspec])
220
- gem.versions(:recursive => true, :dev_deps => true) do |tgt, dep, versions|
248
+ gem.versions(:recursive => true,
249
+ :dev_deps => conf[:devel_deps]) do |tgt, dep, versions|
221
250
  print_dep(tgt, dep, versions)
222
251
  end
223
252
 
@@ -231,7 +260,8 @@ elsif conf[:gemfile]
231
260
  exit 1
232
261
  end
233
262
 
234
- gemfile.dependency_versions do |tgt, dep, versions|
263
+ gemfile.dependency_versions :recursive => true,
264
+ :dev_deps => conf[:devel_deps] do |tgt, dep, versions|
235
265
  print_dep(tgt, dep, versions)
236
266
  end
237
267
  end
@@ -11,13 +11,11 @@
11
11
  # Copyright (C) 2013-2014 Red Hat, Inc.
12
12
 
13
13
  require 'colored'
14
- require 'curb'
15
- require 'json'
16
14
  require 'optparse'
17
- require 'nokogiri'
18
15
 
19
16
  require 'polisher/git'
20
17
  require 'polisher/gem'
18
+ require 'polisher/core'
21
19
 
22
20
  ORIG_DIR = Dir.pwd
23
21
 
@@ -45,9 +43,18 @@ optparse = OptionParser.new do|opts|
45
43
  end
46
44
  end
47
45
 
48
- optparse.parse!
46
+ optparse.parse!
49
47
 
50
- conf[:gems] += Polisher::Fedora.gems_owned_by(conf[:user]) unless conf[:user].nil?
48
+ Polisher::Config.set
49
+
50
+ unless conf[:user].nil?
51
+ begin
52
+ conf[:gems] += Polisher::Fedora.gems_owned_by(conf[:user])
53
+ rescue
54
+ puts "Could not retrieve gems owned by #{conf[:user]}".red
55
+ exit 1
56
+ end
57
+ end
51
58
 
52
59
  if conf[:gems].empty?
53
60
  puts "must specify a gem name or user name!".red
@@ -61,7 +68,7 @@ Dir.chdir conf[:dir]
61
68
  conf[:gems].each do |gem_name|
62
69
  pkg =
63
70
  begin
64
- Polisher::Git::Pkg.new(:name => gem_name).clone
71
+ Polisher::Git::Pkg.new(:name => gem_name).fetch
65
72
  rescue => e
66
73
  puts "Problem Cloning Package, Skipping: #{e}"
67
74
  next
@@ -71,7 +78,11 @@ conf[:gems].each do |gem_name|
71
78
  pkg.update_to(gem)
72
79
  # TODO append gem dependencies to conf[:gems] list
73
80
 
74
- pkg.build
81
+ begin
82
+ pkg.build
83
+ rescue => e
84
+ puts "Warning: scratch build failed: #{e}".bold.red
85
+ end
75
86
 
76
87
  unless pkg.spec.has_check?
77
88
  puts "Warning: no %check section in spec, "\
@@ -5,18 +5,19 @@
5
5
 
6
6
  # XXX issue w/ retreiving packages from pkgwat causing sporadic issues:
7
7
  # https://github.com/fedora-infra/fedora-packages/issues/55
8
-
9
- # fedora pkgwat provides a frontend to bodhi
10
- require 'pkgwat'
8
+ require 'polisher/component'
11
9
 
12
10
  module Polisher
13
- class Bodhi
14
- def self.versions_for(name, &bl)
15
- versions = Pkgwat.get_updates("rubygem-#{name}", 'all', 'all').
16
- select { |update| update['stable_version'] != 'None' }.
17
- collect { |update| update['stable_version'] }
18
- bl.call(:bodhi, name, versions) unless(bl.nil?)
19
- versions
11
+ # fedora pkgwat provides a frontend to bodhi
12
+ Component.verify("Bodhi", "pkgwat") do
13
+ class Bodhi
14
+ def self.versions_for(name, &bl)
15
+ versions = Pkgwat.get_updates("rubygem-#{name}", 'all', 'all').
16
+ select { |update| update['stable_version'] != 'None' }.
17
+ collect { |update| update['stable_version'] }
18
+ bl.call(:bodhi, name, versions) unless(bl.nil?)
19
+ versions
20
+ end
20
21
  end
21
22
  end
22
23
  end
@@ -0,0 +1,43 @@
1
+ # Polisher Components & Component Helpers
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2014 Red Hat, Inc.
5
+
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+
9
+ module Polisher
10
+ module Component
11
+ class Missing
12
+ def initialize(*args)
13
+ raise "polisher is missing a dependency - cannot instantiate"
14
+ end
15
+
16
+ def method_missing(method_id, *args, &bl)
17
+ raise "polisher is missing a dependency - cannot invoke #{method_id} on #{self}"
18
+ end
19
+ end # class MissingComponent
20
+
21
+ def self.verify(polisher_klass, *dependencies)
22
+ all_required = dependencies.all? do |dep|
23
+ require_dependency(polisher_klass, dep)
24
+ end
25
+
26
+ yield if all_required
27
+ end
28
+
29
+ def self.require_dependency(polisher_klass, dependency)
30
+ require dependency
31
+ true
32
+ rescue LoadError
33
+ klasses = polisher_klass.split("::")
34
+ desired_namespace = Polisher
35
+
36
+ klasses.each do |k|
37
+ desired_namespace.const_set(k, Missing) unless desired_namespace.const_defined?(k)
38
+ desired_namespace = "#{desired_namespace.name}::#{k}".constantize
39
+ end
40
+ warn "Failed to require #{dependency}. Added runtime exception in Polisher::#{polisher_klass}"
41
+ end
42
+ end # module Component
43
+ end # module Polisher
@@ -0,0 +1,32 @@
1
+ # Polisher Config Operations
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ require 'yaml'
7
+ require 'active_support'
8
+ require 'active_support/core_ext'
9
+
10
+ module Polisher
11
+ class Config
12
+ CONF = "#{ENV['HOME']}/.polisher/config"
13
+ TARGETS = [['koji', 'polisher/koji', 'Koji'],
14
+ ['distgit', 'polisher/git/pkg', 'Git::Pkg'],
15
+ ['rpm', 'polisher/rpm/spec', 'RPM::Requirement'],
16
+ ['tags', 'polisher/tag_mapper', 'TagMapper']]
17
+
18
+ def self.opts
19
+ @opts ||= File.exist?(CONF) ? YAML.load_file(CONF) : {}
20
+ end
21
+
22
+ def self.set
23
+ TARGETS.each do |target, req, polisher_class|
24
+ if opts[target]
25
+ require req
26
+ target_class = "Polisher::#{polisher_class}".constantize
27
+ opts[target].each { |k, v| target_class.send(k.intern, v) }
28
+ end
29
+ end
30
+ end
31
+ end # class Config
32
+ end # module Polisher
@@ -3,38 +3,58 @@
3
3
  # Licensed under the MIT license
4
4
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
+ require 'polisher/config'
7
+
6
8
  module ConfHelpers
7
- # Defines a 'config attribute' or attribute on the class
8
- # which this is defined in. Accessors to the single shared
9
- # attribute will be added to the class as well as instances
10
- # of the class. Specify the default value with the attr name
11
- # or via an env variable
12
- #
13
- # @example
14
- # class Custom
15
- # extend ConfHelpers
16
- # conf_attr :data_dir, '/etc/'
17
- # end
18
- # Custom.data_dir # => '/etc/'
19
- # ENV['POLISHER_DATA_DIR'] = '/usr/'
20
- # Custom.data_dir # => '/usr/'
21
- # Custom.data_dir == Custom.new.data_dir # => true
22
- #
23
- def conf_attr(name, default=nil)
24
- self.send(:define_singleton_method, name) do |*args|
25
- nvar = "@#{name}".intern
26
- current = self.instance_variable_get(nvar)
27
- envk = "POLISHER_#{name.to_s.upcase}"
28
- instance_variable_set(nvar, default) unless current
29
- instance_variable_set(nvar, ENV[envk]) if ENV.key?(envk)
30
- # TODO also allow vars to be able to be set from a conf file
31
- self.instance_variable_set(nvar, args.first) unless args.empty?
32
- self.instance_variable_get(nvar)
9
+ module ClassMethods
10
+ # Defines a 'config attribute' or attribute on the class
11
+ # which this is defined in. Accessors to the single shared
12
+ # attribute will be added to the class as well as instances
13
+ # of the class. Specify the default value with the attr name
14
+ # or via an env variable
15
+ #
16
+ # @example
17
+ # class Custom
18
+ # extend ConfHelpers
19
+ # conf_attr :data_dir, '/etc/'
20
+ # end
21
+ # Custom.data_dir # => '/etc/'
22
+ # ENV['POLISHER_DATA_DIR'] = '/usr/'
23
+ # Custom.data_dir # => '/usr/'
24
+ # Custom.data_dir == Custom.new.data_dir # => true
25
+ #
26
+ def conf_attr(name, default=nil)
27
+ self.send(:define_singleton_method, name) do |*args|
28
+ nvar = "@#{name}".intern
29
+ current = self.instance_variable_get(nvar)
30
+ envk = "POLISHER_#{name.to_s.upcase}"
31
+ instance_variable_set(nvar, default) unless current
32
+ instance_variable_set(nvar, ENV[envk]) if ENV.key?(envk)
33
+ # TODO also allow vars to be able to be set from a conf file
34
+ self.instance_variable_set(nvar, args.first) unless args.empty?
35
+ self.instance_variable_get(nvar)
36
+ end
37
+
38
+ self.send(:define_method, name) do
39
+ self.class.send(name)
40
+ end
33
41
  end
34
42
 
35
- self.send(:define_method, name) do
36
- self.class.send(name)
43
+ def cmd_available?(cmd)
44
+ File.exist?(cmd) && File.executable?(cmd)
37
45
  end
46
+
47
+ def require_cmd!(cmd)
48
+ raise "command #{cmd} not available" unless cmd_available?(cmd)
49
+ end # module ClassMethods
50
+ end
51
+
52
+ def self.included(base)
53
+ base.extend(ClassMethods)
54
+ end
55
+
56
+ def require_cmd!(cmd)
57
+ self.class.require_cmd!(cmd)
38
58
  end
39
59
  end
40
60
 
@@ -59,10 +79,10 @@ class String
59
79
  # simply be removed
60
80
  def unrpmize
61
81
  require 'polisher/rpm/spec'
62
- fmm = Polisher::RPM::Spec::FILE_MACRO_MATCHERS
63
- fmr = Polisher::RPM::Spec::FILE_MACRO_REPLACEMENTS
64
- f = fmm.inject(self) { |file, matcher| file.gsub(matcher, '') }
65
- f = fmr.keys.inject(f) { |file, r| file.gsub(Regexp.new(r), fmr[r]) }
82
+ matchers = Polisher::RPM::Spec::FILE_MACRO_MATCHERS
83
+ replacements = Polisher::RPM::Spec::FILE_MACRO_REPLACEMENTS
84
+ f = matchers.inject(self) { |file, matcher| file.gsub(matcher, '') }
85
+ f = replacements.keys.inject(f) { |file, r| file.gsub(Regexp.new(r), replacements[r]) }
66
86
  f
67
87
  end
68
88
 
@@ -70,7 +90,12 @@ class String
70
90
  # with their macro correspondences
71
91
  def rpmize
72
92
  require 'polisher/rpm/spec'
73
- fmr = Polisher::RPM::Spec::FILE_MACRO_REPLACEMENTS.invert
74
- fmr.keys.inject(self) { |file, r| file.gsub(r, fmr[r]) }
93
+ matchers = Polisher::RPM::Spec::FILE_MACRO_MATCHERS
94
+ replacements = Polisher::RPM::Spec::FILE_MACRO_REPLACEMENTS.invert
95
+ f = replacements.keys.inject(self) { |file, r| file.gsub(r, replacements[r]) }
96
+
97
+ special = (matchers + replacements.values).any? { |matcher| f =~ /^#{matcher}.*/ }
98
+ f = special ? f : "%{gem_instdir}/#{f}"
99
+ f
75
100
  end
76
101
  end