[SOLVED] Arduino Package

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 15, 2021 - 8:37 AM

Good morning,

Changelog of 24/03/2022:
- Correction of the def install() function: which could not work in its current state!

I'm sharing my package for the Arduino software I just created:

Control file:

Code: Select all

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    :
Setup file:

Code: Select all

# -*- 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)
Last edited by olaplanche on March 24, 2022 - 09:01, edited 2 times.
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

December 16, 2021 - 2:43 PM

Haha, Arduino version 1.8.16 is affected by the log4shell vulnerability (https://support.arduino.cc/hc/en-us/art ... 2021-44228). I'm really glad to have the update_package function to update to version 1.8.18 in 4 clicks. :D
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
Gaelds
Messages: 254
Registration: Nov 22, 2015 - 08:37

May 10, 2022 - 10:03

Thanks for this package! It installs fine, but the update-package-sources function gives me this error:

Code: Select all

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
>>> 
User avatar
dcardon
WAPT Expert
Messages: 1932
Registration: June 18, 2014 - 09:58
Location: Saint Sébastien sur Loire
Contact :

May 10, 2022 - 5:42 PM

Which version of WAPT (see forum rules above)?
Denis Cardon - Tranquil IT
Share your experiences on WAPT! Send us your blog and article URLs in the "Your Opinion of the forum, and we'll feature them on the WAPT
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

May 11, 2022 - 09:38

Hello,

the bs_find_all function is defined in the setuphelper file since I don't know which version :D
. We should probably look there!
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
Locked