Subject: [PATCH] Remove incomplete MANIFEST support

From: Bernie Innocenti <[email-masked]>
Date: Thu, 20 May 2010 02:19:14 -0400

This incomplete feature contributes to confuse new activity authors and
slightly complicates our bundle installation logic.

The day someone finds something useful to do with the MANIFEST
specification, we can revert this patch in no time.

Signed-off-by: Bernie Innocenti <[email-masked]>
Tested-by: Bernie Innocenti <[email-masked]>
---
 src/sugar/activity/bundlebuilder.py |   48 ++---------------
 src/sugar/bundle/activitybundle.py  |   99 +----------------------------------
 src/sugar/bundle/bundle.py          |    9 ---
 3 files changed, 6 insertions(+), 150 deletions(-)

diff --git a/src/sugar/activity/bundlebuilder.py b/src/sugar/activity/bundlebuilder.py
index 868ca3d..630a3e4 100644
--- a/src/sugar/activity/bundlebuilder.py
+++ b/src/sugar/activity/bundlebuilder.py
@@ -141,37 +141,9 @@ class Builder(object):
             f.close()
 
     def get_files(self):
-        files = self.config.bundle.get_files()
-
-        if not files:
-            logging.error('No files found, fixing the MANIFEST.')
-            self.fix_manifest()
-            files = self.config.bundle.get_files()
-
-        return files
-
-    def check_manifest(self):
-        missing_files = []
-
         allfiles = list_files(self.config.source_dir,
                               IGNORE_DIRS, IGNORE_FILES)
-        for path in allfiles:
-            if path not in self.config.bundle.manifest:
-                missing_files.append(path)
-
-        return missing_files
-
-    def fix_manifest(self):
-        self.build()
-
-        manifest = self.config.bundle.manifest
-
-        for path in self.check_manifest():
-            manifest.append(path)
-
-        f = open(os.path.join(self.config.source_dir, "MANIFEST"), "wb")
-        for line in manifest:
-            f.write(line + "\n")
+        return allfiles

 class Packager(object):
@@ -197,13 +169,6 @@ class XOPackager(Packager):
         bundle_zip = zipfile.ZipFile(self.package_path, 'w',
                                      zipfile.ZIP_DEFLATED)
 
-        missing_files = self.builder.check_manifest()
-        if missing_files:
-            logging.warn('These files are not included in the manifest ' \
-                         'and will not be present in the bundle:\n\n' +
-                         '\n'.join(missing_files) +
-                         '\n\nUse fix_manifest if you want to add them.')
-
         for f in self.builder.get_files():
             bundle_zip.write(os.path.join(self.config.source_dir, f),
                              os.path.join(self.config.bundle_root_dir, f))
@@ -307,14 +272,11 @@ def cmd_dist_xo(config, args):

 def cmd_fix_manifest(config, args):
-    '''Add missing files to the manifest'''
+    '''Add missing files to the manifest (OBSOLETE)'''
 
-    if args:
-        print 'Usage: %prog fix_manifest'
-        return
-
-    builder = Builder(config)
-    builder.fix_manifest()
+    print "WARNING: the fix_manifest command is obsolete"
+    print "the MANIFEST file is no longer used in bundles, please remove it"
+    pass

 def cmd_dist_source(config, args):
--- sugar-toolkit-0.88.1/src/sugar/bundle/activitybundle.py.orig	2010-06-03 02:56:29.000000000 -0400
+++ sugar-toolkit-0.88.1/src/sugar/bundle/activitybundle.py	2010-06-06 10:36:58.000000000 -0400
@@ -59,7 +59,6 @@ class ActivityBundle(Bundle):
         self._tags = None
         self._activity_version = 0
         self._installation_time = os.stat(path).st_mtime
-        self._manifest = None
 
         info_file = self.get_file('activity/activity.info')
         if info_file is None:
@@ -73,74 +72,6 @@ class ActivityBundle(Bundle):
         if self._local_name == None:
            self._local_name = self._name
 
-    def _get_manifest(self):
-        if self._manifest is None:
-            self._manifest = self._read_manifest()
-        return self._manifest
-
-    manifest = property(_get_manifest, None, None,
-        "NOTICE: this property is potentially quite slow, so better make sure "
-        "that it's not called at performance-critical points like shell or "
-        "activity startup.")
-
-    def _raw_manifest(self):
-        f = self.get_file("MANIFEST")
-        if not f:
-            logging.warning("Activity directory lacks a MANIFEST file.")
-            return []
-
-        ret = [line.strip() for line in f.readlines()]
-        f.close()
-        return ret
-
-    def _read_manifest(self):
-        """return a list with the lines in MANIFEST, with invalid lines
-        replaced by empty lines.
-
-        Since absolute order carries information on file history, it should
-        be preserved. For instance, when renaming a file, you should leave
-        the new name on the same line as the old one.
-        """
-        logging.debug('STARTUP: Reading manifest')
-        lines = self._raw_manifest()
-
-        # Remove trailing newlines, they do not help keep absolute position.
-        while lines and lines[-1] == "":
-            lines = lines[:-1]
-
-        for num, line in enumerate(lines):
-            if not line:
-                continue
-
-            # Remove duplicates
-            if line in lines[0:num]:
-                lines[num] = ""
-                logging.warning('Bundle %s: duplicate entry in MANIFEST: %s',
-                    self._name, line)
-                continue
-
-            # Remove MANIFEST
-            if line == "MANIFEST":
-                lines[num] = ""
-                logging.warning('Bundle %s: MANIFEST includes itself: %s',
-                    self._name, line)
-
-            # Remove invalid files
-            if not self.is_file(line):
-                lines[num] = ""
-                logging.warning('Bundle %s: invalid entry in MANIFEST: %s',
-                    self._name, line)
-
-        return lines
-
-    def get_files(self, manifest = None):
-        files = [line for line in (manifest or self.manifest) if line]
-
-        if self.is_file('MANIFEST'):
-            files.append('MANIFEST')
-
-        return files
-
     def _parse_info(self, info_file):
         cp = ConfigParser()
         cp.readfp(info_file)
@@ -300,41 +231,13 @@ class ActivityBundle(Bundle):
         """Get whether there should be a visible launcher for the activity"""
         return self._show_launcher
 
-    def install(self, install_dir=None, strict_manifest=False):
+    def install(self, install_dir=None):
         if install_dir is None:
             install_dir = env.get_user_activities_path()
 
         self._unzip(install_dir)
 
         install_path = os.path.join(install_dir, self._zip_root_dir)
-
-        # List installed files
-        manifestfiles = self.get_files(self._raw_manifest())
-        paths = []
-        for root, dirs_, files in os.walk(install_path):
-            rel_path = root[len(install_path) + 1:]
-            for f in files:
-                paths.append(os.path.join(rel_path, f))
-
-        # Check the list against the MANIFEST
-        for path in paths:
-            if path in manifestfiles:
-                manifestfiles.remove(path)
-            elif path != "MANIFEST":
-                logging.warning('Bundle %s: %s not in MANIFEST', self._name,
-                    path)
-                if strict_manifest:
-                    os.remove(os.path.join(install_path, path))
-
-        # Is anything in MANIFEST left over after accounting for all files?
-        if manifestfiles:
-            err = ("Bundle %s: files in MANIFEST not included: %s"%
-                   (self._name, str(manifestfiles)))
-            if strict_manifest:
-                raise MalformedBundleException(err)
-            else:
-                logging.warning(err)
-
         self.install_mime_type(install_path)
 
         return install_path
diff --git a/src/sugar/bundle/bundle.py b/src/sugar/bundle/bundle.py
index a04c873..adba480 100644
--- a/src/sugar/bundle/bundle.py
+++ b/src/sugar/bundle/bundle.py
@@ -80,14 +80,6 @@ class Bundle(object):
                     % (self._path, ziperror))
             self._check_zip_bundle()
 
-        # manifest = self._get_file(self._infodir + '/contents')
-        # if manifest is None:
-        #     raise MalformedBundleException('No manifest file')
-
-        # signature = self._get_file(self._infodir + '/contents.sig')
-        # if signature is None:
-        #     raise MalformedBundleException('No signature file')
-
     def __del__(self):
         if self._zip_file is not None:
             self._zip_file.close()
@@ -176,7 +168,6 @@ class Bundle(object):
         # correctly by hand, but handling all the oddities of
         # Windows/UNIX mappings, extension attributes, deprecated
         # features, etc makes it impractical.
-        # FIXME: use manifest
         if os.spawnlp(os.P_WAIT, 'unzip', 'unzip', '-o', self._path,
                       '-x', 'mimetype', '-d', install_dir):
             # clean up install dir after failure
-- 
1.7.0.1