Skip to content

Instantly share code, notes, and snippets.

@brutasse
Created January 5, 2016 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brutasse/209480a6c73a0daaeb0d to your computer and use it in GitHub Desktop.
Save brutasse/209480a6c73a0daaeb0d to your computer and use it in GitHub Desktop.
import os
import subprocess
base = [f.rsplit('-', 3)[0] for f in os.listdir('..') if f.endswith('.xz')]
downloaded = {'sh'}
def clean(p):
return p.split('>=')[0].split('=')[0]
def deps(pkg):
if pkg == 'awk':
pkg = 'gawk'
out = subprocess.check_output(
'pacman -Si "{0}"|grep "Depends On"'.format(pkg),
shell=True,
)
return [clean(p) for p in
out[len('Depends On : '):].decode().strip().split()
if p not in ['None', 'libncursesw.so=6-64']]
def provides(pkg):
if pkg == 'awk':
pkg = 'gawk'
out = subprocess.check_output(
'pacman -Si "{0}"|grep "Provides :"'.format(pkg),
shell=True,
)
return [clean(p) for p in out[len("Provides : "):].decode().strip().split()
if p not in ['None']]
def download(dep):
link = subprocess.check_output('pacman -Sp {0}'.format(dep),
shell=True).decode().strip()
path = link.rsplit(os.sep)[-1]
if not os.path.exists(path):
print("downloading {0}".format(dep))
subprocess.check_output('wget {0}'.format(link), shell=True)
def resolve(pkg):
if pkg in downloaded:
return
print("resolving {0}".format(pkg))
dependencies = deps(pkg)
for dep in dependencies:
resolve(dep)
download(dep)
downloaded.add(pkg)
for provided in provides(pkg):
downloaded.add(provided)
for pkg in base:
resolve(pkg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment