From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 06B60138359 for ; Wed, 21 Oct 2020 00:24:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 31A68E0A64; Wed, 21 Oct 2020 00:24:05 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 29BFCE0A64 for ; Wed, 21 Oct 2020 00:24:05 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id 19so345901pge.12 for ; Tue, 20 Oct 2020 17:24:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C2iGJxG54B+74Smbz9RKXKJ+vOXKWUuakHv/k771W3k=; b=uG/7qE3pJlqX5xwTvq1s3jXuC7hfHFgK1tWWv0/OJdJ9HPAZx5j5VRTq/lkR5c+IQ5 wEmmuS/pXw2tu0zPU0gfUvD+lIqYQNN0QayUKpnuTmLrB6Dh0nUx0u/y+p+G1RnLP05o BQrC6zh/u+yoMYywJK0OoapRD9JQNEeR6Cq+UZ1UEvA+SZcri7gvdmcoNR9bARHPlqLN jOubz+2eD4ZqaJWdbLF4LVtcscZi3rdBdYt52K2QiQKMggk/Fof2haIEVqfuGNqBT1tj 8yElGa7y/HTx5lS1aj4w8aEc/YTyLhu9MI0IV2Vh72CXRUmAjZYr0pKxdb/rGTyN+yBY S0Cg== X-Gm-Message-State: AOAM532w8LW3p6DeCVTDFcAAuR2jB2x+0AuMECaS3/IcSKj5TljENz11 1UNBmEejHepKg4aWuOt9kDrJoTD7pjepUw== X-Google-Smtp-Source: ABdhPJy0tWTS6vGni2NzYuIPepNKj20hXKh44MkXbuftU/ufBGBj5sYVZYVXw020yRWaHuESbP8eVw== X-Received: by 2002:a63:5b64:: with SMTP id l36mr704279pgm.435.1603239843799; Tue, 20 Oct 2020 17:24:03 -0700 (PDT) Received: from localhost ([108.161.26.224]) by smtp.gmail.com with ESMTPSA id c17sm165897pfj.220.2020.10.20.17.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2020 17:24:03 -0700 (PDT) From: Matt Turner To: gentoo-catalyst@lists.gentoo.org Cc: Matt Turner Subject: [gentoo-catalyst] [PATCH 04/37] catalyst: Add and use sanitize_name() function Date: Tue, 20 Oct 2020 17:23:11 -0700 Message-Id: <20201021002344.378131-4-mattst88@gentoo.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201021002344.378131-1-mattst88@gentoo.org> References: <20201021002344.378131-1-mattst88@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 83c74a26-718f-4f80-b324-9eaac9b35a50 X-Archives-Hash: 9909069e14f59552a5bc978b3e6be0c1 Will be used in an additional place in a follow-on commit. Signed-off-by: Matt Turner --- catalyst/base/stagebase.py | 10 +++++----- catalyst/support.py | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index 6f5aa23a..1ccc9f04 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -16,7 +16,8 @@ from DeComp.compress import CompressMap from catalyst import log from catalyst.defaults import (confdefaults, MOUNT_DEFAULTS, PORT_LOGDIR_CLEAN) from catalyst.support import (CatalystError, file_locate, normpath, - cmd, read_makeconf, ismount, file_check) + cmd, read_makeconf, ismount, file_check, + sanitize_name) from catalyst.base.targetbase import TargetBase from catalyst.base.clearbase import ClearBase from catalyst.base.genbase import GenBase @@ -1314,10 +1315,9 @@ class StageBase(TargetBase, ClearBase, GenBase): for opt in self.settings[x]: self.env['clst_' + opt.upper()] = "true" continue - # Sanitize var names by doing "s|/-.|_|g" - varname = "clst_" + x.replace("/", "_") - varname = varname.replace("-", "_") - varname = varname.replace(".", "_") + + varname = 'clst_' + sanitize_name(x) + if isinstance(self.settings[x], str): # Prefix to prevent namespace clashes if "path" in x: diff --git a/catalyst/support.py b/catalyst/support.py index a6a6854a..f49315a5 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -256,3 +256,12 @@ def normpath(mypath): if TrailingSlash: newpath = newpath+'/' return newpath + + +def sanitize_name(name: str) -> str: + """ + Normalize name by replacing [.-/] with _, so it may be used as a + variable name in bash + """ + table = str.maketrans(".-/", "___") + return name.translate(table) -- 2.26.2