refactor contents file writing to its own function
authorAviv Keshet <akeshet@chromium.org>
Fri, 12 Apr 2013 00:51:34 +0000 (17:51 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 12 Apr 2013 17:22:00 +0000 (10:22 -0700)
This CL refactors out the functionality of writing a contents dicionary
to file. That functionality is required by a change in the chromeos
chromite repository.

BUG=chromium:229234
TEST=None

Change-Id: I851724408b1d10827eee2ea8d67bdca9ad90c455

pym/portage/dbapi/vartree.py

index 9bc6e89b2d1f6a48552b794d1a602141333c205b..0d4a75608cb84d0eb6ef4da82024a342699efd79 100644 (file)
@@ -1010,12 +1010,23 @@ class vardbapi(dbapi):
                                removed += 1
 
                if removed:
-                       self._bump_mtime(pkg.mycpv)
-                       f = atomic_ofstream(os.path.join(pkg.dbdir, "CONTENTS"))
-                       write_contents(new_contents, root, f)
-                       f.close()
-                       self._bump_mtime(pkg.mycpv)
-                       pkg._clear_contents_cache()
+                       self.writeContentsToContentsFile(pkg, new_contents)
+
+       def writeContentsToContentsFile(self, pkg, new_contents):
+               """
+               @param pkg: package to write contents file for
+               @type pkg: dblink
+               @param new_contents: contents to write to CONTENTS file
+               @type new_contents: contents dictionary of the form
+                                       {u'/path/to/file' : (contents_attribute 1, ...), ...}
+               """
+               root = self.settings['ROOT']
+               self._bump_mtime(pkg.mycpv)
+               f = atomic_ofstream(os.path.join(pkg.dbdir, "CONTENTS"))
+               write_contents(new_contents, root, f)
+               f.close()
+               self._bump_mtime(pkg.mycpv)
+               pkg._clear_contents_cache()
 
        class _owners_cache(object):
                """