lib/server.rb in machinery-tool-1.18.0 vs lib/server.rb in machinery-tool-1.19.0
- old
+ new
@@ -48,11 +48,11 @@
def render_scope(scope)
render_partial scope, scope => @description[scope]
end
def scope_meta_info(scope)
- return "" if !@description[scope]
+ return "" unless @description[scope]
" (" \
"inspected host: '#{@description[scope].meta.hostname}', " \
"at: #{DateTime.parse(@description[scope].meta.modified).strftime("%F %T")})"
end
@@ -227,10 +227,11 @@
use Rack::TryStatic,
root: File.join(Machinery::ROOT, "manual"),
urls: %w[/site],
try: ["index.html"]
+ enable :sessions
get "/descriptions/:id/files/:scope/*" do
description = SystemDescription.load(params[:id], settings.system_description_store)
filename = File.join("/", params["splat"].first)
@@ -249,10 +250,11 @@
content
end
get "/" do
+ check_session_for_error
descriptions = settings.system_description_store.list
@all_descriptions = Hash.new
descriptions.each do |name|
scopes = []
@@ -296,15 +298,15 @@
if @description_a[scope] && @description_b[scope]
@diff[scope] = Comparison.compare_scope(@description_a, @description_b, scope)
elsif @description_a[scope] || @description_b[scope]
@meta[:uninspected] ||= Hash.new
- if !@description_a[scope]
+ unless @description_a[scope]
@meta[:uninspected][@description_a.name] ||= Array.new
@meta[:uninspected][@description_a.name] << scope
end
- if !@description_b[scope]
+ unless @description_b[scope]
@meta[:uninspected][@description_b.name] ||= Array.new
@meta[:uninspected][@description_b.name] << scope
end
end
end
@@ -326,19 +328,37 @@
diff.to_s(:html)
end
get "/:id" do
- @description = SystemDescription.load(params[:id], settings.system_description_store)
-
- diffs_dir = @description.scope_file_store("analyze/config_file_diffs").path
- if @description.config_files && diffs_dir
- # Enrich description with the config file diffs
- @description.config_files.each do |file|
- path = File.join(diffs_dir, file.name + ".diff")
- file.diff = diff_to_object(File.read(path)) if File.exists?(path)
+ begin
+ @description = SystemDescription.load(params[:id], settings.system_description_store)
+ rescue Machinery::Errors::SystemDescriptionNotFound => e
+ session[:error] = e.to_s
+ redirect "/"
+ rescue Machinery::Errors::SystemDescriptionIncompatible => e
+ @error = e
+ haml File.read(File.join(Machinery::ROOT, "html/upgrade.html.haml"))
+ else
+ diffs_dir = @description.scope_file_store("analyze/changed_config_files_diffs").path
+ if @description.changed_config_files && diffs_dir
+ # Enrich description with the config file diffs
+ @description.changed_config_files.each do |file|
+ path = File.join(diffs_dir, file.name + ".diff")
+ file.diff = diff_to_object(File.read(path)) if File.exist?(path)
+ end
end
+
+ haml File.read(File.join(Machinery::ROOT, "html/index.html.haml"))
end
+ end
- haml File.read(File.join(Machinery::ROOT, "html/index.html.haml"))
+ private
+
+ def check_session_for_error
+ if session[:error]
+ @errors ||= Array.new
+ @errors.push(session[:error])
+ session.clear
+ end
end
end