Class: ListTask

Inherits:
Object
  • Object
show all
Defined in:
lib/list_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

#list(store, options = {}) ⇒ 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
75
76
77
78
79
80
81
82
83
84
# File 'lib/list_task.rb', line 19

def list(store, options = {})
  descriptions = store.list
  has_incompatible_version = false

  descriptions.each do |name|
    begin
      description = SystemDescription.load(name, store, skip_validation: true)
    rescue Machinery::Errors::SystemDescriptionIncompatible => e
      if !e.format_version
        show_error("#{name}: incompatible format version. Can not be upgraded.\n", options)
      elsif e.format_version < SystemDescription::CURRENT_FORMAT_VERSION
        show_error("#{name}: format version #{e.format_version}, " \
          "needs to be upgraded.\n", options)
        has_incompatible_version = true
      else
        show_error("#{name}: format version #{e.format_version}. " \
          "Please upgrade Machinery to the latest version.\n", options)
      end
      next
    rescue Machinery::Errors::SystemDescriptionValidationFailed
      show_error("#{name}: This description is broken. Use " \
        "`#{$0} validate #{name}` to see the error message.\n", options)
      next
    rescue Machinery::Errors::SystemDescriptionError
      show_error("#{name}: This description is broken.\n", options)
      next
    end

    if options[:short]
      Machinery::Ui.puts name
    else
      scopes = []

      description.scopes.each do |scope|
        entry = Machinery::Ui.internal_scope_list_to_string(scope)
        if SystemDescription::EXTRACTABLE_SCOPES.include?(scope)
          if description.scope_extracted?(scope)
            entry += " (extracted)"
          else
            entry += " (not extracted)"
          end
        end

        if options[:verbose]
          meta = description[scope].meta
          if meta
            time = Time.parse(meta.modified).getlocal
            date = time.strftime "%Y-%m-%d %H:%M:%S"
            hostname = meta.hostname
          else
            date = "unknown"
            hostname = "Unknown hostname"
          end
          entry += "\n      Host: [#{hostname}]"
          entry += "\n      Date: (#{date})"
        end

        scopes << entry
      end

      Machinery::Ui.puts " #{name}:\n   * " + scopes .join("\n   * ") + "\n\n"
    end
  end

  Hint.print(:upgrade_system_description) if has_incompatible_version
end