From 81fdd75aaca88a896dbec98486b9bab159d2f873 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 12 Apr 2022 12:30:49 +0300 Subject: [PATCH] Report problematic file before publishing package to the registry --- platformio/package/commands/publish.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/platformio/package/commands/publish.py b/platformio/package/commands/publish.py index 69b1ac63..150fdb19 100644 --- a/platformio/package/commands/publish.py +++ b/platformio/package/commands/publish.py @@ -13,6 +13,7 @@ # limitations under the License. import os +import tarfile import tempfile from datetime import datetime @@ -111,6 +112,9 @@ def package_publish_cmd( # pylint: disable=too-many-arguments, too-many-locals data.insert(len(data) - 1, ("System:", ", ".join(manifest.get("system")))) click.echo(tabulate(data, tablefmt="plain")) + # check files containing non-ascii chars + check_archive_file_names(archive_path) + # look for duplicates check_package_duplicates(owner, type_, name, version, manifest.get("system")) @@ -141,6 +145,17 @@ def package_publish_cmd( # pylint: disable=too-many-arguments, too-many-locals click.secho(response.get("message"), fg="green") +def check_archive_file_names(archive_path): + with tarfile.open(archive_path, mode="r:gz") as tf: + for name in tf.getnames(): + if not name.isascii(): + click.secho( + f"Warning! The `{name}` file contains non-ASCII chars and can " + "lead to the unpacking issues on a user machine", + fg="yellow", + ) + + def check_package_duplicates( owner, type, name, version, system ): # pylint: disable=redefined-builtin