From ca12cd6a5114f2fa9a7009768a78e610762ad350 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 15 Apr 2006 11:17:43 +0000 Subject: [PATCH] Split out a reusable Manifest._readManifest() method. svn path=/main/trunk/; revision=3150 --- pym/portage_manifest.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/pym/portage_manifest.py b/pym/portage_manifest.py index 50d061ecc..96abc7503 100644 --- a/pym/portage_manifest.py +++ b/pym/portage_manifest.py @@ -74,30 +74,41 @@ class Manifest(object): """ Similar to getDigests(), but restricted to files of the given type. """ return self.fhashdict[ftype] - def _readDigests(self): + def _readDigests(self, myhashdict=None): """ Parse old style digest files for this Manifest instance """ - mycontent = "" + if myhashdict is None: + myhashdict = {} for d in os.listdir(os.path.join(self.pkgdir, "files")): if d.startswith("digest-"): - f = open(os.path.join(self.pkgdir, "files", d), "r") - mycontent += f.read() - f.close() - return mycontent - - def _read(self): - """ Parse Manifest file for this instance """ - mylines = [] + self._readManifest(os.path.join(self.pkgdir, "files", d), + myhashdict=myhashdict) + return myhashdict + + def _readManifest(self, file_path, myhashdict=None): + """Parse a manifest or an old style digest. If myhashdict is given + then data will be added too it. Otherwise, a new dict will be created + and returned.""" try: - fd = open(self.getFullname(), "r") - mylines.extend(fd.readlines()) + fd = open(file_path, "r") + if myhashdict is None: + myhashdict = {} + mylines = fd.readlines() fd.close() + self._parseDigests(mylines, myhashdict=myhashdict) + return myhashdict except (OSError, IOError), e: if e.errno == errno.ENOENT: - pass + raise FileNotFound(file_path) else: raise - mylines.extend(self._readDigests().split("\n")) - self._parseDigests(mylines, myhashdict=self.fhashdict) + + def _read(self): + """ Parse Manifest file for this instance """ + try: + self._readManifest(self.getFullname(), myhashdict=self.fhashdict) + except FileNotFound: + pass + self._readDigests(myhashdict=self.fhashdict) def _parseDigests(self, mylines, myhashdict=None): if myhashdict is None: -- 2.26.2