public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/
Date: Mon,  4 Apr 2022 19:04:58 +0000 (UTC)	[thread overview]
Message-ID: <1649099085.64d84ce2d9a333e83e2a5fba5e7ec95f936959e7.sam@gentoo> (raw)

commit:     64d84ce2d9a333e83e2a5fba5e7ec95f936959e7
Author:     Kenneth Raplee <kenrap <AT> kennethraplee <DOT> com>
AuthorDate: Sat Apr  2 01:32:42 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Apr  4 19:04:45 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=64d84ce2

Miscellaneous refactors and cleanups

Signed-off-by: Kenneth Raplee <kenrap <AT> kennethraplee.com>
Closes: https://github.com/gentoo/portage/pull/798
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/manifest.py | 89 +++++++++++++++++++++++++------------------------
 lib/portage/news.py     |  9 +++--
 lib/portage/output.py   |  2 +-
 3 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/lib/portage/manifest.py b/lib/portage/manifest.py
index 655eabf68..eb3695669 100644
--- a/lib/portage/manifest.py
+++ b/lib/portage/manifest.py
@@ -83,13 +83,13 @@ def parseManifest2(line):
     if not isinstance(line, str):
         line = " ".join(line)
     myentry = None
-    match = _manifest_re.match(line)
-    if match is not None:
-        tokens = match.group(3).split()
+    matched = _manifest_re.match(line)
+    if matched:
+        tokens = matched.group(3).split()
         hashes = dict(zip(tokens[1::2], tokens[2::2]))
         hashes["size"] = int(tokens[0])
         myentry = Manifest2Entry(
-            type=match.group(1), name=match.group(2), hashes=hashes
+            type=matched.group(1), name=matched.group(2), hashes=hashes
         )
     return myentry
 
@@ -274,19 +274,21 @@ class Manifest:
 
     def _createManifestEntries(self):
         valid_hashes = set(itertools.chain(get_valid_checksum_keys(), ("size")))
-        mytypes = list(self.fhashdict)
-        mytypes.sort()
-        for t in mytypes:
-            myfiles = list(self.fhashdict[t])
-            myfiles.sort()
-            for f in myfiles:
-                myentry = Manifest2Entry(
-                    type=t, name=f, hashes=self.fhashdict[t][f].copy()
+        mytypes = sorted(self.fhashdict)
+        for mytype in mytypes:
+            myfiles = sorted(self.fhashdict[mytype])
+            for myfile in myfiles:
+                remainings = set(self.fhashdict[mytype][myfile]).intersection(
+                    valid_hashes
+                )
+                yield Manifest2Entry(
+                    type=mytype,
+                    name=myfile,
+                    hashes={
+                        remaining: self.fhashdict[mytype][myfile][remaining]
+                        for remaining in remainings
+                    },
                 )
-                for h in list(myentry.hashes):
-                    if h not in valid_hashes:
-                        del myentry.hashes[h]
-                yield myentry
 
     def checkIntegrity(self):
         manifest_data = (
@@ -320,7 +322,7 @@ class Manifest:
             preserved_stats = {self.pkgdir.rstrip(os.sep): os.stat(self.pkgdir)}
             if myentries and not force:
                 try:
-                    f = io.open(
+                    with io.open(
                         _unicode_encode(
                             self.getFullname(),
                             encoding=_encodings["fs"],
@@ -329,16 +331,15 @@ class Manifest:
                         mode="r",
                         encoding=_encodings["repo.content"],
                         errors="replace",
-                    )
-                    oldentries = list(self._parseManifestLines(f))
-                    preserved_stats[self.getFullname()] = os.fstat(f.fileno())
-                    f.close()
-                    if len(oldentries) == len(myentries):
-                        update_manifest = False
-                        for i in range(len(oldentries)):
-                            if oldentries[i] != myentries[i]:
-                                update_manifest = True
-                                break
+                    ) as f:
+                        oldentries = list(self._parseManifestLines(f))
+                        preserved_stats[self.getFullname()] = os.fstat(f.fileno())
+                        if len(oldentries) == len(myentries):
+                            update_manifest = False
+                            for oldentry, myentry in zip(oldentries, myentries):
+                                if oldentry != myentry:
+                                    update_manifest = True
+                                    break
                 except (IOError, OSError) as e:
                     if e.errno == errno.ENOENT:
                         pass
@@ -463,16 +464,17 @@ class Manifest:
 
     def addFile(self, ftype, fname, hashdict=None, ignoreMissing=False):
         """Add entry to Manifest optionally using hashdict to avoid recalculation of hashes"""
-        if ftype == "AUX" and not fname.startswith("files/"):
-            fname = os.path.join("files", fname)
-        if not os.path.exists(self.pkgdir + fname) and not ignoreMissing:
+        if ftype == "AUX":
+            if not fname.startswith("files/"):
+                fname = os.path.join("files", fname)
+            if fname.startswith("files"):
+                fname = fname[6:]
+        if not os.path.exists(f"{self.pkgdir}{fname}") and not ignoreMissing:
             raise FileNotFound(fname)
-        if not ftype in MANIFEST2_IDENTIFIERS:
+        if ftype not in MANIFEST2_IDENTIFIERS:
             raise InvalidDataType(ftype)
-        if ftype == "AUX" and fname.startswith("files"):
-            fname = fname[6:]
         self.fhashdict[ftype][fname] = {}
-        if hashdict != None:
+        if hashdict is not None:
             self.fhashdict[ftype][fname].update(hashdict)
         if self.required_hashes.difference(set(self.fhashdict[ftype][fname])):
             self.updateFileHashes(
@@ -497,7 +499,7 @@ class Manifest:
         checkExisting=False,
         assumeDistHashesSometimes=False,
         assumeDistHashesAlways=False,
-        requiredDistfiles=[],
+        requiredDistfiles=None,
     ):
         """Recreate this Manifest from scratch.  This will not use any
         existing checksums unless assumeDistHashesSometimes or
@@ -511,10 +513,9 @@ class Manifest:
             return
         if checkExisting:
             self.checkAllHashes()
+        distfilehashes = {}
         if assumeDistHashesSometimes or assumeDistHashesAlways:
-            distfilehashes = self.fhashdict["DIST"]
-        else:
-            distfilehashes = {}
+            distfilehashes.update(self.fhashdict["DIST"])
         self.__init__(
             self.pkgdir,
             distdir=self.distdir,
@@ -624,7 +625,7 @@ class Manifest:
                 f = _unicode_decode(f, encoding=_encodings["fs"], errors="strict")
             except UnicodeDecodeError:
                 continue
-            if f[:1] == ".":
+            if f.startswith("."):
                 continue
             pf = self._is_cpv(cat, pn, f)
             if pf is not None:
@@ -640,7 +641,7 @@ class Manifest:
         recursive_files = []
 
         pkgdir = self.pkgdir
-        cut_len = len(os.path.join(pkgdir, "files") + os.sep)
+        cut_len = len(os.path.join(pkgdir, "files", os.sep))
         for parentdir, dirs, files in os.walk(os.path.join(pkgdir, "files")):
             for f in files:
                 try:
@@ -662,12 +663,12 @@ class Manifest:
 
     def _getAbsname(self, ftype, fname):
         if ftype == "DIST":
-            absname = os.path.join(self.distdir, fname)
+            abspath = (self.distdir, fname)
         elif ftype == "AUX":
-            absname = os.path.join(self.pkgdir, "files", fname)
+            abspath = (self.pkgdir, "files", fname)
         else:
-            absname = os.path.join(self.pkgdir, fname)
-        return absname
+            abspath = (self.pkgdir, fname)
+        return os.path.join(*abspath)
 
     def checkAllHashes(self, ignoreMissingFiles=False):
         for t in MANIFEST2_IDENTIFIERS:

diff --git a/lib/portage/news.py b/lib/portage/news.py
index 801edb68c..132e050f2 100644
--- a/lib/portage/news.py
+++ b/lib/portage/news.py
@@ -80,7 +80,7 @@ class NewsManager:
         portdir = portdb.repositories.mainRepoLocation()
         profiles_base = None
         if portdir is not None:
-            profiles_base = os.path.join(portdir, "profiles") + os.path.sep
+            profiles_base = os.path.join(portdir, "profiles", os.path.sep)
         profile_path = None
         if profiles_base is not None and portdb.settings.profile_path:
             profile_path = normalize_path(
@@ -295,14 +295,13 @@ class NewsItem:
         return self._valid
 
     def parse(self):
-        f = io.open(
+        with io.open(
             _unicode_encode(self.path, encoding=_encodings["fs"], errors="strict"),
             mode="r",
             encoding=_encodings["content"],
             errors="replace",
-        )
-        lines = f.readlines()
-        f.close()
+        ) as f:
+            lines = f.readlines()
         self.restrictions = {}
         invalids = []
         news_format = None

diff --git a/lib/portage/output.py b/lib/portage/output.py
index 565f782ff..c7922038e 100644
--- a/lib/portage/output.py
+++ b/lib/portage/output.py
@@ -35,8 +35,8 @@ from portage.localization import _
 havecolor = 1
 dotitles = 1
 
-_styles = {}
 """Maps style class to tuple of attribute names."""
+_styles = {}
 
 """Maps attribute name to ansi code."""
 


             reply	other threads:[~2022-04-04 19:05 UTC|newest]

Thread overview: 147+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 19:04 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-01-11 16:01 [gentoo-commits] proj/portage:master commit in: lib/portage/ Mike Gilbert
2025-01-11 16:01 Mike Gilbert
2025-01-01  0:33 Zac Medico
2024-11-02 22:12 Zac Medico
2024-11-02 15:48 Zac Medico
2024-11-02 15:48 Zac Medico
2024-09-09 18:08 Ulrich Müller
2024-09-09 18:08 Ulrich Müller
2024-08-14 15:22 Zac Medico
2024-06-09 17:54 Zac Medico
2024-06-02 18:28 Zac Medico
2024-04-26 22:06 Sam James
2024-04-26 22:06 Sam James
2024-02-28 16:01 Sam James
2024-02-28 15:52 Sam James
2024-02-28 15:49 Sam James
2024-02-25  8:25 Sam James
2024-02-24 20:10 Zac Medico
2024-02-21  2:08 Sam James
2024-02-21  2:08 Sam James
2024-02-12  7:58 Zac Medico
2024-02-11 19:57 Zac Medico
2024-02-10  6:09 Zac Medico
2024-02-10  6:06 Zac Medico
2024-02-09  8:51 Sam James
2024-02-09  7:08 Sam James
2024-02-07  2:35 Zac Medico
2024-02-07  2:35 Zac Medico
2024-02-05  1:03 Zac Medico
2024-02-05  1:03 Zac Medico
2024-01-29 17:49 Zac Medico
2024-01-29 16:09 Zac Medico
2023-12-26 23:15 Zac Medico
2023-11-02 14:58 Zac Medico
2023-10-24 21:26 Zac Medico
2023-10-24  1:48 Zac Medico
2023-10-03 15:07 Zac Medico
2023-10-02  2:10 Zac Medico
2023-09-26  5:53 Zac Medico
2023-09-08 20:36 Sam James
2023-09-08 19:49 Sam James
2023-08-24 18:23 Mike Gilbert
2023-08-02  6:31 Sam James
2023-07-29  3:57 Sam James
2023-06-29  8:22 Sam James
2023-03-21  2:30 Sam James
2023-03-21  2:30 Sam James
2023-03-21  2:30 Sam James
2023-03-21  2:30 Sam James
2023-03-21  2:30 Sam James
2023-03-21  2:30 Sam James
2023-02-27  6:15 Sam James
2023-02-17  1:23 Sam James
2023-01-02  5:25 Sam James
2022-11-02 22:58 Sam James
2022-11-02 22:58 Sam James
2022-09-29 21:37 Sam James
2022-09-29 20:45 Sam James
2022-09-28 23:56 Sam James
2022-09-26 17:52 Zac Medico
2022-09-20 19:45 Sam James
2022-09-20  3:39 Sam James
2022-09-18 18:30 Mike Gilbert
2022-08-01 22:39 Sam James
2022-08-01 17:34 Mike Gilbert
2022-07-19 21:39 Sam James
2022-07-18 18:47 Sam James
2022-07-11 23:02 Sam James
2022-07-10 15:07 Mike Gilbert
2022-07-05 22:56 Sam James
2022-06-05 20:25 Zac Medico
2022-04-11 12:11 Mike Gilbert
2022-04-11 12:11 Mike Gilbert
2022-04-09  4:32 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-04 19:04 Sam James
2022-04-01 20:30 Matt Turner
2022-03-30 23:11 Sam James
2022-03-28  1:10 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-27 23:07 Sam James
2022-03-15  2:52 Matt Turner
2022-02-09 11:13 Sam James
2021-09-20 20:06 Zac Medico
2021-09-20 19:55 Mike Gilbert
2021-09-07  7:04 Michał Górny
2021-09-04 11:53 Michał Górny
2021-05-24  6:08 Zac Medico
2021-05-24  4:55 Zac Medico
2021-03-28  3:33 Zac Medico
2021-03-11 12:32 Zac Medico
2021-03-07 14:03 Zac Medico
2021-03-06  9:18 Zac Medico
2021-03-06  9:05 Zac Medico
2021-03-06  9:05 Zac Medico
2021-03-06  8:20 Zac Medico
2021-03-06  6:16 Zac Medico
2021-02-08  4:55 Zac Medico
2020-09-11 19:02 Zac Medico
2020-08-04  1:39 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-08-03 19:30 Zac Medico
2020-06-27 19:46 Zac Medico
2020-06-09  0:58 Zac Medico
2020-05-17  9:37 Michał Górny
2020-05-07 20:35 Zac Medico
2020-04-20 21:16 Mike Gilbert
2020-03-28 18:57 Michał Górny
2020-03-25 19:18 Zac Medico
2020-03-25  7:57 Zac Medico
2020-03-25  7:57 Zac Medico
2020-02-04  6:43 Zac Medico
2020-02-02  9:00 Zac Medico
2019-12-15 23:04 Zac Medico
2019-11-12 22:25 Zac Medico
2019-09-17  2:59 Zac Medico
2019-09-07  6:40 Zac Medico
2019-08-18 22:15 Zac Medico
2019-08-04 18:03 Zac Medico
2019-08-02 20:03 Mike Gilbert
2019-08-01 19:02 Mike Gilbert
2019-05-28  1:49 Zac Medico
2019-04-27 19:20 Zac Medico
2019-02-20  0:58 Zac Medico
2019-02-20  0:58 Zac Medico
2019-02-20  0:58 Zac Medico
2019-02-18  1:01 Zac Medico
2019-02-11 19:46 Zac Medico
2019-01-04  3:49 Zac Medico
2018-12-31  5:27 Zac Medico
2018-12-04  1:35 Zac Medico
2018-11-25  0:03 Zac Medico
2018-11-24 21:34 Zac Medico
2018-08-07 18:36 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1649099085.64d84ce2d9a333e83e2a5fba5e7ec95f936959e7.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox