Class: Machinery::AnalyzeConfigFileDiffsTask
- Defined in:
- lib/analyze_changed_config_files_diffs_task.rb
Overview
Copyright © 2013-2016 SUSE LLC
This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.
To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com
Instance Method Summary collapse
Instance Method Details
#analyze(description) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/analyze_changed_config_files_diffs_task.rb', line 19 def analyze(description) description.assert_scopes("os") check_os(description) Machinery::LocalSystem.validate_existence_of_packages(["zypper"]) description.validate_analysis_compatibility description.assert_scopes( "repositories", "changed_config_files" ) unless description["repositories"].any? { |repo| repo.enabled && !repo.external_medium? } raise Machinery::Errors::AnalysisFailed, "Can not analyze the system description because it does not contain any online repository" end unless description.scope_extracted?("changed_config_files") raise Machinery::Errors::MissingExtractedFiles.new(description, ["changed_config_files"]) end with_repositories(description) do |zypper| file_store = description.scope_file_store("analyze/changed_config_files_diffs") file_store.create diffs_path = file_store.path extracted_files_path = description.scope_file_store("changed_config_files").path Machinery::Ui.puts "Generating diffs..." cnt = 1 list = files_by_package(description) total = list.map(&:files).flatten.length.to_s list.each do |package| path = zypper.download_package("#{package.name}-#{package.version}") if !path || path.empty? Machinery::Ui.warn "Warning: Could not download package #{package.name}-#{package.version}." cnt += package.files.length next end package.files.each do |file| diff = Machinery::Rpm.new(path).diff(file, File.join(extracted_files_path, file)) if !diff || diff.empty? Machinery::Ui.warn "Warning: Could not generate diff for #{file}." else diff_path = File.join(diffs_path, file + ".diff") FileUtils.mkdir_p(File.dirname(diff_path)) File.write(diff_path, diff) Machinery::Ui.puts "[#{cnt.to_s.rjust(total.length)}/#{total}] #{file}" end cnt += 1 end end Machinery::Ui.puts "done" end end |