diff options
author | Zac Medico <zmedico@gentoo.org> | 2006-04-15 11:17:43 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2006-04-15 11:17:43 +0000 |
commit | ca12cd6a5114f2fa9a7009768a78e610762ad350 (patch) | |
tree | a1108d6e782eae5c1f2e6959915d4ef73f1e3acc | |
parent | 5210ef39ff48f5701a837931881680e65aebf716 (diff) | |
download | portage-ca12cd6a5114f2fa9a7009768a78e610762ad350.tar.gz portage-ca12cd6a5114f2fa9a7009768a78e610762ad350.tar.bz2 portage-ca12cd6a5114f2fa9a7009768a78e610762ad350.zip |
Split out a reusable Manifest._readManifest() method.
svn path=/main/trunk/; revision=3150
-rw-r--r-- | pym/portage_manifest.py | 41 |
1 files 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: |