def update(filename, log):
    """ Invoked if the user has chosen to update his system """
    
    # Check if the platform is supported
    utils.check_platform_supported()
    
    # Check if the user is running with super-user priviliges
    utils.check_root()
    
    #FIXME: Unicode Fix
    # This is only a workaround.
    # When using locales, we get translation files. But apt doesn't extract the URI properly.
    # Once the extraction problem is root-caused, we can fix this easily.
    os.environ['__apt_set_update'] = filename
    try:
            old_environ = os.environ['LANG']
    except KeyError:
            old_environ = "C"
    os.environ['LANG'] = "C"
    log.verbose( "Set environment variable for LANG from %s to %s temporarily.\n" % ( old_environ, os.environ['LANG'] ) )
    if os.system( '/usr/bin/apt-get -qq --print-uris update >> $__apt_set_update' ) != 0:
            log.err( "FATAL: Something is wrong with the apt system.\n" )
            Bool_SetterErrors = True
    log.verbose( "Set environment variable for LANG back to its original from %s to %s.\n" % ( os.environ['LANG'], old_environ ) )
    os.environ['LANG'] = old_environ
def install_packages(filename, install_packages_list, target_release, log):
    """ Invoked if the user wants to install packages """
    
    # Check if the platform is supported
    utils.check_platform_supported()
    
    # Check if the user is running with super-user priviliges
    utils.check_root()
    
    comma_sep_package_list = ", ".join(install_packages_list)
    log.msg( "\nGenerating database of package %s and its dependencies.\n" % (comma_sep_package_list) )
    
    package_list = " ".join(install_packages_list)
    os.environ['__apt_set_install_packages'] = package_list
    
    os.environ['__apt_set_install'] = filename
    
    # If the target release is specified, include it as -t switch
    if target_release:
        os.environ['__apt_set_install_release'] = target_release
        if os.system( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release install $__apt_set_install_packages >> $__apt_set_install' ) != 0:
            raise AptSystemBrokenError(APT_SYSTEM_BROKEN)
    else:
        #FIXME: Find a more Pythonic implementation
        if os.system( '/usr/bin/apt-get -qq --print-uris install $__apt_set_install_packages >> $__apt_set_install' ) != 0:
            raise AptSystemBrokenError(APT_SYSTEM_BROKEN)

    return True
def upgrade(filename, upgrade_type, log):
    """ Invoked if the user wants to perform an upgrade """
    
    # Check if the platform is supported
    utils.check_platform_supported()
    
    # Check if the user is running with super-user priviliges
    utils.check_root()
    
    # Check if the provided upgrade type is valid or not
    utils.check_valid_upgrade_type(upgrade_type)
    
    if upgrade_type == "upgrade":
        res = upgrade_upgrade(filename ,log)
    elif upgrade_type == "dist-upgrade":
        res = upgrade_dist_upgrade(filename ,log)
    elif upgrade_type == "dselect-upgrade":
        res = upgrade_dist_upgrade(filename ,log)
        
    return res