Bug 911375 - Part 3: Remove PurgeManifest; r=glandium
authorGregory Szorc <gps@mozilla.com>
Mon, 16 Sep 2013 17:50:04 -0700
changeset 147353 0608e7abe1813e9a4c2104abbb7a7d2fa843d656
parent 147352 312925464acbda3fb964108c34e7408c2c06a3e3
child 147354 f24d5b2801f83f7a88b19c9a048392b656546fd0
push id86
push usergszorc@mozilla.com
push dateTue, 17 Sep 2013 00:50:43 +0000
reviewersglandium
bugs911375
milestone26.0a1
Bug 911375 - Part 3: Remove PurgeManifest; r=glandium
python/mozbuild/mozbuild/action/purge_manifests.py
python/mozbuild/mozpack/manifests.py
python/mozbuild/mozpack/test/test_manifests.py
deleted file mode 100644
--- a/python/mozbuild/mozbuild/action/purge_manifests.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# This script is used to purge a directory of unwanted files as defined by
-# a manifest file.
-
-from __future__ import print_function, unicode_literals
-
-import argparse
-import os
-import sys
-import threading
-
-from mozpack.manifests import PurgeManifest
-
-
-def do_purge(purger, dest, state):
-    state['result'] = purger.purge(dest)
-
-
-def process_manifest(topdir, manifest_path):
-    manifest = PurgeManifest(path=manifest_path)
-    purger = manifest.get_purger()
-    full = os.path.join(topdir, manifest.relpath)
-
-    state = dict(
-        relpath=manifest.relpath,
-        result=None,
-    )
-
-    t = threading.Thread(target=do_purge, args=(purger, full, state))
-    state['thread'] = t
-    t.start()
-
-    return state
-
-
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser(
-        description='Purge a directory of untracked files.')
-
-    parser.add_argument('--directory', '-d',
-        help='Directory containing manifest files. Will process every file '
-            'in directory.')
-    parser.add_argument('topdir',
-        help='Top directory all paths are evaluated from.')
-    parser.add_argument('manifests', nargs='*',
-        help='List of manifest files defining purge operations to perform.')
-
-    args = parser.parse_args()
-
-    states = []
-
-    print('Purging unaccounted files from object directory...')
-
-    # We perform purging using threads for performance reasons. Hopefully
-    # multiple I/O operations will be faster than just 1.
-    paths = []
-    if args.directory:
-        for path in sorted(os.listdir(args.directory)):
-            paths.append(os.path.join(args.directory, path))
-
-    paths.extend(args.manifests)
-
-    for path in paths:
-        states.append(process_manifest(args.topdir, path))
-
-    for state in states:
-        state['thread'].join()
-        print('Deleted %d files and %d directories from %s.' % (
-            state['result'].removed_files_count,
-            state['result'].removed_directories_count,
-            state['relpath']
-        ))
-
-    print('Finished purging.')
-
-    sys.exit(0)
--- a/python/mozbuild/mozpack/manifests.py
+++ b/python/mozbuild/mozpack/manifests.py
@@ -29,90 +29,16 @@ def _auto_fileobj(path, fileobj, mode='r
 
     try:
         yield fileobj
     finally:
         if path:
             fileobj.close()
 
 
-class UnreadablePurgeManifest(Exception):
-    """Error for failure when reading content of a serialized PurgeManifest."""
-
-
-class PurgeManifest(object):
-    """Describes actions to be used with a copier.FilePurger instance.
-
-    This class facilitates serialization and deserialization of data used
-    to construct a copier.FilePurger and to perform a purge operation.
-
-    The manifest contains a set of entries (paths that are accounted for and
-    shouldn't be purged) and a relative path. The relative path is optional and
-    can be used to e.g. have several manifest files in a directory be
-    dynamically applied to subdirectories under a common base directory.
-
-    Don't be confused by the name of this class: entries are files that are
-    *not* purged.
-    """
-    def __init__(self, relpath='', path=None, fileobj=None):
-        self.relpath = relpath
-        self.entries = set()
-
-        if not path and not fileobj:
-            return
-
-        with _auto_fileobj(path, fileobj, mode='rt') as fh:
-            self._read_from_fh(fh)
-
-    def __eq__(self, other):
-        if not isinstance(other, PurgeManifest):
-            return False
-
-        return other.relpath == self.relpath and other.entries == self.entries
-
-    def _read_from_fh(self, fileobj):
-        version = fileobj.readline().rstrip()
-        if version != '1':
-            raise UnreadablePurgeManifest('Unknown manifest version: %s' %
-                version)
-
-        self.relpath = fileobj.readline().rstrip()
-
-        for entry in fileobj:
-            self.entries.add(entry.rstrip())
-
-    def add(self, path):
-        return self.entries.add(path)
-
-    def write(self, path=None, fileobj=None):
-        with _auto_fileobj(path, fileobj, 'wt') as fh:
-            fh.write('1\n')
-            fh.write('%s\n' % self.relpath)
-
-            # We write sorted so written output is consistent.
-            for entry in sorted(self.entries):
-                fh.write('%s\n' % entry)
-
-    def get_purger(self, prepend_relpath=False):
-        """Obtain a FilePurger instance from this manifest.
-
-        If :prepend_relpath is truish, the relative path in the manifest will
-        be prepended to paths added to the FilePurger. Otherwise, the raw paths
-        will be used.
-        """
-        p = FilePurger()
-        for entry in self.entries:
-            if prepend_relpath:
-                entry = mozpath.join(self.relpath, entry)
-
-            p.add(entry)
-
-        return p
-
-
 class UnreadableInstallManifest(Exception):
     """Raised when an invalid install manifest is parsed."""
 
 
 class InstallManifest(object):
     """Describes actions to be used with a copier.FileCopier instance.
 
     This class facilitates serialization and deserialization of data used to
--- a/python/mozbuild/mozpack/test/test_manifests.py
+++ b/python/mozbuild/mozpack/test/test_manifests.py
@@ -9,53 +9,20 @@ import os
 import mozunit
 
 from mozpack.copier import (
     FileCopier,
     FileRegistry,
 )
 from mozpack.manifests import (
     InstallManifest,
-    PurgeManifest,
-    UnreadablePurgeManifest,
 )
 from mozpack.test.test_files import TestWithTmpDir
 
 
-class TestPurgeManifest(TestWithTmpDir):
-    def test_construct(self):
-        m = PurgeManifest()
-        self.assertEqual(m.relpath, '')
-        self.assertEqual(len(m.entries), 0)
-
-    def test_serialization(self):
-        m = PurgeManifest(relpath='rel')
-        m.add('foo')
-        m.add('bar')
-        p = self.tmppath('m')
-        m.write(path=p)
-
-        self.assertTrue(os.path.exists(p))
-
-        m2 = PurgeManifest(path=p)
-        self.assertEqual(m.relpath, m2.relpath)
-        self.assertEqual(m.entries, m2.entries)
-        self.assertEqual(m, m2)
-
-    def test_unknown_version(self):
-        p = self.tmppath('bad')
-
-        with open(p, 'wt') as fh:
-            fh.write('2\n')
-            fh.write('not relevant')
-
-        with self.assertRaises(UnreadablePurgeManifest):
-            PurgeManifest(path=p)
-
-
 class TestInstallManifest(TestWithTmpDir):
     def test_construct(self):
         m = InstallManifest()
         self.assertEqual(len(m), 0)
 
     def test_adds(self):
         m = InstallManifest()
         m.add_symlink('s_source', 's_dest')