Class: AnalyzeConfigFileDiffsTask

Inherits:
Object
  • Object
show all
Defined in:
lib/analyze_config_file_diffs_task.rb

Overview

Copyright © 2013-2015 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
# File 'lib/analyze_config_file_diffs_task.rb', line 19

def analyze(description)
  description.assert_scopes("os")
  description.validate_analysis_compatibility
  description.assert_scopes(
    "repositories",
    "config_files"
  )
  if !description.scope_extracted?("config_files")
    raise Machinery::Errors::MissingExtractedFiles.new(description, ["config_files"])
  end

  with_repositories(description) do |zypper|
    file_store = description.scope_file_store("analyze/config_file_diffs")
    file_store.create
    diffs_path = file_store.path
    extracted_files_path = description.scope_file_store("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 = 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