Skip to content

Instantly share code, notes, and snippets.

@NickGeek
Last active January 1, 2016 10:09

Revisions

  1. NickGeek revised this gist Dec 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ppapt.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/usr/bin/python
    #!/usr/bin/python2.7
    #Install packages from most PPA's (via launchpad) on Debian and other Debian based distros.

    #Usage:
  2. NickGeek created this gist Dec 26, 2013.
    73 changes: 73 additions & 0 deletions ppapt.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    #!/usr/bin/python
    #Install packages from most PPA's (via launchpad) on Debian and other Debian based distros.

    #Usage:
    #./ppapt ppa:user/package

    #NOTE: This is written for Python 2.7.5. Feel free to run it on older/newer versions but don't expect stuff to work

    #Imports
    import os, sys, urllib2

    def launchpadParser(url, user, package):
    launchpadHTMLRequest = urllib2.urlopen(url)
    launchpadHTML = launchpadHTMLRequest.read()
    launchpadHTMLRequest.close()
    launchpadHTML = launchpadHTML.split("\n")
    searchTerms = ['href="+sourcepub/']
    searchResults = []

    #Search for link to deb file deatail page in HTML
    for line in launchpadHTML:
    if any(word in line for word in searchTerms):
    searchResults.append(line.strip())

    packageDetailsURL = searchResults[0]
    packageID = packageDetailsURL.split("/")[1]
    packageDetailsURL = "https://launchpad.net/~"+user+"/+archive/"+package+"/+sourcepub/"+packageID+"/+listing-archive-extra"
    launchpadHTMLRequest = urllib2.urlopen(packageDetailsURL)
    launchpadHTML = launchpadHTMLRequest.read()
    launchpadHTMLRequest.close()
    launchpadHTML = launchpadHTML.split("\n")
    searchTerms = ['.deb']
    searchResults = []
    for line in launchpadHTML:
    if any(word in line for word in searchTerms):
    searchResults.append(line.strip())

    debFileURL = searchResults[0]
    debFileURL = debFileURL.split('"')[1]
    return debFileURL

    def install(user, package):
    #Find the package on launchpad
    launchpadURL = "https://launchpad.net/~"+user+"/+archive/"+package+"/+packages"
    print("Finding package...")
    debFileURL = launchpadParser(launchpadURL, user, package)

    #Download the package
    print("Downloading package...")
    debFile = urllib2.urlopen(debFileURL)
    fileSys = open('package.deb', 'wb')
    fileSys.write(debFile.read())
    fileSys.close()
    debFile.close()

    #Install the package
    print("Installing package...")
    #If possible use gdebi, but if that isn't installed use dpkg
    if any([os.path.exists(os.path.join(p,"gdebi")) for p in os.environ["PATH"].split(":")]):
    os.system('sudo gdebi package.deb')
    else:
    os.system('sudo dpkg -i package.deb')
    os.remove('package.deb')

    ppa = sys.argv[1]

    #Decode the PPA
    ppa = ppa.split(":")
    ppa = ppa[1]
    user = ppa.split("/")[0]
    package = ppa.split("/")[1]

    install(user, package)