Python is an interpreted, high-level, general-purpose programming language
tis-python3-32 icon


  • package : tis-python3-32
  • version : 3.9.7-28
  • architecture : all
  • categories : Development
  • maintainer : WAPT Team,Tranquil IT,Jimmy PELÉ
  • description : Python is an interpreted, high-level, general-purpose programming language
  • locale :
  • target_os : windows
  • min_wapt_version : 1.8
  • sources : https://www.python.org/downloads/windows/
  • installed_size :
  • impacted_process :
  • description_fr : Python est un langage de programmation interprété, multi-paradigme et multiplateformes
  • description_pl :
  • description_de :
  • description_es :
  • description_pt :
  • description_it :
  • description_nl :
  • description_ru :
  • editor : Python Software Foundation
  • licence : Python Software Foundation License
  • signature_date : 2021-09-29T16:57:03.754248
  • Homepage : https://www.python.org/
  • Depends :
  • Conflicts :


# -*- coding: utf-8 -*-
from setuphelpers import *
import platform
import bs4 as BeautifulSoup

# Installation procedure: https://docs.python.org/3/using/windows.html

# Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
bin_contains = 'python-'
app_dir_sub = makepath(programfiles32, 'Python%s-32')
app_uninstallkey = '' # Let it empty because it change every versions

def install():
    # Declaring local variables
    package_version = control.get_software_version()
    short_version = '.'.join(package_version.split('.')[:2])
    two_digit_version = ''.join(package_version.split('.')[:2])
    app_dir = app_dir_sub % two_digit_version
    bin_name = glob.glob('*%s*.exe' % bin_contains)[0]
    app_name = control.name
    app_installer_path = makepath(app_dir, bin_name)
    product_name = get_file_properties(bin_name)['ProductName']
    silent_args = '/quiet InstallAllUsers=1 PrependPath=1 AssociateFiles=1 Include_launcher=0 InstallLauncherAllUsers=0 TargetDir="%s"' % app_dir
    #silent_args = '/quiet InstallAllUsers=1 PrependPath=1 AssociateFiles=1 Include_launcher=0 InstallLauncherAllUsers=0'

    # Repairing if older installation is incomplete
    python_app = installed_softwares(name='Python %s' % short_version)
    if python_app and len(python_app) < 9:
        print("Repairing: %s at: %s" % (product_name, app_dir))
        run('"%s" /repair %s' % (bin_name, silent_args))

    # Installing the package
    if need_install(name='Python %s' % short_version, min_version=get_version_from_binary(bin_name), force=force):
        print("Installing: %s to: %s" % (product_name, app_dir))
        print("%s is already installed and up-to-date" % app_name)

    # Copying installer for future uninstall
    if not isfile(app_installer_path):

def uninstall():
    # Declaring local variables
    package_version = control.get_software_version()
    two_digit_version = ''.join(package_version.split('.')[:2])
    app_dir = app_dir_sub % two_digit_version
    bin_name = glob.glob(r'%s\%s*.exe' % (app_dir, bin_contains))[0]
    app_installer_path = makepath(app_dir,bin_name)
    silent_uninst_args = '/uninstall /quiet'

    # Uninstalling the package
    run('"%s" %s' % (app_installer_path, silent_uninst_args))

    # Removing remaining files of this Python version
        if isdir(app_dir):
            print("Removing remaining folder: %s" % app_dir)
        print("Unable to remove Python %s remaining folder: %s" % (package_version, app_dir))

    # Removing system environment variables
    remove_from_system_path(makepath(app_dir, 'Scripts'))

def update_package():
    # Declaring local variables
    result = False
    proxies = get_proxies()
    if not proxies:
        proxies = get_proxies_from_wapt_console()
    app_name = control.name
    url = 'https://www.python.org/downloads/windows/'
    if control.architecture == 'x64':
        arch = '64-bit'
        arch = '32-bit'

    # Getting latest version from official sources
    for bs_search in bs_find_all(url, 'a', proxies=proxies):
        if bs_search['href'].startswith('https://www.python.org/ftp/python/3.') and bs_search.string.startswith('Windows installer (%s)' % arch):
            version = bs_search['href'].split('/')[-2]
            latest_bin = bs_search['href'].split('/')[-1]
            url_dl = bs_search['href']

    print("Latest %s version is: %s" % (app_name, version))
    print("Download url is: %s" % url_dl)

    # Downloading latest binaries
    if not isfile(latest_bin):
        print("Downloading: %s" % latest_bin)
        wget(url_dl, latest_bin, proxies=proxies)

        # Checking version from file
        version_from_file = get_version_from_binary(latest_bin, 'ProductName').split(' (')[0].split(' ')[-1]
        if Version(version) != Version(version_from_file) and version_from_file != '':
            print("Changing version to the version number of the binary (from: %s to: %s)" % (version, version_from_file))
            os.rename(latest_bin, bin_contains + version_from_file + latest_bin.split(version)[-1])
            version = version_from_file

    # Changing version of the package
    if Version(version) > Version(control.get_software_version()):
        print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version)))
        result = True
    control.version = '%s-%s' % (Version(version), control.version.split('-', 1)[-1])

    # Deleting outdated binaries

    # Validating or not update-package-sources
    return result

def need_install(key='', min_version=None, force=False, get_version=None, keywords='', name=''):
    """Return True if the software with key can be found in uninstall registry
    and the registred version is equal or greater than min_version

        key (str): uninstall key
        min_version (str): minimum version or None if don't check version (like when key is specific for each soft version)
        get_version (callable): optional func to get installed software version from one installed_softwares item
            if not provided, version is taken from 'version' attribute in uninstall registry
        keywords (str or list): string to lookup in key, display_name or publisher fields
        name (str regexp) : filter on a regular expression on software name


    .. versionchanged:: 2.1
        added keywords and name


    if force or (not bool(key) and not bool(keywords) and not bool(name)):
        return True
    elif len([i for i in [key, name, keywords] if i]) >= 2:
        error("Please only specify key or keywords or name")
        if key:
            current = installed_softwares(uninstallkey=key)
        if keywords:
            current = installed_softwares(keywords=keywords)
        if name:
            current = installed_softwares(name=name)
        for soft in current:
            if min_version is None:
                return False
            if get_version is not None:
                installed_version = get_version(soft)
                installed_version = soft['version']
            if Version(min_version) <= installed_version:
                return False
        return True

def get_proxies():
    r"""Return system proxy with the urllib python library

    >>> get_proxies()
    {'http': 'http://srvproxy.ad.domain.lan:8080',
    'https': 'http://srvproxy.ad.domain.lan:8080'}

    if platform.python_version_tuple()[0] == '3':
        from urllib.request import getproxies
        from urllib import getproxies
    return getproxies()

def get_proxies_from_wapt_console():
    r"""Return proxy information from the current user WAPT console

    >>> get_proxies_from_wapt_console()
    {'http': 'http://srvproxy.ad.domain.lan:8080',
    'https': 'http://srvproxy.ad.domain.lan:8080'}

    proxies = {}
    if platform.system() == 'Windows':
        waptconsole_ini_path = makepath(user_local_appdata(), 'waptconsole', 'waptconsole.ini')
        waptconsole_ini_path = makepath(user_home_directory(), '.config', 'waptconsole', 'waptconsole.ini')
    if isfile(waptconsole_ini_path):
        proxy_wapt = inifile_readstring(waptconsole_ini_path, 'global', 'http_proxy')
        if proxy_wapt:
            proxies = {'http': proxy_wapt, 'https': proxy_wapt}
    return proxies

def bs_find_all(url, element, attribute=None, value=None, user_agent=None, proxies=None, features='html.parser', **kwargs):
    r""""Parse html web page with BeautifulSoup and get a list of the result

        url (str): url of the web page to parse
        element (str): searched element
        attribute (str): selected attribute of the element
        value (str): value of the selected attribute
        user_agent (str): specify a user-agent if needed
        proxies (dict): specify your proxy if needed
        **kwargs (str): joker for requests parameters
        features (str): bs feature to use

    >>> bs_find_all('https://www.w3.org/', 'a', 'title', 'Open Web Platform testing')[0]['href']

    >>> bs_find_all('https://www.w3.org/', 'span', 'class', 'alt-logo')[0].string

    .. versionadded:: 2.0

    import requests
    if user_agent:
        page = requests.get(url, proxies=proxies, headers={'User-Agent':'%s' % user_agent}, **kwargs).text
        page = requests.get(url, proxies=proxies, **kwargs).text
    soup = BeautifulSoup.BeautifulSoup(page, features=features)
    if value:
        return soup.find_all(element, {attribute:value})
        return soup.find_all(element)

def get_version_from_binary(filename, property_name='ProductVersion'):
    r""" Get installer version from file informations, for now, only exe and msi files are compatibles

        filename (str): path to the file
        property_name (str): selected property

        str: version number

    if filename.endswith('.msi'):
        return get_msi_properties(filename)[property_name]
        return get_file_properties(filename)[property_name]

def remove_outdated_binaries(version, filename_contains=None, list_extensions=['exe','msi','deb','rpm','dmg','pkg']):
    r"""Remove files based on the version contained in his filename

        version (str): version number of keeped files
        filename_contains (str or list of str): Part of the filename that must be contained (useful for distinguishing architecture and os)
        list_extensions (str or list of str): file extensions of verified files


    .. versionadded:: 2.0

    if type(list_extensions) != list:
        list_extensions = [list_extensions]
    if filename_contains:
        if type(filename_contains) != list:
            filename_contains = [filename_contains]
    list_extensions = ['.' + ext for ext in list_extensions if ext[0] != '.']
    for file_ext in list_extensions:
        for bin_in_dir in glob.glob('*%s' % file_ext):
            if not version in bin_in_dir:
            if filename_contains:
                for filename_contain in filename_contains:
                    if not filename_contain in bin_in_dir:



Changelog software url : https://docs.python.org/3/whatsnew/changelog.html

No changelog.txt.