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
79
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
|
#!/usr/bin/ruby
def usage
puts "Usage: #{$0} [options]"
puts "Moves obsolete packages"
puts
puts "-h, --help show help"
puts "-m, --media <path> path to the binary media"
puts "-s, --src <path> path to the associated src media"
puts "-d, --destination <path> path to the old packages storage"
end
require 'fileutils'
require 'getoptlong'
require 'readline'
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--archs', '-a', GetoptLong::REQUIRED_ARGUMENT ],
[ '--base', '-p', GetoptLong::REQUIRED_ARGUMENT ],
[ '--media', '-m', GetoptLong::REQUIRED_ARGUMENT ],
[ '--bmedia', '-b', GetoptLong::REQUIRED_ARGUMENT ],
[ '--smedia', '-s', GetoptLong::REQUIRED_ARGUMENT ],
[ '--destination', '-d', GetoptLong::REQUIRED_ARGUMENT ],
[ '--version', '-v', GetoptLong::REQUIRED_ARGUMENT ]
)
base_path = "<%= scope.lookupvar('buildsystem::var::repository::bootstrap_root') %>/distrib"
archs = [ "i586", "x86_64" ]
media = "core/release"
old_path = "<%= scope.lookupvar('buildsystem::var::youri::packages_archivedir') %>"
version = "cauldron"
opts.each do |opt, arg|
case opt
when '--help'
usage
exit 0
when '--bmedia'
bin_path = arg.split(",")
when '--smedia'
src_path = arg
when '--destination'
old_path = arg
when '--media'
media = arg
when '--archs'
archs = arg.split(",")
when '--base'
base_path = arg
when '--version'
version = arg
end
end
bin_path ||= archs.map{|arch| "#{base_path}/#{version}/#{arch}/media/#{media}" }
src_path ||= "#{base_path}/#{version}/SRPMS/#{media}"
debug_path = bin_path.map{|path| path.sub("/media/", "/media/debug/")}
$used_srcs = {}
$srcs = {}
# Get a list of all src.rpm
`urpmf --synthesis "#{src_path}/media_info/synthesis.hdlist.cz" --qf '%filename' "."`.each_line{|l|
$srcs[l.rstrip] = true
}
# For each binary media:
# - Check if we have the src.rpm (else the binary package is obsolete)
# - Mark used src.rpm (if one is never marked, the src.rpm is obsolete)
def move_packages(src, dst, list)
list.reject!{|f| !File.exist?(src + "/" + f)}
return if list.empty?
list.each{|b|
puts b
}
puts "The #{list.length} listed packages will be moved from #{src} to #{dst}."
line = Readline::readline('Are you sure [Yn]? ')
if (line =~ /^y?$/i)
list.each{|s|
oldfile = src + "/" + s
newfile = dst + "/" + s
next unless File.exist?(oldfile)
if (File.exist?(newfile))
File.unlink(oldfile)
else
FileUtils.mv(oldfile, newfile)
end
}
end
end
def check_binaries(path_list, old_path, mark_used)
path_list.each{|bm|
old_binaries = []
`urpmf --synthesis "#{bm}/media_info/synthesis.hdlist.cz" --qf '%sourcerpm:%filename' ":"`.each_line{|l|
l2 = l.split(':')
src = l2[0]
filename = l2[1].rstrip
old_binaries << filename unless $srcs[src]
$used_srcs[src] = true if mark_used
}
move_packages(bm, old_path, old_binaries)
}
end
check_binaries(bin_path, old_path, true)
check_binaries(debug_path, old_path, false)
$used_srcs.keys.each{|s| $srcs.delete(s)}
move_packages(src_path, old_path, $srcs.keys)
|