-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpkg-without-dependencies.rb
executable file
·71 lines (57 loc) · 1.4 KB
/
dpkg-without-dependencies.rb
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
#this script is for gain only packages without dependencies from list of packages
require 'set'
# return set of dependencies from string with output from "apt-cache rdepends <package>"
def find_dependence(package)
dependencies = Set.new
package_name_found = false
dependence = `apt-rdepends #{package} 2>/dev/null`
dependence.each_line do |i|
if package_name_found
i.sub!(/ Depends: /,"")
i.sub!(/ PreDepends: /,"")
i.sub!(/\(.*/,"")
dependencies.add(i.strip.chomp)
end
if i.chomp == package
package_name_found = true
end
end
return dependencies
end
# return leaves from tree of dependences
def leaves(filename)
dependencies = Set.new
packages_input = Set.new
file = File.new( filename, "r" )
begin
counter = 0
while package = file.gets
packages_input.add(package.chomp)
end
packages_input.each do |package|
packages_input -= find_dependence(package.chomp)
STDOUT.write "\r#{counter += 1}"
end
puts
ensure
file.close
end
return packages_input
end
# main
if ARGV.length != 2
warn "Bad number of parameters!!!\n\nUsing: ruby dpkg-without-dependencies.rb file_name_input file_name_output"
exit 1
end
# run method result
result = leaves(ARGV[0])
# output
begin
file_out = File.new( ARGV[1], "w")
result.each do |i|
file_out.puts i.chomp
end
ensure
file_out.close
end
puts "Done"