Skip to content

Commit 0f29b40

Browse files
committed
feat: add can_install can_from_file functions
1 parent 93bb842 commit 0f29b40

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/rootfs/package/dpkg.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ def manifest_package(file)
4242
end
4343
list
4444
end
45+
46+
def can_install(pkgs)
47+
ignores = []
48+
Libexec.each_line("apt-get install #{pkgs.join(" ")} 2>&1") do |line|
49+
err_pre = "E: Unable to locate package "
50+
if line.include?(err_pre)
51+
pkg = line.chomp.delete_prefix(err_pre)
52+
ignores.push(pkg)
53+
end
54+
end
55+
return pkgs if ignores.empty?
56+
57+
pkgs -= ignores
58+
can_install(pkgs)
59+
end
60+
61+
def can_from_file(file)
62+
pkgs = []
63+
IO.readlines(file).each do |line|
64+
pkgs.push(line.chomp)
65+
end
66+
can_install(pkgs)
67+
end
4568
end
4669
end
4770
end

lib/rootfs/package/dpkg_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ class MyClass
4040
desktop = live_desktop_pkgs - base_pkg
4141

4242
# puts server
43-
puts desktop
43+
# puts desktop
44+
45+
puts u.can_install(desktop)
46+
# puts u.can_from_file("install.txt")

0 commit comments

Comments
 (0)