Page 1 sur 1

[RESOLU] Paquet Arduino

Publié : 15 déc. 2021 - 08:37
par olaplanche
Bonjour,

Changelog du 24/03/2022 :
- Correction de la fonction def install(): qui ne pouvait pas fonctionner en l'état !

Je partage mon paquet pour le logiciel Arduino que je viens de réaliser :

Fichier control :

Code : Tout sélectionner

package           : wapt-arduino
version           : 1.8.16-2
architecture      : all
section           : base
priority          : optional
name              :
categories        :
maintainer        : olaplanche
description       : Arduino IDE
depends           :
conflicts         :
maturity          : PROD
locale            :
target_os         : windows
min_wapt_version  :
sources           : https://www.arduino.cc/en/software
installed_size    :
impacted_process  : arduino
description_fr    :
description_pl    :
description_de    :
description_es    :
description_pt    :
description_it    :
description_nl    :
description_ru    :
audit_schedule    :
editor            : Arduino.cc
keywords          :
licence           :
homepage          : www.arduino.cc
package_uuid      : 
valid_from        :
valid_until       :
forced_install_on :
changelog         :
min_os_version    :
max_os_version    :
icon_sha256sum    :
Fichier setup :

Code : Tout sélectionner

# -*- coding: utf-8 -*-
from setuphelpers import *
import platform

"""
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_name_string = 'arduino-%s-windows.exe'


def install():
    # Declaring local variables
    package_version = control.get_software_version()
    bin_name = bin_name_string % package_version
    impacted_process = control.impacted_process.split(",")

    # Installing the software
    print("Installing: %s" % bin_name)
    install_exe_if_needed(bin_name,
        silentflags='/S',
        key='Arduino',
        min_version=package_version,
        killbefore=impacted_process,
    )

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 = control.sources

    # Getting latest version from official website
    version_temp = bs_find_all(url, 'span', 'class', 'download-title',proxies=proxies)[0].string
    version = version_temp[-6:]
    latest_bin = bin_name_string % version
    download_url = 'https://downloads.arduino.cc/arduino-%s-windows.exe' % version

    print("Latest %s version is: %s" % (app_name, version))
    print("Download URL is: %s" % download_url)

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

        # Checking version from file
        version_from_file = get_version_from_binary(latest_bin)
        if not version_from_file.startswith(version) 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 + ends_bin_name)
            version = version_from_file
        else:
            print("Binary file version corresponds to online version")

    # 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
    else:
        print("Software version up-to-date (%s)" % Version(version))
    control.version = '%s-%s' % (Version(version), control.version.split('-', 1)[-1])
    #control.set_software_version(version)
    control.save_control_to_wapt()

    # Deleting outdated binaries
    remove_outdated_binaries(version)

    # Validating update-package-sources
    return result

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


def get_version_from_binary(filename):
    if filename.endswith('.msi'):
        return get_msi_properties(filename)['ProductVersion']
    else:
        return get_file_properties(filename)['ProductVersion']


def remove_outdated_binaries(version, list_extensions=['exe','msi','deb','rpm','dmg','pkg'], list_filename_contain=None):
    if type(list_extensions) != list:
        list_extensions = [list_extensions]
    if list_filename_contain:
        if type(list_filename_contain) != list:
            list_filename_contain = [list_filename_contain]
    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:
                remove_file(bin_in_dir)
            if list_filename_contain:
                for filename_contain in list_filename_contain:
                    if not filename_contain in bin_in_dir:
                        remove_file(bin_in_dir)

def get_proxies_from_wapt_console():
    proxies = {}
    if platform.system() == 'Windows':
        waptconsole_ini_path = makepath(user_local_appdata(), 'waptconsole', 'waptconsole.ini')
    else:
        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 uninstall():
    print("Uninstalling: %s" % control.package)
    run(r'"%s\Arduino\uninstall.exe" /s' % programfiles32)

Re: [RESOLU] Paquet Arduino

Publié : 16 déc. 2021 - 14:43
par olaplanche
haha la version 1.8.16 d'arduino est impactée par la faille log4shell (https://support.arduino.cc/hc/en-us/art ... 2021-44228), je suis bien content d'avoir la fonction update_package pour mettre à jour vers la version 1.8.18 en 4 clics :D

Re: [RESOLU] Paquet Arduino

Publié : 10 mai 2022 - 10:03
par gaelds
Merci pour ce paquet ! Il s'installe bien, mais la fonction update-package-sources me donne cette erreur :

Code : Tout sélectionner

Ligne de Commande : update-package-sources "C:\waptdev\dst-arduino-windows-wapt\WAPT\.."
Using config file: C:\Users\informatique\AppData\Local\waptconsole\waptconsole.ini
2022-05-10 10:02:29,368 CRITICAL Fatal error in update_package function: NameError: global name 'bs_find_all' is not defined:
Traceback (most recent call last):
  File "C:\Program Files (x86)\wapt\waptpackage.py", line 2449, in call_setup_hook
    hookdata = hook_func()
  File "C:\waptdev\dst-arduino-windows-wapt\setup.py", line 44, in update_package
    version_temp = bs_find_all(url, 'span', 'class', 'download-title',proxies=proxies)[0].string
NameError: global name 'bs_find_all' is not defined

FATAL ERROR : NameError: global name 'bs_find_all' is not defined
Exit code:  3
>>> 

Re: [RESOLU] Paquet Arduino

Publié : 10 mai 2022 - 17:42
par dcardon
quelle version de WAPT (cf. forum rules above)?

Re: [RESOLU] Paquet Arduino

Publié : 11 mai 2022 - 09:38
par olaplanche
Bonjour,

La fonction bs_find_all est définie dans le fichier setuphelper depuis je ne sais pas quelle version :D
Il faut sans doute chercher de ce côté là !