summaryrefslogtreecommitdiff
blob: c0a968bf7e0df349db8c4c36ba4d981f03847d6b (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
#!/usr/bin/env ruby

require 'json'

GLOBAL = '/usr/portage/profiles/use.desc'
LOCAL  = '/usr/portage/profiles/use.local.desc'

output = { 'global' => {}, 'local' => {} }

File.readlines(GLOBAL).each do |line|
  next if line =~ /^(|#.*)$/

  flag, desc = line.strip.split(' - ', 2)
  output['global'][flag] = desc
end

File.readlines(LOCAL).each do |line|
  next if line =~ /^(|#.*)$/

  atom_flag, desc = line.strip.split(' - ', 2)
  atom, flag      = atom_flag.split(':', 2)
  cat, pkg        = atom.split('/', 2)

  output['local'][cat]          ||= {}
  output['local'][cat][pkg]     ||= {}
  output['local'][cat][pkg][flag] = desc
end

puts output.to_json