commit d9d66926997b7e5dcdcf5ccbe75d7b7fb054ab9a
Author: Dominic Cleal <dcleal@redhat.com>
Date:   Tue Dec 2 08:28:43 2014 +0000

    Conversion script

diff --git a/tfm/scl_prefix_update.conf b/tfm/scl_prefix_update.conf
new file mode 100644
index 000000000..28a52fe83
--- /dev/null
+++ b/tfm/scl_prefix_update.conf
@@ -0,0 +1,281 @@
+rubygem-%{gem_name}=scl_prefix
+rubygem(%{gem_name})=scl_prefix
+rubygem-%{gemname}=scl_prefix
+rubygem(%{gemname})=scl_prefix
+ruby-%{gem_name}=scl_prefix
+ruby(%{gem_name})=scl_prefix
+ruby-%{gemname}=scl_prefix
+ruby(%{gemname})=scl_prefix
+%{pkg_name}=scl_prefix
+irb=scl_prefix_ruby
+ruby-irb=scl_prefix_ruby
+ruby=scl_prefix_ruby
+}ruby=scl_prefix_ruby
+ruby}=scl_prefix_ruby
+rake}=scl_prefix_ruby
+rails}=scl_prefix_ruby
+ruby}=scl_prefix_ruby
+ruby-devel=scl_prefix_ruby
+ruby(release)=scl_prefix_ruby
+ruby(rubygems)=scl_prefix_ruby
+ruby(abi)=scl_prefix_ruby
+rubygems=scl_prefix_ruby
+rubygems-devel=scl_prefix_ruby
+actionmailer=scl_prefix_ruby
+actionpack=scl_prefix_ruby
+activemodel=scl_prefix_ruby
+activerecord=scl_prefix_ruby
+activeresource=scl_prefix_ruby
+activesupport=scl_prefix_ruby
+arel=scl_prefix_ruby
+bacon=scl_prefix_ruby
+bcrypt-ruby=scl_prefix_ruby
+bigdecimal=scl_prefix_ruby
+bigdecimal=scl_prefix_ruby
+bson=scl_prefix_ruby
+bson_ext=scl_prefix_ruby
+builder=scl_prefix_ruby
+bundler=scl_prefix_ruby
+coffee-rails=scl_prefix_ruby
+coffee-script=scl_prefix_ruby
+coffee-script-source=scl_prefix_ruby
+diff-lcs=scl_prefix_ruby
+erubis=scl_prefix_ruby
+execjs=scl_prefix_ruby
+fakeweb=scl_prefix_ruby
+hike=scl_prefix_ruby
+http_connection=scl_prefix_ruby
+i18n=scl_prefix_ruby
+introspection=scl_prefix_ruby
+io-console=scl_prefix_ruby
+io-console=scl_prefix_ruby
+journey=scl_prefix_ruby
+jquery-rails=scl_prefix_ruby
+json=scl_prefix_ruby
+json=scl_prefix_ruby
+mail=scl_prefix_ruby
+metaclass=scl_prefix_ruby
+mime-types=scl_prefix_ruby
+minitest=scl_prefix_ruby
+minitest=scl_prefix_ruby
+mocha=scl_prefix_ruby
+mongo=scl_prefix_ruby
+multi_json=scl_prefix_ruby
+net-http-persistent=scl_prefix_ruby
+passenger40=scl_prefix_ruby
+passenger40-devel=scl_prefix_ruby
+passenger40-native=scl_prefix_ruby
+passenger40-native-libs=scl_prefix_ruby
+polyglot=scl_prefix_ruby
+rack=scl_prefix_ruby
+rack-cache=scl_prefix_ruby
+rack-protection=scl_prefix_ruby
+rack-ssl=scl_prefix_ruby
+rack-test=scl_prefix_ruby
+rails=scl_prefix_ruby
+railties=scl_prefix_ruby
+rake=scl_prefix_ruby
+rake=scl_prefix_ruby
+rdoc=scl_prefix_ruby
+rdoc=scl_prefix_ruby
+ref=scl_prefix_ruby
+rspec=scl_prefix_ruby
+rspec-core=scl_prefix_ruby
+rspec-expectations=scl_prefix_ruby
+rspec-mocks=scl_prefix_ruby
+sass=scl_prefix_ruby
+sass-rails=scl_prefix_ruby
+sinatra=scl_prefix_ruby
+sprockets=scl_prefix_ruby
+sqlite3=scl_prefix_ruby
+test_declarative=scl_prefix_ruby
+therubyracer=scl_prefix_ruby
+thor=scl_prefix_ruby
+tilt=scl_prefix_ruby
+treetop=scl_prefix_ruby
+tzinfo=scl_prefix_ruby
+uglifier=scl_prefix_ruby
+ZenTest=scl_prefix_ruby
+facter=scl_prefix
+mod_passenger=scl_prefix
+ruby-wrapper=scl_prefix
+addressable=scl_prefix
+ancestry=scl_prefix
+apipie-bindings=scl_prefix
+apipie-rails=scl_prefix
+audited-activerecord=scl_prefix
+audited=scl_prefix
+autoparse=scl_prefix
+awesome_print=scl_prefix
+bootstrap-sass=scl_prefix
+bundler_ext=scl_prefix
+daemons=scl_prefix
+deep_cloneable=scl_prefix
+eventmachine=scl_prefix
+excon=scl_prefix
+extlib=scl_prefix
+faraday=scl_prefix
+fast_gettext=scl_prefix
+ffi=scl_prefix
+flot-rails=scl_prefix
+fog=scl_prefix
+fog-core=scl_prefix
+fog-json=scl_prefix
+fog-xml=scl_prefix
+foreigner=scl_prefix
+foremancli=scl_prefix
+formatador=scl_prefix
+friendly_id=scl_prefix
+gettext=scl_prefix
+gettext_i18n_rails=scl_prefix
+gettext_i18n_rails_js=scl_prefix
+google-api-client=scl_prefix
+gridster-rails=scl_prefix
+gssapi=scl_prefix
+highline=scl_prefix
+hirb-unicode=scl_prefix
+hirb=scl_prefix
+i18n_data=scl_prefix
+ipaddress=scl_prefix
+jquery_pwstrength_bootstrap=scl_prefix
+jquery-ui-rails=scl_prefix
+jquery-turbolinks=scl_prefix
+jwt=scl_prefix
+kafo=scl_prefix
+launchy=scl_prefix
+ldap_fluff=scl_prefix
+levenshtein=scl_prefix
+libv8=scl_prefix
+locale=scl_prefix
+maruku=scl_prefix
+multi_json=scl_prefix
+multipart-post=scl_prefix
+multi-select-rails=scl_prefix
+mysql2=scl_prefix
+netrc=scl_prefix
+net-ldap=scl_prefix
+net-scp=scl_prefix
+net-ssh=scl_prefix
+nokogiri=scl_prefix
+oauth=scl_prefix
+paint=scl_prefix
+passenger-native-libs=scl_prefix
+passenger-native=scl_prefix
+passenger=scl_prefix
+pg=scl_prefix
+po_to_json=scl_prefix
+puppet=scl_prefix
+quiet_assets=scl_prefix
+rabl=scl_prefix
+rack-mini-profiler=scl_prefix
+rack-jsonp=scl_prefix
+rbovirt=scl_prefix
+rbvmomi=scl_prefix
+rdoc4=scl_prefix
+rest-client=scl_prefix
+retriable=scl_prefix
+rkerberos=scl_prefix
+rr=scl_prefix
+rspec-rails=scl_prefix
+ruby-libvirt=scl_prefix
+ruby2ruby=scl_prefix
+rubyipmi=scl_prefix
+ruby_parser=scl_prefix
+safemode=scl_prefix
+sass=scl_prefix
+scoped_search=scl_prefix
+secure_headers=scl_prefix
+sequel=scl_prefix
+sexp_processor=scl_prefix
+shadow=scl_prefix
+shoulda=scl_prefix
+signet=scl_prefix
+single_test=scl_prefix
+spice-html5-rails=scl_prefix
+sprockets-rails=scl_prefix
+sshkey=scl_prefix
+syntax=scl_prefix
+text=scl_prefix
+trollop=scl_prefix
+turbolinks=scl_prefix
+unf=scl_prefix
+unf_ext=scl_prefix
+unicode-display_width=scl_prefix
+uuidtools=scl_prefix
+validates_lengths_from_database=scl_prefix
+will_paginate=scl_prefix
+wirb=scl_prefix
+algebrick=scl_prefix
+angular-rails-templates=scl_prefix
+apipie-params=scl_prefix
+archive-tar-minitar=scl_prefix
+commonjs=scl_prefix
+dalli=scl_prefix
+deface=scl_prefix
+diffy=scl_prefix
+docker-api=scl_prefix
+dynflow=scl_prefix
+ffi=scl_prefix
+graphite-api=scl_prefix
+jgrep=scl_prefix
+less=scl_prefix
+less-rails=scl_prefix
+little-plugger=scl_prefix
+logging=scl_prefix
+openscap=scl_prefix
+scaptimony=scl_prefix
+opennebula=scl_prefix
+sprockets-rails=scl_prefix
+wicked=scl_prefix
+zscheduler=scl_prefix
+chef-api=scl_prefix
+logify=scl_prefix
+satyr=scl_prefix
+delorean=scl_prefix
+open4=scl_prefix
+shindo=scl_prefix
+foreman-tasks=scl_prefix
+test-unit=scl_prefix
+test-unit-notify=scl_prefix
+test-unit-rr=scl_prefix
+ruby-gettext-package=scl_prefix
+rubyforge=scl_prefix
+flexmock=scl_prefix
+json_pure=scl_prefix
+okjson)=scl_prefix
+ruby-net-ldap=scl_prefix
+ruby(racc)=scl_prefix
+daemon_controller=scl_prefix
+ruby(postgres)=scl_prefix
+ansi=scl_prefix
+hashie=scl_prefix
+rake-compiler=scl_prefix
+dbi-dbrc=scl_prefix
+session=scl_prefix
+ammeter=scl_prefix
+cucumber=scl_prefix
+aruba=scl_prefix
+jeweler=scl_prefix
+eco=scl_prefix
+ejs=scl_prefix
+foreman_discovery=scl_prefix
+%gem_minitest=scl_prefix_ruby
+hoe=scl_prefix
+git=scl_prefix
+fog-aws=scl_prefix
+rails-i18n=scl_prefix
+select2-rails=scl_prefix
+hammer_cli=scl_prefix
+hammer_cli_foreman=scl_prefix
+fog-libvirt=scl_prefix
+fog-google=scl_prefix
+concurrent-ruby=scl_prefix
+concurrent-ruby-edge=scl_prefix
+net-ssh-gateway=scl_prefix
+net-ssh-multi=scl_prefix
+powerbar=scl_prefix
+clamp=scl_prefix
+rb-readline=scl_prefix
+table_print=scl_prefix
+fastercsv=scl_prefix
+underscore-rails=scl_prefix
diff --git a/tfm/scl_prefix_update.rb b/tfm/scl_prefix_update.rb
new file mode 100644
index 000000000..b7983848e
--- /dev/null
+++ b/tfm/scl_prefix_update.rb
@@ -0,0 +1,65 @@
+#!/usr/bin/env ruby
+#
+# Converts %{?scl_prefix}rubygem-foo in a load of spec files to use a different scl_prefix variant
+# Used when moving from a single SCL to multiple, as it's configurable for different packages to
+# have different scl_prefixes.
+
+def lookup_table
+  return @table if @table
+  @table = {}
+  File.read(File.expand_path('scl_prefix_update.conf', File.dirname(__FILE__))).each_line do |l|
+    k,v = l.chomp.split('=')
+    @table[k] = v
+  end
+  @table
+end
+
+def lookup(string)
+  return lookup_table[string] if lookup_table.has_key?(string)
+  if string =~ /\Arubygem[(-]([\w-]+)\)?\z/
+    return lookup_table[$1] if lookup_table.has_key?($1)
+  end
+  raise("unknown #{string}")
+end
+
+def replace(file)
+  file.gsub(/(%{\??)scl_prefix}([\w%{}()-]+)/) { |m| "#{$1}#{lookup($2)}}#{$2}" }
+end
+
+def add_obsoletes(file, filename)
+  old_names = `rpm --define 'scl ruby193' --qf '%{name}\n' -q --specfile #{filename}`.split($/)
+  old_name = old_names.first
+  old_name = $1.gsub(/%{\??scl_prefix}/, 'ruby193-') if file =~ /^Name:\s*(.+?)\s*$/
+  if old_name.include?('ruby193')
+    lines = file.split($/)
+
+    # insert Obsoletes after last Provides in main package
+    first_package = lines.index { |l| l.start_with? '%package' } || -1
+    last_provides = lines[0..first_package].rindex { |l| l.start_with? 'Provides:' }
+    last_provides = lines[0..first_package].rindex { |l| l.start_with? 'Requires:' } unless last_provides
+    lines.insert last_provides+1, "%{?scl:Obsoletes: #{old_name}}"
+
+    # insert Obsoletes for -doc subpackages
+    doc_package = lines.index { |l| l =~ /\A%package\s+.*doc/ }
+    if doc_package
+      next_section = lines[doc_package+1..-1].index { |l| l.start_with? '%' }
+      last_requires = lines[doc_package, next_section].rindex { |l| l =~ /\A(Requires|Provides)/ }
+      last_requires = lines[doc_package, next_section].rindex { |l| l =~ /\A[A-Z]/ } unless last_requires
+      lines.insert doc_package+last_requires+1, "%{?scl:Obsoletes: #{old_name}-doc}"
+    end
+
+    file = lines.join($/) + $/
+  end
+  file
+end
+
+raise 'Usage: scl_prefix_update.rb FILE..' if ARGV.empty?
+
+ARGV.each do |a|
+  begin
+    File.write(a, add_obsoletes(replace(File.read(a)), a))
+  rescue => e
+    puts "parsing #{a}"
+    raise e
+  end
+end
