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 F3DE7138359 for ; Thu, 29 Oct 2020 16:16:39 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2C284E0951; Thu, 29 Oct 2020 16:16:39 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (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 DE4C9E0951 for ; Thu, 29 Oct 2020 16:16:38 +0000 (UTC) Received: by mail-qk1-f176.google.com with SMTP id r7so2428588qkf.3 for ; Thu, 29 Oct 2020 09:16:38 -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:mime-version :content-transfer-encoding; bh=zKuTx62/ockxo05dD09YHrfsnx3mSWFbM4po89K211Q=; b=Kh9X4bBPLA+gih1sPJEi7w8HW6mnZ3Gu0kbae/8Lw1Uqg3NnccqHFQS+W0lxMl5sAX 2x8XVVzHUgxndOATE6hISiRE/Hjg6QWLYfwDO3X/LCgJS5ozXf+5QOicVKl+TzCr4nIw U3u1Hy1MOz+klggFA2WxCR/HGjsISxnsRmg0OwX8xj+ylHvpn5k8tfqXPxnw6TQHDAlc Q1uCoFijF61WWARZ4ewLR+zZG0Eh5Wm0JZ9Hr9G6GeCGCAxLD8FkLb4SjSjdkjauIOjf g7oZ45Az1QWYj1yazhKXGLr2nInhFMKA/VYulGc69nmfEFrhDK3BLtXTEH3Tw62srJVf VhcA== X-Gm-Message-State: AOAM532Ghc0SV7A13GXgiW7CiPM6sQQMjPNzZa8mBwFfcW3idwwf2NUU qqWl0c7VOoZxC9HpB8yBUHlVsO6OVKE= X-Google-Smtp-Source: ABdhPJxsOwO/7kSbxwnc2JZiOgCCPSUPIodUutKn6XGpsy8t9U5691+nqLMMReXXzgrtmrMO916XMg== X-Received: by 2002:a37:2c03:: with SMTP id s3mr4290930qkh.91.1603988197678; Thu, 29 Oct 2020 09:16:37 -0700 (PDT) Received: from localhost (2606-a000-131c-10bb-0000-0000-0000-1fc3.inf6.spectrum.com. [2606:a000:131c:10bb::1fc3]) by smtp.gmail.com with ESMTPSA id 19sm1315642qkf.93.2020.10.29.09.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 09:16:36 -0700 (PDT) From: Matt Turner To: gentoo-catalyst@lists.gentoo.org Cc: Matt Turner Subject: [gentoo-catalyst] [PATCH 01/12] catalyst: Replace pathcompare() Date: Thu, 29 Oct 2020 12:16:21 -0400 Message-Id: <20201029161632.146732-1-mattst88@gentoo.org> X-Mailer: git-send-email 2.26.2 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: 9ebd4c8e-052e-4eca-81c7-9524d0755293 X-Archives-Hash: 9d1cfbb15b005d590b07313d7025f70b Modern Python allows us to do this in a much cleaner way. Signed-off-by: Matt Turner --- catalyst/support.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/catalyst/support.py b/catalyst/support.py index f49315a5..4458ed20 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -5,6 +5,7 @@ import os import re import shutil import time +from pathlib import Path from subprocess import Popen from catalyst import log @@ -179,31 +180,20 @@ def read_makeconf(mymakeconffile): return makeconf -def pathcompare(path1, path2): - # Change double slashes to slash - path1 = re.sub(r"//", r"/", path1) - path2 = re.sub(r"//", r"/", path2) - # Removing ending slash - path1 = re.sub("/$", "", path1) - path2 = re.sub("/$", "", path2) - - if path1 == path2: - return 1 - return 0 - - def ismount(path): """Like os.path.ismount, but also support bind mounts""" if os.path.ismount(path): - return 1 + return True + a = os.popen("mount") mylines = a.readlines() a.close() for line in mylines: mysplit = line.split() - if pathcompare(path, mysplit[2]): - return 1 - return 0 + if Path(path) == Path(mysplit[2]): + return True + + return False def addl_arg_parse(myspec, addlargs, requiredspec, validspec): -- 2.26.2