Instantly share code, notes, and snippets.

Embed
What would you like to do?
mirror a PPA
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
'''
PPA=$1
if [ -z $PPA ] then;
echo "PPA is required. E.g:
fi
DIRECTORY=${2:-ubuntu}
PATH="$PPA/$DIRECTORY"
wget -m -I $PATH http://ppa.launchpad.net/$PATH
mv ppa.launchpad.net/$PATH/dists ppa.launchpad.net/$PATH/pool .
rm -rf ppa.launchpad.net/
# clean up
find . -type f -name 'index.*' -delete
find pool/ -type f ! -name '*.deb' -delete
rm -rf `find dists/ -maxdepth 1 -mindepth 1 ! -name precise ! -name trusty`
# because some deb can be used for all (E.g: salt-api)
find pool/ \( -type f -name '*.deb' \( -name '*lucid*' -or -name '*natty*' -or -name '*oneiric*' -or -name '*quantal*' -or -name '*raring*' -or -name '*saucy*' -or -name '*utopic*' -or -name '*vivid*' \) \) -delete
'''
import argparse
import shutil
LAUNCHPAD_DOMAIN = "ppa.launchpad.net"
LAUNCHPAD_URL = "http://" + LAUNCHPAD_DOMAIN
def main():
argp = argparse.ArgumentParser()
argp.add_argument("ppa")
argp.add_argument("directory", default="ubuntu")
args = argp.parse_args()
path = os.path.join(args.ppa, args.directory)
wget_cmd = ["wget", "-m" , "-I", path, LAUNCHPAD_URL + "/" + path]
mv_cmd = ["mv", os.path.join(LAUNCHPAD_DOMAIN, path), os.path.join(LAUNCHPAD_DOMAIN, path, "pool"), "."]
shutil.rmtree(LAUNCHPAD_DOMAIN, ignore_errors=True)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment