* remove the old developer page and show developer2 there
[opensuse:software-o-o.git] / app / controllers / main_controller.rb
1 require 'net/http'
2 require 'gettext_rails'
3
4 class MainController < ApplicationController
5
6   verify :only => :ymp, :params => [:project, :repository, :arch, :binary],
7     :redirect_to => :index
8
9   # these pages are completely static:
10   caches_page :index, :developer, :developer_download_js
11
12   def old_dist
13     dist = params[:dist]
14     begin
15       render :template => "main/old_#{dist}.rhtml"
16     rescue Object
17       @message = "No old page found for dist #{dist}"
18       render :template => "error", :status => 404
19     end
20   end
21
22   def ymp_with_arch_and_version
23     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:arch]}/#{params[:binary]}?view=ymp"
24     res = get_from_api(path)
25     render :text => res.body, :content_type => res.content_type
26   end
27
28   def ymp_without_arch_and_version
29     path = "/published/#{params[:project]}/#{params[:repository]}/#{params[:package]}?view=ymp"
30     res = get_from_api(path)
31     render :text => res.body, :content_type => res.content_type
32   end
33
34   def index
35     GetText.locale = "en"
36     render :template => "main/index"
37   end
38
39   def set_developer
40     @isos = {}
41     @directory = "http://download.opensuse.org/distribution/11.2-RC2"
42     @isos["lang-32"] = "Addon-Lang-Build0339-i586"
43     @isos["lang-64"] = "Addon-Lang-Build0339-x86_64"
44     @isos["nonoss"] = "Addon-NonOss-BiArch-Build0339-i586-x86_64"
45     @isos["kde-64"] = "KDE4-LiveCD-Build0339-x86_64"
46     @isos["kde-32"] = "KDE4-LiveCD-Build0339-i686"
47     @isos["gnome-64"] = "GNOME-LiveCD-Build0339-x86_64"
48     @isos["gnome-32"] = "GNOME-LiveCD-Build0339-i686"
49     @isos["dvd-64"] = "DVD-Build0339-x86_64"
50     @isos["dvd-32"] = "DVD-Build0339-i586"
51     @isos["net-32"] = "NET-Build0339-i586"
52     @isos["net-64"] = "NET-Build0339-x86_64"
53
54     @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
55     @releasename = "openSUSE 11.2-RC2"
56     @repourl = "http://download.opensuse.org/distribution/11.2"
57     @medium = "dvd"
58   end
59
60   def developer
61     
62     if params[:lang].nil?
63       lang = request.compatible_language_from(LANGUAGES) || "en"
64       redirect_to "/developer/" + lang
65       return
66     else
67       @lang = params[:lang][0]
68     end
69     GetText.locale = @lang
70
71     set_developer
72     render :template => "main/developer2"
73   end
74
75   def change_developer_install
76     set_developer
77     @medium = params[:medium]
78     render :template => "main/developer2"
79   end
80
81   def developer_download_js
82     set_developer
83     render :template => "main/download", :content_type => 'text/javascript', :layout => false
84   end
85
86   def download
87     if params[:release] == "developer"
88       set_developer
89     end
90  
91     medium = params[:medium]
92
93     if params[:arch] == "i686"
94       medium += "-32"
95     else
96       medium += "-64"
97     end
98
99     suffix = ".iso"
100     
101     case
102     when params[:protocol] == "torrent"
103       suffix = ".iso.torrent"
104     when params[:protocol] == "mirror"
105       suffix = ".iso?mirrorlist"
106     when params[:protocol] == "metalink"
107       suffix = ".iso.metalink"
108     end
109     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
110
111   end
112
113   private
114   
115   def get_from_api(path)
116     req = Net::HTTP::Get.new(path)
117     req['x-username'] = "obs_read_only"
118
119     host, port = API_HOST.split(/:/)
120     port ||= 80
121     res = Net::HTTP.new(host, port).start do |http|
122       http.request(req)
123     end
124   end
125 end