Class: Debci::RejectList

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

Instance Method Summary collapse

Constructor Details

#initializeRejectList

Returns a new instance of RejectList.



3
4
5
6
7
# File 'lib/debci/reject_list.rb', line 3

def initialize
  @config_dir = Debci.config.config_dir
  @suite_list = Debci.config.suite_list
  @arch_list = Debci.config.arch_list
end

Instance Method Details

#comment(name, params = {}) ⇒ Object



69
70
71
72
# File 'lib/debci/reject_list.rb', line 69

def comment(name, params = {})
  suite, arch, version = unpack_params(params)
  data.dig(name, suite, arch, version)
end

#dataObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/debci/reject_list.rb', line 80

def data
  @data ||=
    begin
      reject_list_file = File.join(@config_dir, 'reject_list')
      blacklist_file = File.join(@config_dir, 'blacklist')
      unless File.exist?(reject_list_file)
        return {} unless File.exist?(blacklist_file)

        Debci.warn("#{blacklist_file} is deprecated; please rename it to #{reject_list_file}")
        reject_list_file = blacklist_file
      end
      data = {}
      reason = ''
      File.readlines(reject_list_file).each do |line|
        if line =~ /^\s*$/
          true # skip blank lines
        elsif line =~ /^\s*#/
          old_str = %r{(https?://\S*)}
          new_str = '<a href="\1">\1</a>'
          reason << line.sub(/^\s*#\s*/, '').gsub(old_str, new_str)
        else
          pkg, suite, arch, version = line.strip.split

          suite ||= '*'
          arch ||= '*'
          version ||= '*'

          data[pkg] ||= {}
          data[pkg][suite] ||= {}
          data[pkg][suite][arch] ||= {}
          data[pkg][suite][arch][version] = reason
          reason = ''
        end
      end
      data
    end
end

#find_expanding_package_name(name, params) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/debci/reject_list.rb', line 43

def find_expanding_package_name(name, params)
  suite, arch, version = unpack_params(params)
  # Expand package name
  data.keys.select { |k| File.fnmatch(k, name) }.each do |wildcard|
    return true if include?(wildcard, suite: suite, arch: arch, version: version)
  end
  # None of the package name wildcards match
  false
end

#find_expanding_wildcards(name, params) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/debci/reject_list.rb', line 53

def find_expanding_wildcards(name, params)
  suite, arch, version = unpack_params(params)

  if suite == '*'
    return @suite_list.all? do |s|
      include?(name, suite: s, arch: arch, version: version)
    end
  end

  return unless arch == '*'

  @arch_list.all? do |a|
    include?(name, suite: suite, arch: a, version: version)
  end
end

#include?(name, params = {}) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/debci/reject_list.rb', line 16

def include?(name, params = {})
  name = String(name)
  suite, arch, version = unpack_params(params)

  return find_expanding_package_name(name, params) unless data.key?(name)

  if data[name].key?(suite)
    nil
  elsif data[name].key?('*')
    suite = '*'
  else
    return find_expanding_wildcards(name, params)
  end

  if data[name][suite].key?(arch)
    nil
  elsif data[name][suite].key?('*')
    arch = '*'
  else
    return find_expanding_wildcards(name, params)
  end

  return true if [version, '*'].include?(data[name][suite][arch].keys.first)

  find_expanding_wildcards(name, params)
end

#packagesObject



74
75
76
77
78
# File 'lib/debci/reject_list.rb', line 74

def packages
  # A package is rejectlisted only if it is rejectlisted for all suites,
  # architectures and versions.
  @packages ||= data.keys.select { |key| !key.include?("*") && include?(key) }
end

#unpack_params(params) ⇒ Object



9
10
11
12
13
14
# File 'lib/debci/reject_list.rb', line 9

def unpack_params(params)
  suite = params[:suite] || '*'
  arch = params[:arch] || '*'
  version = params[:version] || '*'
  [suite, arch, version]
end