some debug and some XML validation
[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, :developer2, :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 set_developer
35     @isos = {}
36     @directory = "http://download.opensuse.org/distribution/11.2-RC1"
37     @isos["lang-32"] = "Addon-Lang-Build0331-i586"
38     @isos["lang-64"] = "Addon-Lang-Build0332-x86_64"
39     @isos["nonoss"] = "Addon-NonOss-BiArch-Build0335-i586-x86_64"
40     @isos["kde-64"] = "KDE4-LiveCD-Build0336-x86_64"
41     @isos["kde-32"] = "KDE4-LiveCD-Build0336-i686"
42     @isos["gnome-64"] = "GNOME-LiveCD-Build0336-x86_64"
43     @isos["gnome-32"] = "GNOME-LiveCD-Build0336-i686"
44     @isos["dvd-64"] = "DVD-Build0334-x86_64"
45     @isos["dvd-32"] = "DVD-Build0331-i586"
46     @isos["net-32"] = "NET-Build0331-i586"
47     @isos["net-64"] = "NET-Build0331-x86_64"
48
49     @releasenotes = "http://www.suse.de/relnotes/i386/openSUSE/11.2/RELEASE-NOTES.en.html"
50     @releasename = "openSUSE 11.2-RC1"
51     @repourl = "http://download.opensuse.org/distribution/11.2"
52     @medium = "dvd"
53   end
54
55   def developer
56     set_developer
57     render :template => "main/developer"
58   end
59
60   def developer2
61     request.user_preferred_languages.each { |l| puts "user " + l }
62    
63     puts LANGUAGES
64     puts "ready", request.compatible_language_from(LANGUAGES)
65     if params[:lang].nil?
66       lang = request.compatible_language_from(LANGUAGES) || "en"
67       redirect_to "/developer2/" + lang
68       return
69     else
70       @lang = params[:lang][0]
71     end
72     GetText.locale = @lang
73
74     set_developer
75     render :template => "main/developer2"
76   end
77
78   def change_developer_install
79     set_developer
80     @medium = params[:medium]
81     render :template => "main/developer2"
82   end
83
84   def developer_download_js
85     set_developer
86     render :template => "main/download", :content_type => 'text/javascript', :layout => false
87   end
88
89   def download
90     if params[:release] == "developer"
91       set_developer
92     end
93  
94     medium = params[:medium]
95
96     if params[:arch] == "i686"
97       medium += "-32"
98     else
99       medium += "-64"
100     end
101
102     suffix = ".iso"
103     
104     case
105     when params[:protocol] == "torrent"
106       suffix = ".iso.torrent"
107     when params[:protocol] == "mirror"
108       suffix = ".iso?mirrorlist"
109     when params[:protocol] == "metalink"
110       suffix = ".iso.metalink"
111     end
112     redirect_to @directory + "/iso/openSUSE-" + @isos[medium] + suffix
113
114   end
115
116   private
117   
118   def get_from_api(path)
119     req = Net::HTTP::Get.new(path)
120     req['x-username'] = "obs_read_only"
121
122     host, port = API_HOST.split(/:/)
123     port ||= 80
124     res = Net::HTTP.new(host, port).start do |http|
125       http.request(req)
126     end
127   end
128 end