Better escaping for package file names

This commit is contained in:
Ivan Kravets
2017-06-24 16:07:40 +03:00
parent 1c5b08de59
commit 8f4c09a600
2 changed files with 26 additions and 27 deletions

View File

@ -122,16 +122,17 @@ def cli(ctx, environment, target, upload_port, project_dir, silent, verbose,
class EnvironmentProcessor(object): class EnvironmentProcessor(object):
KNOWN_OPTIONS = ( KNOWN_OPTIONS = ("platform", "framework", "board", "board_mcu",
"platform", "framework", "board", "board_mcu", "board_f_cpu", "board_f_cpu", "board_f_flash", "board_flash_mode",
"board_f_flash", "board_flash_mode", "build_flags", "src_build_flags", "build_flags", "src_build_flags", "build_unflags",
"build_unflags", "src_filter", "extra_script", "targets", "src_filter", "extra_script", "targets", "upload_port",
"upload_port", "upload_protocol", "upload_speed", "upload_flags", "upload_protocol", "upload_speed", "upload_flags",
"upload_resetmethod", "lib_deps", "lib_ignore", "lib_extra_dirs", "upload_resetmethod", "lib_deps", "lib_ignore",
"lib_ldf_mode", "lib_compat_mode", "piotest", "test_transport", "lib_extra_dirs", "lib_ldf_mode", "lib_compat_mode",
"test_ignore", "test_port", "debug_tool", "debug_port", "piotest", "test_transport", "test_ignore", "test_port",
"debug_init_cmds", "debug_extra_cmds", "debug_server", "debug_tool", "debug_port", "debug_init_cmds",
"debug_init_break", "debug_load_cmd") "debug_extra_cmds", "debug_server", "debug_init_break",
"debug_load_cmd")
IGNORE_BUILD_OPTIONS = ("test_transport", "test_ignore", "test_port", IGNORE_BUILD_OPTIONS = ("test_transport", "test_ignore", "test_port",
"debug_tool", "debug_port", "debug_init_cmds", "debug_tool", "debug_port", "debug_init_cmds",
@ -169,12 +170,13 @@ class EnvironmentProcessor(object):
self.options[k] = self.options[k].strip() self.options[k] = self.options[k].strip()
if not self.silent: if not self.silent:
click.echo("[%s] Processing %s (%s)" % ( click.echo("[%s] Processing %s (%s)" %
datetime.now().strftime("%c"), (datetime.now().strftime("%c"),
click.style(self.name, fg="cyan", bold=True), "; ".join([ click.style(self.name, fg="cyan", bold=True),
"%s: %s" % (k, v.replace("\n", ", ")) "; ".join([
for k, v in self.options.items() "%s: %s" % (k, v.replace("\n", ", "))
]))) for k, v in self.options.items()
])))
click.secho("-" * terminal_width, bold=True) click.secho("-" * terminal_width, bold=True)
self.options = self._validate_options(self.options) self.options = self._validate_options(self.options)
@ -357,9 +359,10 @@ def print_summary(results, start_time):
err=status is False) err=status is False)
print_header( print_header(
"[%s] Took %.2f seconds" % ( "[%s] Took %.2f seconds" %
(click.style("SUCCESS", fg="green", bold=True) if successed else ((click.style("SUCCESS", fg="green", bold=True)
click.style("ERROR", fg="red", bold=True)), time() - start_time), if successed else click.style("ERROR", fg="red", bold=True)),
time() - start_time),
is_error=not successed) is_error=not successed)

View File

@ -16,6 +16,7 @@ import codecs
import hashlib import hashlib
import json import json
import os import os
import re
import shutil import shutil
from os.path import basename, getsize, isdir, isfile, islink, join from os.path import basename, getsize, isdir, isfile, islink, join
from tempfile import mkdtemp from tempfile import mkdtemp
@ -126,9 +127,6 @@ class PkgRepoMixin(object):
class PkgInstallerMixin(object): class PkgInstallerMixin(object):
PATH_ESCAPE_CHARS = ("/", "\\", "?", "%", "*", ":", "|", '"', "<", ">",
".", "(", ")", "&", "#", ",", "'")
SRC_MANIFEST_NAME = ".piopkgmanager.json" SRC_MANIFEST_NAME = ".piopkgmanager.json"
FILE_CACHE_VALID = "1m" # 1 month FILE_CACHE_VALID = "1m" # 1 month
@ -192,11 +190,9 @@ class PkgInstallerMixin(object):
fu = FileUnpacker(source_path, dest_dir) fu = FileUnpacker(source_path, dest_dir)
return fu.start() return fu.start()
def get_install_dirname(self, manifest): @staticmethod
name = manifest['name'] def get_install_dirname(manifest):
for c in self.PATH_ESCAPE_CHARS: name = re.sub(r"[^\da-z\_\-\. ]", "_", manifest['name'], flags=re.I)
if c in name:
name = name.replace(c, "_")
if "id" in manifest: if "id" in manifest:
name += "_ID%d" % manifest['id'] name += "_ID%d" % manifest['id']
return name return name