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 BE988138351 for ; Fri, 17 Apr 2020 19:52:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0F7B7E08CA; Fri, 17 Apr 2020 19:52:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (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 D36E6E08CA for ; Fri, 17 Apr 2020 19:52:30 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C216034F15B for ; Fri, 17 Apr 2020 19:52:29 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D01381E3 for ; Fri, 17 Apr 2020 19:52:26 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1587149718.f0e78af28a5e1c6275cd5b6b3f8c602e7fd16f7f.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/genbase.py X-VCS-Directories: catalyst/base/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: f0e78af28a5e1c6275cd5b6b3f8c602e7fd16f7f X-VCS-Branch: master Date: Fri, 17 Apr 2020 19:52:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 12013293-222b-4825-94d7-34cc7ecae4ea X-Archives-Hash: 9fc7de24edb93a7ac1a9dc95b6037421 commit: f0e78af28a5e1c6275cd5b6b3f8c602e7fd16f7f Author: Matt Turner gentoo org> AuthorDate: Fri Apr 17 17:17:49 2020 +0000 Commit: Matt Turner gentoo org> CommitDate: Fri Apr 17 18:55:18 2020 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=f0e78af2 catalyst: Simplify GenBase So much was wrong with this code. Deleting a file if it exists only to open it with 'w' (which would have truncated it anyway!), checking for presence of files that must exist and doing it in the wrong place, etc. Signed-off-by: Matt Turner gentoo.org> catalyst/base/genbase.py | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/catalyst/base/genbase.py b/catalyst/base/genbase.py index 632ee0d9..bc7f9375 100644 --- a/catalyst/base/genbase.py +++ b/catalyst/base/genbase.py @@ -3,10 +3,9 @@ import hashlib import io import os - class GenBase(): """ - This class does generation of the contents and digests files. + Generates CONTENTS and DIGESTS files. """ def __init__(self, myspec): @@ -27,27 +26,16 @@ class GenBase(): return f'# {name.upper()} HASH\n{h.hexdigest()} {filename}\n' def gen_contents_file(self, path): - contents = path + ".CONTENTS" - if os.path.exists(contents): - os.remove(contents) - - contents_map = self.settings["contents_map"] - if os.path.exists(path): - with io.open(contents, "w", encoding='utf-8') as myf: - contents = contents_map.contents(path, '', - verbose=self.settings["VERBOSE"]) - if contents: - myf.write(contents) + c = self.settings['contents_map'] + + with io.open(path + '.CONTENTS', 'w', encoding='utf-8') as file: + file.write(c.contents(path, '', verbose=self.settings['VERBOSE'])) def gen_digest_file(self, path): - digests = path + ".DIGESTS" - if os.path.exists(digests): - os.remove(digests) - if "digests" in self.settings: - if os.path.exists(path): - with io.open(digests, "w", encoding='utf-8') as myf: - for f in [path, path + '.CONTENTS']: - if os.path.exists(f): - for i in self.settings["digests"].split(): - digest = self.generate_hash(f, name=i) - myf.write(digest) + if 'digests' not in self.settings: + return + + with io.open(path + '.DIGESTS', 'w', encoding='utf-8') as file: + for f in [path, path + '.CONTENTS']: + for i in self.settings['digests'].split(): + file.write(self.generate_hash(f, name=i))