Example #1
0
def print_tabular_inventory(args):

    selected = set(select.get_selected_packages())

    packages = repository.get_packages()
    packages.sort(key=lambda p: p.project.name)


    columns = [
        lambda p: p.project.qualified_id,
        lambda p: p.project.name,
        lambda p: p.attributes.get('version', ''),
    ]

    rows = []

    for i, package in enumerate(packages):
        row = []
        for column in columns:
            cell = column(package)
            width = len(cell)
            if width > getattr(column, 'width', 0):
                column.width = width
            row.append(cell)
        rows.append((row, package))

    for row, package in rows:
        print style(package, package in selected), '',
        for i, column in enumerate(columns):
            if i == 0:
                print row[i].rjust(column.width),
            else:
                print row[i].ljust(column.width),

        print reset_style
Example #2
0
def print_wide_inventory():
    selected = set(select.get_selected_packages())

    packages = repository.get_packages()
    packages.sort(key=lambda p: (p.project.namespace, p.project.id))

    format = lambda p: p.project.qualified_id

    cells = [
        style(p, p in selected) + format(p) + reset_style
        for p in packages
    ]

    cells = []
    for p in packages:
        text = format(p)
        cells.append((p, text))

    width = max(map(len, map(format, packages)))
    cols = 79 // width

    for row in chop(cells, cols):
        for (package, text) in row:
            print style(package, package in selected),
            print text.ljust(width),
            print reset_style,
        print ''
Example #3
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)
Example #4
0
def get_list(interface):
    result = []
    for package in select.get_selected_packages():
        result.extend(interface(package))
    return result