Example #1
0
def update_project(projects, local_repos=None, remote_repos=None,
    interactive=True, dry_run=False, term_width=0, verbose=False):
    """\
    Update a project, if possible.

    """
    # Before we do anything, save the current working state of the environment
    # to a rollback point.
    # TODO:  If the upgrade fails, we need to rollback to this save point.
    save_state(verbose=verbose)

    # Ensure we know what our local repository consists of.
    if local_repos == None:
        local_repos = get_local_repos()
    local = RepositoryUnion(local_repos)

    # If no explicit project(s) were specified to update, add all locally
    # installed projects to those we'll try to update.
    if len(projects) == 0:
        for project in sorted(local.projects):
            pkg = local.projects[project].active_package
            if pkg:
                projects.append(project)

    # Otherwise, since all of the name in the local.projects dictionary
    # are lowercase, we might as well make them all that way for consistency
    # sake.
    else:
        projects = [name.lower() for name in projects]

    # Determine the requirement specification needed for each project.
    requirements = []
    for name in projects:

        # If the user specified a project which isn't installed, just skip it.
        try:
            active_local_projects = [project
                for project in local.projects[name].projects
                if project.active]
        except KeyError:
            if verbose:
                print ("Skipping %s because it is not installed on your "
                    "system.") % name
            continue

        # If we have a current version active, then we use it's version to
        # to determine what a valid update would be.
        if active_local_projects:
            pkg = active_local_projects[0].active_package
            req_str = get_upgrade_str(name, pkg.version, upgrade=False)
            requirement = Requirement.parse(req_str)

        # Otherwise, we try to build an upgrade requirement from the largest
        # version number of all inactive versions.
        else:
            max_pkg = None
            for pkg in local.projects[name].packages:
                if max_pkg is None or pkg > max_pkg:
                    max_pkg = pkg
            if max_pkg is not None:
                req_str = get_upgrade_str(name, max_pkg.version, upgrade=False)
                requirement = Requirement.parse(req_str)
            else:
                requirement = Requirement.parse(project)
        requirements.append(requirement)
    if not requirements:
        return
    if verbose:
        print 'Generated requirements for updates:'
        for r in requirements:
            print '\t%s' % r

    # Try to install all of the generated requirements.
    # FIXME: This takes WAY to long.
    install_requirement(requirements, local_repos=local_repos,
        remote_repos=remote_repos, interactive=interactive, dry_run=dry_run,
        term_width=term_width, verbose=verbose)

    # After we have finished the update, we save the new state.
    # TODO:  If the update failed, we should instead revert to the
    #        previous state.
    save_state(verbose=verbose)
Example #2
0
def upgrade_project(keys, local_repos=None, remote_repos=None,
    interactive=True, dry_run=False, term_width=0, verbose=False):
    """ Upgrade a project, if possible.
    """
    # Before we do anything, save the current working state of the
    # environment to a rollback point.
    # TODO:  If the upgrade fails, we need to rollback to this save point.
    save_state(verbose=verbose)

    if local_repos == None:
        local_repos = get_local_repos()
    local = RepositoryUnion(get_local_repos())
    requirements = []

    # If no explicit project(s) were specified to upgrade, try to upgrade
    # all of the local projects installed.
    if len(keys) == 0:
        for project in local.projects:
            pkg = local.projects[project].active_package
            if pkg:
                keys.append(project)

    for key in keys:
        # All of the keys in the local.projects dictionary are lowercase, so
        # convert all of the user-specified keys to lowercase.
        key = key.lower()

        # If the user specified a project which isn't installed, just skip it.
        try:
            active_local_projects = [project
                for project in local.projects[key].projects
                    if project.active]
        except KeyError:
            print("Skipping %s because it is not installed on your system." %
                  key)
            continue

        if active_local_projects:
            pkg = active_local_projects[0].active_package

            # Retrieve an upgrade string based on the package name/version.
            req_str = get_upgrade_str(key, pkg.version)

            # Create a requirement object from our requirement string.
            requirement = Requirement.parse(req_str)
        else:
            max_pkg = None
            for pkg in local.projects[key].packages:
                if max_pkg is None or pkg > max_pkg:
                    max_pkg = pkg
            if max_pkg is not None:
                req_str = get_upgrade_str(key, max_pkg.version)
                requirement = Requirement.parse(req_str)
            else:
                requirement = Requirement.parse(project)
        requirements.append(requirement)

    # Try to install all of the generated requirements.
    install_requirement(requirements, local_repos=local_repos,
        remote_repos=remote_repos, interactive=interactive, dry_run=dry_run,
        term_width=term_width)

    # After we have finished the upgrade, we save the new state.
    # TODO:  If the upgrade failed, we should instead revert to the
    #        previous state.
    save_state(verbose=verbose)
Example #3
0
    # Try to set up a proxy server, either from options or environment vars.
    # This makes urllib2 calls do the right thing.
    try:
        installed = setup_proxy(options.proxy)
    except ValueError, e:
        error('Proxy configuration error: %s' % e)
        sys.exit(2)

    # Do the user's requested command.
    command = args[0]
    args = args[1:]

    if command == "install":
        install_requirement([Requirement.parse(arg) for arg in args],
            remote_repos=remote_repos,
            interactive=options.interactive, dry_run=options.dry_run,
            term_width=options.term_width)

    elif command == "upgrade":
        upgrade_project(args,
            remote_repos=remote_repos,
            interactive=options.interactive, dry_run=options.dry_run,
            term_width=options.term_width, verbose=options.verbose)

    elif command == "update":
        update_project(args,
            remote_repos=remote_repos,
            interactive=options.interactive, dry_run=options.dry_run,
            term_width=options.term_width, verbose=options.verbose)

    elif command == "rollback":