polisher 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/README +243 -0
  2. data/app/controllers/application_controller.rb +12 -0
  3. data/app/controllers/callback_controller.rb +47 -0
  4. data/app/controllers/manage_controller.rb +112 -0
  5. data/app/helpers/application_helper.rb +3 -0
  6. data/app/models/artifact.rb +21 -0
  7. data/app/models/event_handler.rb +61 -0
  8. data/app/models/gem_search_criteria.rb +24 -0
  9. data/app/models/gem_source.rb +43 -0
  10. data/app/models/managed_gem.rb +47 -0
  11. data/app/views/callback/gem_updated.rhtml +0 -0
  12. data/app/views/layouts/_header.rhtml +8 -0
  13. data/app/views/layouts/index.rhtml +27 -0
  14. data/app/views/manage/create_event_handler.rhtml +15 -0
  15. data/app/views/manage/create_gem.rhtml +15 -0
  16. data/app/views/manage/create_gem_source.rhtml +15 -0
  17. data/app/views/manage/delete_event_handler.rhtml +15 -0
  18. data/app/views/manage/delete_gem.rhtml +15 -0
  19. data/app/views/manage/delete_gem_source.rhtml +15 -0
  20. data/app/views/manage/list.rhtml +66 -0
  21. data/app/views/manage/new_event_handler.rhtml +38 -0
  22. data/app/views/manage/new_gem.rhtml +21 -0
  23. data/app/views/manage/new_gem_search_criteria.rhtml +3 -0
  24. data/app/views/manage/new_gem_source.rhtml +10 -0
  25. data/config/boot.rb +110 -0
  26. data/config/database.yml +48 -0
  27. data/config/environment.rb +44 -0
  28. data/config/environments/development.rb +17 -0
  29. data/config/environments/production.rb +28 -0
  30. data/config/environments/test.rb +28 -0
  31. data/config/initializers/backtrace_silencers.rb +7 -0
  32. data/config/initializers/inflections.rb +10 -0
  33. data/config/initializers/mime_types.rb +5 -0
  34. data/config/initializers/new_rails_defaults.rb +21 -0
  35. data/config/initializers/session_store.rb +15 -0
  36. data/config/locales/en.yml +5 -0
  37. data/config/polisher.yml +10 -0
  38. data/config/routes.rb +44 -0
  39. data/db/migrate/001_create_gem_sources.rb +34 -0
  40. data/db/migrate/002_create_managed_gems.rb +32 -0
  41. data/db/migrate/003_create_gem_search_criterias.rb +33 -0
  42. data/db/migrate/004_create_event_handlers.rb +32 -0
  43. data/db/migrate/005_create_artifacts.rb +32 -0
  44. data/db/schema.rb +42 -0
  45. data/db/seeds.rb +7 -0
  46. data/lib/email_adapter.rb +46 -0
  47. data/lib/gem2rpm.rb +189 -0
  48. data/lib/gem_api_adapter.rb +87 -0
  49. data/lib/rpm_adapter.rb +39 -0
  50. data/public/404.html +30 -0
  51. data/public/422.html +30 -0
  52. data/public/500.html +30 -0
  53. data/public/dispatch.cgi +10 -0
  54. data/public/dispatch.fcgi +24 -0
  55. data/public/dispatch.rb +29 -0
  56. data/public/favicon.ico +0 -0
  57. data/public/images/rails.png +0 -0
  58. data/public/javascripts/application.js +2 -0
  59. data/public/javascripts/controls.js +963 -0
  60. data/public/javascripts/dragdrop.js +973 -0
  61. data/public/javascripts/effects.js +1128 -0
  62. data/public/javascripts/jquery-1.2.6.min.js +32 -0
  63. data/public/javascripts/prototype.js +4320 -0
  64. data/public/robots.txt +5 -0
  65. data/public/stylesheets/style.css +68 -0
  66. data/script/about +4 -0
  67. data/script/console +3 -0
  68. data/script/dbconsole +3 -0
  69. data/script/destroy +3 -0
  70. data/script/generate +3 -0
  71. data/script/performance/benchmarker +3 -0
  72. data/script/performance/profiler +3 -0
  73. data/script/plugin +3 -0
  74. data/script/runner +3 -0
  75. data/script/server +3 -0
  76. data/tmp/gems/README +1 -0
  77. data/tmp/rpms/README +1 -0
  78. metadata +141 -0
@@ -0,0 +1,42 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of Active Record to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 5) do
13
+
14
+ create_table "artifacts", :force => true do |t|
15
+ t.integer "gem_id"
16
+ t.string "type"
17
+ t.string "location"
18
+ end
19
+
20
+ create_table "event_handlers", :force => true do |t|
21
+ t.integer "managed_gem_id"
22
+ t.string "event"
23
+ t.string "handler"
24
+ end
25
+
26
+ create_table "gem_search_criterias", :force => true do |t|
27
+ t.string "regex"
28
+ t.integer "gem_source_id"
29
+ end
30
+
31
+ create_table "gem_sources", :force => true do |t|
32
+ t.string "name"
33
+ t.string "uri"
34
+ end
35
+
36
+ create_table "managed_gems", :force => true do |t|
37
+ t.string "name"
38
+ t.string "version"
39
+ t.integer "gem_source_id"
40
+ end
41
+
42
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Major.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,46 @@
1
+ # Copyright (C) 2010 Red Hat, Inc.
2
+ # Written by Mohammed Morsi <mmorsi@redhat.com>
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16
+ # MA 02110-1301, USA. A copy of the GNU General Public License is
17
+ # also available at http://www.gnu.org/copyleft/gpl.html.
18
+
19
+ require 'net/smtp'
20
+
21
+ # Adapts an email subsystem to polisher
22
+ class EmailAdapter
23
+ # send email w/ specified args
24
+ def self.send_email(args = {})
25
+ server = args[:server]
26
+ to = args[:to]
27
+ from = args[:from]
28
+ body = args[:body]
29
+ subject = args[:subject]
30
+ logger = args[:logger]
31
+
32
+ logger.info ">> sending email to #{to} from #{from} using smtp server #{server}" unless logger.nil?
33
+ msg = <<END_OF_MESSAGE
34
+ From: #{from}
35
+ To: #{to}
36
+ Subject: #{subject}
37
+
38
+ #{body}
39
+ END_OF_MESSAGE
40
+
41
+ Net::SMTP.start(server) do |smtp|
42
+ smtp.send_message msg, from, to
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,189 @@
1
+ require 'erb'
2
+ require 'socket'
3
+ require 'rubygems/format'
4
+
5
+ # Adapt to the differences between rubygems < 1.0.0 and after
6
+ # Once we can be reasonably certain that everybody has version >= 1.0.0
7
+ # all this logic should be killed
8
+ GEM_VERSION = Gem::Version.create(Gem::RubyGemsVersion)
9
+ HAS_REMOTE_INSTALLER = GEM_VERSION < Gem::Version.create("1.0.0")
10
+
11
+ if HAS_REMOTE_INSTALLER
12
+ require 'rubygems/remote_installer'
13
+ end
14
+
15
+ # Extend String with a word_wrap method, which we use in the ERB template
16
+ # below. Taken with modification from the word_wrap method in ActionPack.
17
+ # Text::Format does the smae thing better.
18
+ class String
19
+ def word_wrap(line_width = 80)
20
+ gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
21
+ end
22
+ end
23
+
24
+ module Gem
25
+ class Requirement
26
+ def rpm_version_transform(version)
27
+ if version == "> 0.0.0"
28
+ version = ""
29
+ end
30
+ version
31
+ end
32
+
33
+ def to_rpm
34
+ result = as_list
35
+ return result.map { |version| rpm_version_transform(version) }
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ module Gem2Rpm
42
+ Gem2Rpm::VERSION = "0.6.0"
43
+
44
+ if HAS_REMOTE_INSTALLER
45
+ def self.find_download_url(name, version)
46
+ installer = Gem::RemoteInstaller.new
47
+ dummy, download_path = installer.find_gem_to_install(name, "=#{version}")
48
+ download_path += "/gems/" if download_path.to_s != ""
49
+ return download_path
50
+ end
51
+ else
52
+ def self.find_download_url(name, version)
53
+ dep = Gem::Dependency.new(name, "=#{version}")
54
+ fetcher = Gem::SpecFetcher.fetcher
55
+ dummy, download_path = fetcher.find_matching(dep, false, false).first
56
+ download_path += "gems/" if download_path.to_s != ""
57
+ return download_path
58
+ end
59
+ end
60
+
61
+ def Gem2Rpm.convert(fname, template=TEMPLATE, out=$stdout,
62
+ nongem=true, local=false)
63
+ format = Gem::Format.from_file_by_path(fname)
64
+ spec = format.spec
65
+ spec.description ||= spec.summary
66
+ download_path = ""
67
+ unless local
68
+ begin
69
+ download_path = find_download_url(spec.name, spec.version)
70
+ rescue Gem::Exception => e
71
+ $stderr.puts "Warning: Could not retrieve full URL for #{spec.name}\nWarning: Edit the specfile and enter the full download URL as 'Source0' manually"
72
+ $stderr.puts "#{e.inspect}"
73
+ end
74
+ end
75
+ template = ERB.new(template, 0, '<>')
76
+ out.puts template.result(binding)
77
+ end
78
+
79
+ # Returns the email address of the packager (i.e., the person running
80
+ # gem2spec). Taken from RPM macros if present, constructed from system
81
+ # username and hostname otherwise.
82
+ def Gem2Rpm.packager()
83
+ packager = `rpm --eval '%{packager}'`.chomp
84
+ if packager == '' or packager == '%{packager}'
85
+ packager = "FIXME"
86
+ #packager = "#{Etc::getpwnam(Etc::getlogin).gecos} <#{Etc::getlogin}@#{Socket::gethostname}>"
87
+ end
88
+ packager
89
+ end
90
+
91
+ TEMPLATE =
92
+ %q{# Generated from <%= File::basename(format.gem_path) %> by gem2rpm -*- rpm-spec -*-
93
+ %define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
94
+ %define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
95
+ %define gemname <%= spec.name %>
96
+ %define geminstdir %{gemdir}/gems/%{gemname}-%{version}
97
+
98
+ Summary: <%= spec.summary.gsub(/\.$/, "") %>
99
+ Name: rubygem-%{gemname}
100
+ Version: <%= spec.version %>
101
+ Release: 1%{?dist}
102
+ Group: Development/Languages
103
+ License: GPLv2+ or Ruby
104
+ URL: <%= spec.homepage %>
105
+ Source0: <%= download_path %>%{gemname}-%{version}.gem
106
+ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
107
+ Requires: rubygems
108
+ <% for d in spec.dependencies %>
109
+ <% for req in d.version_requirements.to_rpm %>
110
+ Requires: rubygem(<%= d.name %>) <%= req %>
111
+ <% end %>
112
+ <% end %>
113
+ BuildRequires: rubygems
114
+ <% if spec.extensions.empty? %>
115
+ BuildArch: noarch
116
+ <% end %>
117
+ Provides: rubygem(%{gemname}) = %{version}
118
+
119
+ %description
120
+ <%= spec.description.to_s.chomp.word_wrap(78) + "\n" %>
121
+
122
+ <% if nongem %>
123
+ %package -n ruby-%{gemname}
124
+ Summary: <%= spec.summary.gsub(/\.$/, "") %>
125
+ Group: Development/Languages
126
+ Requires: rubygem(%{gemname}) = %{version}
127
+ <% spec.files.select{ |f| spec.require_paths.include?(File::dirname(f)) }.reject { |f| f =~ /\.rb$/ }.collect { |f| File::basename(f) }.each do |p| %>
128
+ Provides: ruby(<%= p %>) = %{version}
129
+ <% end %>
130
+ %description -n ruby-%{gemname}
131
+ <%= spec.description.to_s.chomp.word_wrap(78) + "\n" %>
132
+ <% end # if nongem %>
133
+
134
+ %prep
135
+
136
+ %build
137
+
138
+ %install
139
+ rm -rf %{buildroot}
140
+ mkdir -p %{buildroot}%{gemdir}
141
+ <% rdoc_opt = spec.has_rdoc ? "--rdoc " : "" %>
142
+ gem install --local --install-dir %{buildroot}%{gemdir} \
143
+ --force <%= rdoc_opt %>%{SOURCE0}
144
+ <% unless spec.executables.empty? %>
145
+ mkdir -p %{buildroot}/%{_bindir}
146
+ mv %{buildroot}%{gemdir}/bin/* %{buildroot}/%{_bindir}
147
+ rmdir %{buildroot}%{gemdir}/bin
148
+ find %{buildroot}%{geminstdir}/bin -type f | xargs chmod a+x
149
+ <% end %>
150
+ <% if nongem %>
151
+ mkdir -p %{buildroot}%{ruby_sitelib}
152
+ <% spec.files.select{ |f| spec.require_paths.include?(File::dirname(f)) }.each do |p| %>
153
+ ln -s %{gemdir}/gems/%{gemname}-%{version}/<%= p %> %{buildroot}%{ruby_sitelib}
154
+ <% end %>
155
+ <% end # if nongem %>
156
+
157
+ %clean
158
+ rm -rf %{buildroot}
159
+
160
+ %files
161
+ %defattr(-, root, root, -)
162
+ <% for f in spec.executables %>
163
+ %{_bindir}/<%= f %>
164
+ <% end %>
165
+ %{gemdir}/gems/%{gemname}-%{version}/
166
+ <% if spec.has_rdoc %>
167
+ %doc %{gemdir}/doc/%{gemname}-%{version}
168
+ <% end %>
169
+ <% for f in spec.extra_rdoc_files %>
170
+ %doc %{geminstdir}/<%= f %>
171
+ <% end %>
172
+ %{gemdir}/cache/%{gemname}-%{version}.gem
173
+ %{gemdir}/specifications/%{gemname}-%{version}.gemspec
174
+
175
+ <% if nongem %>
176
+ %files -n ruby-%{gemname}
177
+ %defattr(-, root, root, -)
178
+ %{ruby_sitelib}/*
179
+ <% end # if nongem %>
180
+
181
+ %changelog
182
+ * <%= Time.now.strftime("%a %b %d %Y") %> <%= packager %> - <%= spec.version %>-1
183
+ - Initial package
184
+ }
185
+ end
186
+
187
+ # Local Variables:
188
+ # ruby-indent-level: 2
189
+ # End:
@@ -0,0 +1,87 @@
1
+ # Copyright (C) 2010 Red Hat, Inc.
2
+ # Written by Mohammed Morsi <mmorsi@redhat.com>
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16
+ # MA 02110-1301, USA. A copy of the GNU General Public License is
17
+ # also available at http://www.gnu.org/copyleft/gpl.html.
18
+
19
+ require 'uri'
20
+ require 'net/http'
21
+ #require 'net/https'
22
+ require 'json'
23
+
24
+ # Adapts the gem(cutter) api to polisher
25
+ # http://gemcutter.org/pages/api_docs
26
+ class GemApiAdapter
27
+ # retrieve gem information
28
+ def self.gem_info(args = {})
29
+ api_uri = args[:api_uri]
30
+ gem_name = args[:gem_name]
31
+ logger = args[:logger]
32
+
33
+ get_path = "/api/v1/gems/#{gem_name}.json"
34
+
35
+ logger.info ">> getting gem #{gem_name} info from #{api_uri}#{get_path}" unless logger.nil?
36
+ http = Net::HTTP.new(URI.parse(api_uri).host, 80)
37
+ res = http.get(get_path)
38
+ logger.info ">> received #{res.body}"
39
+ JSON.parse(res.body)
40
+ end
41
+
42
+ # use api endpoint/credentials to add subscription for specified gem / url
43
+ def self.subscribe(args = {})
44
+ api_uri = args[:api_uri]
45
+ api_key = args[:api_key]
46
+ gem_name = args[:gem_name]
47
+ callback_url = args[:callback_url]
48
+ logger = args[:logger]
49
+
50
+ subscribe_path = '/api/v1/web_hooks'
51
+
52
+ http = Net::HTTP.new(URI.parse(api_uri).host, 80)
53
+ data = "gem_name=#{gem_name}&url=#{callback_url}"
54
+ headers = { 'Authorization' => api_key }
55
+ logger.info ">> sending http request to #{URI.parse(api_uri).host}#{subscribe_path}; data:#{data}; headers:#{headers}"
56
+ res = http.post(subscribe_path, data, headers)
57
+ # FIXME handle res = #<Net::HTTPNotFound:0x7f1df8319e40> This gem could not be found
58
+ logger.info ">> http response received #{res} #{res.body}"
59
+ end
60
+
61
+ # retrieve gem and save to file
62
+ def self.get_gem(args = {})
63
+ uri = args[:uri]
64
+ gemfile = args[:file]
65
+ logger = args[:logger]
66
+
67
+ # handle redirects
68
+ found = false
69
+ until found # FIXME should impose a max tries
70
+ gem_uri = URI.parse(uri)
71
+ http = Net::HTTP.new(gem_uri.host, 80)
72
+ res = http.get(gem_uri.path)
73
+ if res.code == "200"
74
+ File.open(gemfile, "wb") { |f| f.write res.body }
75
+ found = true
76
+ else
77
+ uri = res.header['location']
78
+ end
79
+ end
80
+ end
81
+
82
+ # helper, convert gem uri to source uri
83
+ def self.gem_to_source_uri(gem_uri)
84
+ uri = URI.parse(gem_uri)
85
+ return uri.scheme + "://" + uri.host
86
+ end
87
+ end
@@ -0,0 +1,39 @@
1
+ # Copyright (C) 2010 Red Hat, Inc.
2
+ # Written by Mohammed Morsi <mmorsi@redhat.com>
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16
+ # MA 02110-1301, USA. A copy of the GNU General Public License is
17
+ # also available at http://www.gnu.org/copyleft/gpl.html.
18
+
19
+ # use gem2rpm to create rpm from gem
20
+ require 'gem2rpm'
21
+
22
+ # Adapts rpm subsystem to polisher
23
+ class RpmAdapter
24
+ # build rpm from specified args
25
+ def self.build(args = {})
26
+ gem = args[:gem]
27
+ logger = args[:logger]
28
+ outfile = "../tmp/rpms/#{gem.name}-#{gem.version}.spec." + Time.now.strftime("%y%m%d%H%M%S")
29
+ outfh = File.open(outfile, "wb")
30
+
31
+ # get gem / write to file
32
+ gemfile = "../tmp/gems/#{gem.name}-#{gem.version}.gem"
33
+ logger.info ">> retreive gem from #{gem.uri} and writing to #{Dir.pwd}/#{gemfile}"
34
+ GemApiAdapter.get_gem :uri => gem.uri, :file => gemfile, :logger => logger
35
+
36
+ logger.info ">> generating rpm spec #{outfile} from gemfile #{gemfile}" unless logger.nil?
37
+ Gem2Rpm::convert gemfile, Gem2Rpm::TEMPLATE, outfh
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>