Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions overlays/bootstrap_apt/usr/local/bin/apt-packages-origin
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# Author: Liraz Siri <liraz@turnkeylinux.org>
# list origin of packages

Expand Down Expand Up @@ -52,7 +52,13 @@ def parse_policies(fh):
yield pp

def main():
proc = subprocess.Popen(args="apt-cache policy $(dpkg -l | grep ^ii | awk '{print $2}')", shell=True, bufsize=1, stdout=subprocess.PIPE)
dpkg_proc = subprocess.Popen(['dpkg', '-l'], stdout=subprocess.PIPE, text=True)
pkgs = [line.split()[1] for line in dpkg_proc.stdout if line.startswith('ii')]
dpkg_proc.wait()
if dpkg_proc.returncode != 0:
raise SystemExit('dpkg -l failed with returncode %d' % dpkg_proc.returncode)
# if pkgs is empty, apt-cache policy runs with no args and lists policy for all packages
proc = subprocess.Popen(['apt-cache', 'policy'] + pkgs, bufsize=1, stdout=subprocess.PIPE, text=True)

rows = []
for pp in parse_policies(proc.stdout):
Expand All @@ -72,7 +78,7 @@ def main():

fmt = "%%-%ds %%-%ds %%s" % (maxcols[0], maxcols[1])
for row in rows:
print fmt % tuple(row)
print(fmt % tuple(row))

if __name__ == "__main__":
main()