Class: Autoproj::OSRepositoryResolver

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

Overview

Manager for OS repository provided by package sets

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defs = [], file = nil, operating_system: nil) ⇒ OSRepositoryResolver

Returns a new instance of OSRepositoryResolver.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/autoproj/os_repository_resolver.rb', line 36

def initialize(defs = [], file = nil, operating_system: nil)
    @operating_system = operating_system
    @all_definitions = Set.new
    if file
        defs.each do |def_|
            all_definitions << [[file], def_]
        end
    else
        defs.each do |def_|
            all_definitions << [[], def_]
        end
    end
end

Instance Attribute Details

#all_definitionsObject (readonly)

All the information contained in all the OSrepos files



8
9
10
# File 'lib/autoproj/os_repository_resolver.rb', line 8

def all_definitions
  @all_definitions
end

#operating_systemObject

The operating system



11
12
13
# File 'lib/autoproj/os_repository_resolver.rb', line 11

def operating_system
  @operating_system
end

Class Method Details

.load(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/autoproj/os_repository_resolver.rb', line 13

def self.load(file)
    unless File.file?(file)
        raise ArgumentError, "no such file or directory: #{file}"
    end

    error_t = if defined? Psych::SyntaxError
                  [ArgumentError, Psych::SyntaxError]
              else
                  ArgumentError
              end

    result = new
    file = File.expand_path(file)
    begin
        data = YAML.safe_load(File.read(file)) || {}
        verify_definitions(data)
    rescue *error_t => e
        raise ConfigError.new, "error in #{file}: #{e.message}", e.backtrace
    end
    result.merge(new(data, file))
    result
end

.verify_definitions(array, path = []) ⇒ Object

OS repos definitions must follow the format:

  • distribution:

    • release:

      • key1: value1 key2: value2

The key, value pairs are OS dependent, and will be verified/parsed by the corresponding ‘repository manager’. Thus, for a debian-like distribution one would have something like:



97
98
99
100
101
102
103
# File 'lib/autoproj/os_repository_resolver.rb', line 97

def self.verify_definitions(array, path = [])
    verify_type(array, Array, path)
    array.each do |entry|
        verify_type(entry, Hash, path)
        verify_os(entry, (path + [entry]))
    end
end

.verify_entries(array, path = []) ⇒ Object



125
126
127
128
129
130
# File 'lib/autoproj/os_repository_resolver.rb', line 125

def self.verify_entries(array, path = [])
    verify_type(array, Array, path)
    array.each do |entry|
        verify_type(entry, Hash, path)
    end
end

.verify_os(hash, path = []) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/autoproj/os_repository_resolver.rb', line 105

def self.verify_os(hash, path = [])
    verify_type(hash, Hash, path)
    hash.each do |key, value|
        verify_type(key, String, path)
        verify_release(value, (path + [value]))
    end
end

.verify_release(array, path = []) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/autoproj/os_repository_resolver.rb', line 113

def self.verify_release(array, path = [])
    verify_type(array, Array, path)
    array.each do |releases|
        verify_type(releases, Hash, path)

        releases.values.each do |entries|
            verify_type(entries, Array, path)
            verify_entries(entries, path + entries)
        end
    end
end

.verify_type(obj, type, path = []) ⇒ Object

Raises:

  • (ArgumentError)


132
133
134
135
136
137
# File 'lib/autoproj/os_repository_resolver.rb', line 132

def self.verify_type(obj, type, path = [])
    return if obj.is_a?(type)

    raise ArgumentError, "invalid osrepos definition in #{path.join('/')}: "\
                         "expected a #{type}, found a #{obj.class}"
end

Instance Method Details

#all_entriesObject



58
59
60
61
62
63
64
# File 'lib/autoproj/os_repository_resolver.rb', line 58

def all_entries
    definitions.map do |distribution|
        distribution.values.map do |release|
            release.map(&:values)
        end
    end.flatten.uniq
end

#definitionsObject



54
55
56
# File 'lib/autoproj/os_repository_resolver.rb', line 54

def definitions
    all_definitions.map(&:last).uniq
end

#entry_matches?(entry, identifiers) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/autoproj/os_repository_resolver.rb', line 66

def entry_matches?(entry, identifiers)
    !(entry.keys.first.split(",").map(&:strip) & identifiers).empty?
end

#merge(info) ⇒ Object



50
51
52
# File 'lib/autoproj/os_repository_resolver.rb', line 50

def merge(info)
    @all_definitions += info.all_definitions
end

#resolved_entriesObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/autoproj/os_repository_resolver.rb', line 70

def resolved_entries
    os_name, os_version = operating_system
    os_version << "default" unless os_version.include?("default")

    distribution_filtered = definitions.select do |entry|
        entry_matches?(entry, os_name)
    end.map(&:values).flatten

    release_filtered = distribution_filtered.select { |entry| entry_matches?(entry, os_version) }
    release_filtered.map(&:values).flatten.uniq
end