Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #import subprocess
- import envoy
- import re
- import os
- debline = re.compile(r"^deb https?://([^\s]+)\s*([^\s]+)\s*((main|contrib|non-free)\s*)*$")
- def read_repos_from(path):
- if os.path.isdir(path):
- for i in os.listdir(path):
- read_repos_from(path + '/' + i)
- return
- f = file(path, 'r')
- for line in f:
- m = debline.match(line)
- if m:
- if(m.group(2)[-1] == '/'):
- yield ('_'.join(m.groups()[0:2]), m.group(1))
- else:
- yield ('_dists_'.join(m.groups()[0:2]), m.group(2))
- repos = [i for i in read_repos_from('/etc/apt/sources.list')]
- repos.extend([i for i in read_repos_from('/etc/apt/sources.list.d')])
- reponames = []
- for (path, name) in repos:
- path = path.replace('/','_').replace('__','_')
- if path[-1] == '_':
- path = path[0:-1]
- reponames.append((path, name))
- packages = envoy.run('dpkg -l')
- pkgs = []
- for line in packages.std_out.splitlines()[5:]:
- pkgs.append(line.split()[1:3])
- for i in pkgs:
- s = envoy.run("apt-cache showpkg " + i[0]).std_out
- l = s.index(i[1])
- r = s.index("\n", l)
- pkg_instance = s[l:r]
- l = pkg_instance.index('(')
- r = pkg_instance.index(')',l)
- pkg_path = pkg_instance[pkg_instance.rindex('/',l,r) + 1:r]
- for (path, name) in reponames:
- if pkg_path.find(path,0, len(path)) == 0:
- print(i[0] + " " + i[1] + " from " + name)
Add Comment
Please, Sign In to add comment