Example #1
0
def main(arglist):

    remotePath, localPath, installRoot = pup_common.getConfig(arglist[1:])

    if not os.path.exists(localPath):
        os.makedirs(localPath)
    if not os.path.exists(installRoot):
        os.makedirs(installRoot)

    s = sqlite3.connect(localPath + "/packages.pupdb")
    e = s.execute(
        "select * from packages where name=? order by ver desc limit 1",
        ([arglist[0]]))
    data = e.fetchone()
    if data is None:
        s.close()

        print "The package '%s' is not available. You may need to run `pup sync' to update the list of available packages." % (
            arglist[0])
        exit(1)
    s.close()

    # Package name
    packageName = "%s-%s" % (data[1], data[2])
    localFile = "%s/%s.pup" % (localPath, packageName)

    print "Preparing to install %s" % (packageName)

    if not os.path.exists(localFile):

        print "    -> Downloading..."

        for server in remotePath:
            remoteUrl = "%s/%s.pup" % (server, packageName)

            print "      + trying %s" % (remoteUrl),
            try:
                o = urllib.FancyURLopener()
                o.retrieve(remoteUrl, localFile)
                print "(OK)"
                break
            except:
                print "(failed)"
                continue

        if not os.path.exists(localFile):
            print "Error: couldn't download the package from any server. Check your internet connection and try again."
            exit(1)

    print "    -> Installing..."

    # TODO: track installed packages in a local database

    t = tarfile.open(localFile)
    t.extractall(installRoot)

    print "Package %s is now installed." % (packageName)
Example #2
0
def main(arglist):

    remotePath, localPath, installRoot = pup_common.getConfig(arglist[1:])

    if not os.path.exists(localPath):
        os.makedirs(localPath)
    if not os.path.exists(installRoot):
        os.makedirs(installRoot)

    s = sqlite3.connect(localPath + "/packages.pupdb")
    e = s.execute("select * from packages where name=? order by ver desc limit 1", ([arglist[0]]))
    data = e.fetchone()
    if data is None:
        s.close()

        print "The package '%s' is not available. You may need to run `pup sync' to update the list of available packages." % (
            arglist[0]
        )
        exit(1)
    s.close()

    # Package name
    packageName = "%s-%s" % (data[1], data[2])
    localFile = "%s/%s.pup" % (localPath, packageName)

    print "Preparing to install %s" % (packageName)

    if not os.path.exists(localFile):

        print "    -> Downloading..."

        for server in remotePath:
            remoteUrl = "%s/%s.pup" % (server, packageName)

            print "      + trying %s" % (remoteUrl),
            try:
                o = urllib.FancyURLopener()
                o.retrieve(remoteUrl, localFile)
                print "(OK)"
                break
            except:
                print "(failed)"
                continue

        if not os.path.exists(localFile):
            print "Error: couldn't download the package from any server. Check your internet connection and try again."
            exit(1)

    print "    -> Installing..."

    # TODO: track installed packages in a local database

    t = tarfile.open(localFile)
    t.extractall(installRoot)

    print "Package %s is now installed." % (packageName)
Example #3
0
def main(arglist):

    remotePath, localPath, ignore = pup_common.getConfig(arglist)

    if localPath[-1] == "/":
        localPath = localPath[0:-1]

    if not os.path.exists(localPath):
        os.makedirs(localPath)

    localFile = localPath + "/packages_new.pupdb"

    # TODO: merge multiple databases (and store the server on which each package can be found?)
    success = False
    for server in remotePath:
        remoteUrl = "%s/packages.pupdb" % (server)

        print "    -> syncing with %s" % (remoteUrl),
        try:
            o = urllib.FancyURLopener()
            o.retrieve(remoteUrl, localFile)
            success = True
            print "(OK)"
            break
        except:
            print "(failed)"
            continue

    if not success:
        print "Error: couldn't download package information from any server."
        exit(1)

    # If the database isn't a valid sqlite database, this will fail
    s = sqlite3.connect(localFile)
    e = s.execute("select * from packages")
    s.close()

    os.rename(localFile, localPath + "/packages.pupdb")

    print "Synchronisation complete."
Example #4
0
def main(arglist):

    remotePath, localPath, ignore = pup_common.getConfig(arglist)
    
    if localPath[-1] == "/":
        localPath = localPath[0:-1]

    if not os.path.exists(localPath):
        os.makedirs(localPath)
    
    localFile = localPath + "/packages_new.pupdb"

    # TODO: merge multiple databases (and store the server on which each package can be found?)
    success = False
    for server in remotePath:
        remoteUrl = "%s/packages.pupdb" % (server)
    
        print "    -> syncing with %s" % (remoteUrl),
        try:
            o = urllib.FancyURLopener()
            o.retrieve(remoteUrl, localFile)
            success = True
            print "(OK)"
            break
        except:
            print "(failed)"
            continue
    
    if not success:
        print "Error: couldn't download package information from any server."
        exit(1)
    
    # If the database isn't a valid sqlite database, this will fail
    s = sqlite3.connect(localFile)
    e = s.execute("select * from packages")
    s.close()
    
    os.rename(localFile, localPath + "/packages.pupdb")
    
    print "Synchronisation complete."