def uninstall(installed, attempt_uninstall):
    """ Returns a collection of units allowed to be uninstalled.

    Parameters
        installed
            Set having all currently installed units on the system.
        attempt_uninstall
            an iterable having all units the user is attempting
            to get uninstalled.
    Returns
        list
            having all Package units to be uninstalled.
    """

    already_targeted = Set()
    attempt_uninstall = Set(attempt_uninstall)
    to_uninstall = Set()

    # Ignore units which are not installed
    for unit in list(attempt_uninstall):
        if unit not in installed:
            message.simple("'{0}' is not installed and therefore cannot be uninstalled. Ignoring...".format(unit))
            attempt_uninstall.remove(unit)

    # Target units for uninstallation
    for unit in list(attempt_uninstall):
        if isinstance(unit, Uninstallable):
            unit.target_for_uninstallation(installed, attempt_uninstall, already_targeted, to_uninstall)
        else:
            message.simple("'{0}' is not uninstallable. Ignoring...".format(unit))

    return to_uninstall
Exemple #2
0
def uninstall(installed, attempt_uninstall):
    """ Returns a collection of units allowed to be uninstalled.

    Parameters
        installed
            Set having all currently installed units on the system.
        attempt_uninstall
            an iterable having all units the user is attempting
            to get uninstalled.
    Returns
        list
            having all Package units to be uninstalled.
    """

    already_targeted = Set()
    attempt_uninstall = Set(attempt_uninstall)
    to_uninstall = Set()

    # Ignore units which are not installed
    for unit in list(attempt_uninstall):
        if unit not in installed:
            message.simple(
                "'{0}' is not installed and therefore cannot be uninstalled. Ignoring..."
                .format(unit))
            attempt_uninstall.remove(unit)

    # Target units for uninstallation
    for unit in list(attempt_uninstall):
        if isinstance(unit, Uninstallable):
            unit.target_for_uninstallation(installed, attempt_uninstall,
                                           already_targeted, to_uninstall)
        else:
            message.simple(
                "'{0}' is not uninstallable. Ignoring...".format(unit))

    return to_uninstall
def downgrade(configuration, installed, available, attempt_downgrade):
    """ Returns a collection of units for performing an downgrade.

    Parameters
        configuration
            a valid Craft Configuration object.
        installed
            Set having all currently installed units on the system.
        available
            Set having all currently available units on the system.
        attempt_downgrade
            an iterable having all units the user is attempting
            to get to be downgraded.
    Raises
        BrokenDependency
            if a dependency could not be resolved.
        Conflict
            if a conflict was found between two units.
        PackageNotAllowed
            if at least one of the units targeted for installation
            is not able to be installed due to its CPU architecture
            being disabled.
    Returns
        list
            having the units that must be installed, and are replacing older
            units, the units to be uninstalled, and are being replaced,
            and the newly found dependencies.
    """

    already_targeted_for_installation = Set()
    already_targeted_for_downgrade = Set()
    attempt_downgrade = Set(attempt_downgrade)
    to_install = Set()
    to_uninstall = Set()

    # Ignore units which are not installed
    for unit in list(attempt_downgrade):
        if unit not in installed:
            message.simple("'{0}' is not installed and therefore cannot be downgraded. Ignoring...".format(unit))
            attempt_downgrade.remove(unit)

    for unit in attempt_downgrade:
        if isinstance(unit, Downgradeable):
            try:
                unit.target_for_downgrade(installed, available, already_targeted_for_downgrade, already_targeted_for_installation, to_install, to_uninstall)
            except BrokenDependency:
                raise
        else:
            message.simple("'{0}' is not downgradeable. Ignoring...".format(unit))

    # Check if any of the units is not allowed due to one their CPU
    # architectures not being enabled
    for unit in to_install:
        if not configuration.is_unit_allowed(unit):
            message.simple("'{0}' is not allowed to be installed since its architecture is not currently enabled.".format(unit))
            raise PackageNotAllowed(unit)

    # Check for conflicts
    for unit in to_install:
        if isinstance(unit, Incompatible):
            try:
                unit.check_for_conflicts(installed, to_install)
            except Conflict:
                raise

    return [to_install, to_uninstall]
def install(configuration, installed, available, attempt_install):
    """ Returns a collection of units allowed to be installed.
    Resolves dependencies, handles conflicts and checks
    for disabled CPU architectures.

    Parameters
        configuration
            a valid Craft Configuration object.
        installed
            Set having all currently installed units on the system.
        available
            Set having all currently available units on the system.
        attempt_install
            iterable having all units the user is attempting
            to get installed.
    Raises
        BrokenDependency
            if a dependency could not be resolved.
        Conflict
            if a conflict was found between two units.
        PackageNotAllowed
            if at least one of the units targeted for installation
            is not able to be installed due to its CPU architecture
            being disabled.
    Returns
        list
            having all Package units to be installed.
    """

    already_targeted = Set()
    attempt_install = Set(attempt_install)
    to_install = Set()

    # Remove all already installed units from the list
    for unit in list(attempt_install):
        if unit in installed:
            message.simple("'{0}' is already installed. Ignoring...".format(unit))
            attempt_install.remove(unit)

    # Target units for installation
    for unit in list(attempt_install):
        if isinstance(unit, Installable):
            try:
                unit.target_for_installation(installed, available, attempt_install, already_targeted, to_install)
            except BrokenDependency:
                raise
        else:
            message.simple("'{0}' is not installable. Ignoring...".format(unit))

    # Check if any of the units is not allowed due to one their CPU
    # architectures not being enabled
    for unit in to_install:
        if not configuration.is_unit_allowed(unit):
            message.simple("'{0}' is not allowed to be installed since its architecture is not currently enabled.".format(unit))
            raise PackageNotAllowed(unit)

    # Check for conflicts
    for unit in to_install:
        if isinstance(unit, Incompatible):
            try:
                unit.check_for_conflicts(installed, to_install)
            except Conflict:
                raise

    return to_install
def _uninstall(configuration, installed, package, keep_static):
    """ Performs a low-level package uninstallation.

    Parameters
        configuration
            a valid Craft Configuration object.
        installed
            Set having all currently installed units on the system.
        package
            the Package unit to be uninstalled.
        keep_static
            specifies whether the package's static files must be preserved
            or not.
    Raises
        UninstallError
            if any error occurs during the uninstallation.
    Returns
        True
            if the uninstallation was successfully completed.
    """

    architecture = package.architecture
    name = package.name
    version = package.version
    db = configuration.db()
    root = configuration.root()

    if package not in installed:
        message.warning("'{0}' is not installed. Aborting...".format(package))
        raise UninstallError(package)

    try:
        chdir(db+'installed/'+name+'/'+version+'/'+architecture)
    except OSError:
        message.warning("could not access the directory belonging to package '{0}'.".format(package))
        raise UninstallError(package)

    package_files = []
    try:
        handle = open('files')
    except IOError:
        pass
    else:
        package_files = handle.read().splitlines()
        handle.close()

    craft_files = [
        db+'installed/'+name+'/'+version+'/'+architecture+'/metadata.yml',
        db+'installed/'+name+'/'+version+'/'+architecture+'/files',
        db+'installed/'+name+'/'+version+'/'+architecture
    ]

    for each in package_files:
        if not access(root+each, W_OK):
            message.warning("cannot remove file '{0}' from package '{1}'.".format(root+each, package))
            raise UninstallError(package)

    for each in craft_files:
        if isfile(each) or isdir(each):
            if not access(each, W_OK):
                message.warning("cannot remove file '{0}'.".format(each))
                raise UninstallError(package)

    if keep_static:
        for each in package.static():
            try:
                message.simple("Attempting to save '{0}' as '{1}'...".format(root+each, root+each+'.craft-old'))
                rename(root+each, root+each+'.craft-old')
            except OSError:
                message.simple("Could not preserve the following static file: '{0}'.".format(root+each))
                message.simple("  '{0}' may exist already.".format(root+each+'.craft-old'))
                pass

    for each in package_files:
        try:
            if isdir(root+each):
                rmdir(root+each)
            elif isfile(root+each):
                remove(root+each)
        except OSError:
            pass

    for each in craft_files:
        try:
            if isdir(each):
                rmdir(each)
            elif isfile(each):
                remove(each)
        except OSError:
            pass

    try_to_remove = [
        db+'installed/'+name+'/'+version,
        db+'installed/'+name
    ]
    for each in try_to_remove:
        try:
            rmdir(each)
        except OSError:
            break

    installed.remove(package)
    return True
Exemple #6
0
def downgrade(configuration, installed, available, attempt_downgrade):
    """ Returns a collection of units for performing an downgrade.

    Parameters
        configuration
            a valid Craft Configuration object.
        installed
            Set having all currently installed units on the system.
        available
            Set having all currently available units on the system.
        attempt_downgrade
            an iterable having all units the user is attempting
            to get to be downgraded.
    Raises
        BrokenDependency
            if a dependency could not be resolved.
        Conflict
            if a conflict was found between two units.
        PackageNotAllowed
            if at least one of the units targeted for installation
            is not able to be installed due to its CPU architecture
            being disabled.
    Returns
        list
            having the units that must be installed, and are replacing older
            units, the units to be uninstalled, and are being replaced,
            and the newly found dependencies.
    """

    already_targeted_for_installation = Set()
    already_targeted_for_downgrade = Set()
    attempt_downgrade = Set(attempt_downgrade)
    to_install = Set()
    to_uninstall = Set()

    # Ignore units which are not installed
    for unit in list(attempt_downgrade):
        if unit not in installed:
            message.simple(
                "'{0}' is not installed and therefore cannot be downgraded. Ignoring..."
                .format(unit))
            attempt_downgrade.remove(unit)

    for unit in attempt_downgrade:
        if isinstance(unit, Downgradeable):
            try:
                unit.target_for_downgrade(installed, available,
                                          already_targeted_for_downgrade,
                                          already_targeted_for_installation,
                                          to_install, to_uninstall)
            except BrokenDependency:
                raise
        else:
            message.simple(
                "'{0}' is not downgradeable. Ignoring...".format(unit))

    # Check if any of the units is not allowed due to one their CPU
    # architectures not being enabled
    for unit in to_install:
        if not configuration.is_unit_allowed(unit):
            message.simple(
                "'{0}' is not allowed to be installed since its architecture is not currently enabled."
                .format(unit))
            raise PackageNotAllowed(unit)

    # Check for conflicts
    for unit in to_install:
        if isinstance(unit, Incompatible):
            try:
                unit.check_for_conflicts(installed, to_install)
            except Conflict:
                raise

    return [to_install, to_uninstall]
Exemple #7
0
def install(configuration, installed, available, attempt_install):
    """ Returns a collection of units allowed to be installed.
    Resolves dependencies, handles conflicts and checks
    for disabled CPU architectures.

    Parameters
        configuration
            a valid Craft Configuration object.
        installed
            Set having all currently installed units on the system.
        available
            Set having all currently available units on the system.
        attempt_install
            iterable having all units the user is attempting
            to get installed.
    Raises
        BrokenDependency
            if a dependency could not be resolved.
        Conflict
            if a conflict was found between two units.
        PackageNotAllowed
            if at least one of the units targeted for installation
            is not able to be installed due to its CPU architecture
            being disabled.
    Returns
        list
            having all Package units to be installed.
    """

    already_targeted = Set()
    attempt_install = Set(attempt_install)
    to_install = Set()

    # Remove all already installed units from the list
    for unit in list(attempt_install):
        if unit in installed:
            message.simple(
                "'{0}' is already installed. Ignoring...".format(unit))
            attempt_install.remove(unit)

    # Target units for installation
    for unit in list(attempt_install):
        if isinstance(unit, Installable):
            try:
                unit.target_for_installation(installed, available,
                                             attempt_install, already_targeted,
                                             to_install)
            except BrokenDependency:
                raise
        else:
            message.simple(
                "'{0}' is not installable. Ignoring...".format(unit))

    # Check if any of the units is not allowed due to one their CPU
    # architectures not being enabled
    for unit in to_install:
        if not configuration.is_unit_allowed(unit):
            message.simple(
                "'{0}' is not allowed to be installed since its architecture is not currently enabled."
                .format(unit))
            raise PackageNotAllowed(unit)

    # Check for conflicts
    for unit in to_install:
        if isinstance(unit, Incompatible):
            try:
                unit.check_for_conflicts(installed, to_install)
            except Conflict:
                raise

    return to_install
Exemple #8
0
def _uninstall(configuration, installed, package, keep_static):
    """ Performs a low-level package uninstallation.

    Parameters
        configuration
            a valid Craft Configuration object.
        installed
            Set having all currently installed units on the system.
        package
            the Package unit to be uninstalled.
        keep_static
            specifies whether the package's static files must be preserved
            or not.
    Raises
        UninstallError
            if any error occurs during the uninstallation.
    Returns
        True
            if the uninstallation was successfully completed.
    """

    architecture = package.architecture
    name = package.name
    version = package.version
    db = configuration.db()
    root = configuration.root()

    if package not in installed:
        message.warning("'{0}' is not installed. Aborting...".format(package))
        raise UninstallError(package)

    try:
        chdir(db + 'installed/' + name + '/' + version + '/' + architecture)
    except OSError:
        message.warning(
            "could not access the directory belonging to package '{0}'.".
            format(package))
        raise UninstallError(package)

    package_files = []
    try:
        handle = open('files')
    except IOError:
        pass
    else:
        package_files = handle.read().splitlines()
        handle.close()

    craft_files = [
        db + 'installed/' + name + '/' + version + '/' + architecture +
        '/metadata.yml', db + 'installed/' + name + '/' + version + '/' +
        architecture + '/files',
        db + 'installed/' + name + '/' + version + '/' + architecture
    ]

    for each in package_files:
        if not access(root + each, W_OK):
            message.warning(
                "cannot remove file '{0}' from package '{1}'.".format(
                    root + each, package))
            raise UninstallError(package)

    for each in craft_files:
        if isfile(each) or isdir(each):
            if not access(each, W_OK):
                message.warning("cannot remove file '{0}'.".format(each))
                raise UninstallError(package)

    if keep_static:
        for each in package.static():
            try:
                message.simple("Attempting to save '{0}' as '{1}'...".format(
                    root + each, root + each + '.craft-old'))
                rename(root + each, root + each + '.craft-old')
            except OSError:
                message.simple(
                    "Could not preserve the following static file: '{0}'.".
                    format(root + each))
                message.simple(
                    "  '{0}' may exist already.".format(root + each +
                                                        '.craft-old'))
                pass

    for each in package_files:
        try:
            if isdir(root + each):
                rmdir(root + each)
            elif isfile(root + each):
                remove(root + each)
        except OSError:
            pass

    for each in craft_files:
        try:
            if isdir(each):
                rmdir(each)
            elif isfile(each):
                remove(each)
        except OSError:
            pass

    try_to_remove = [
        db + 'installed/' + name + '/' + version, db + 'installed/' + name
    ]
    for each in try_to_remove:
        try:
            rmdir(each)
        except OSError:
            break

    installed.remove(package)
    return True