Example #1
0
def load_package(blob):
    try:
        namespace, id, attrs = blob
    except:
        id, attrs = blob
        namespace = ''
    if namespace == '':
        return package.Package(recipe.get_project(id), attrs)
    elif namespace == 'site':
        pkg = local.get_package(id)
        return pkg
    else:
        raise Exception("Bad namespace '%s'" % namespace)
Example #2
0
def install(package_specifier):
    """Install a package."""
    project_id = package_specifier.project

    # Look up project.
    project = recipe.get_project(project_id)
    if not project:
        return error("No such project.")

    # Ensure not already installed.
    if find_installed_packages(package_specifier):
        return error("Already installed.")

    # Create a package representing an installed instance of the project with
    # the given parameters.
    package = factory(project, package_specifier)
    if package is no_factory:
        return error("Not installable.")
    if not package:
        return error("Invalid configuration.")
    if isinstance(package, basestring):
        return error(package)
    assert package_specifier.match(package)

    # Install to default location.
    package[a_location] = join(paths.packages, package.project.name)
    installer(package)

    # Update database.
    with catalogue.modify(catalogue_path) as cat:
        cat[package.project.id].append(package)

    # If no packages from this project are already selected, select this one.
    selected = select.get_selected_packages()
    if not any(p for p in selected if p.project.id == project_id):
        select.select_package(package)