blob: 5558d47131400ddf4b4fd355c2f938d526098c99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
|
class UseflagsUpdateJob < ApplicationJob
queue_as :default
def perform(*args)
repo = Portage::Repository::Model.new KKULEOMI_PORTDIR
update_global repo
update_use_expand repo
end
def update_global(repo)
model_flags = repo.global_useflags
index_flags = UseflagRepository.global
new_flags = model_flags.keys - index_flags.keys
del_flags = index_flags.keys - model_flags.keys
eql_flags = model_flags.keys & index_flags.keys
new_flags.each do |flag|
flag_doc = Useflag.new
flag_doc.name = flag
flag_doc.description = model_flags[flag]
flag_doc.scope = 'global'
UseflagRepository.save(flag_doc)
end
eql_flags.each do |flag|
unless index_flags[flag].description == model_flags[flag]
index_flags[flag].description = model_flags[flag]
UseflagRepository.save(index_flags[flag])
end
end
del_flags.each do |flag|
UseflagRepository.delete(index_flags[flag])
end
end
def update_use_expand(repo)
model_flags = repo.use_expand_flags
index_flags = UseflagRepository.use_expand
# Calculate keys only once
index_flag_keys = index_flags.keys
# Record processed flags to find deletion candidates
flag_status = Hash[index_flag_keys.map {|key| [key, false] }]
model_flags.each_pair do |variable, values_hsh|
values_hsh.each_pair do |flag, desc|
_flag = '%s_%s' % [variable, flag]
flag_status[_flag] = true
# Already present ones
if index_flag_keys.include? _flag
unless index_flags[_flag].description == desc
index_flags[_flag].description = desc
UseflagRepository.save(index_flags[_flag])
end
else
# New flag
flag_doc = Useflag.new
flag_doc.name = _flag
flag_doc.description = desc
flag_doc.scope = 'use_expand'
flag_doc.use_expand_prefix = variable
UseflagRepository.save(flag_doc)
end
end
end
# Find and process removed flags
flag_status.each_pair do |flag, status|
UseflagRepository.delete(index_flags[flag]) unless status
end
end
end
|