[jhbuild] uninstall: Move purely into packagedb



commit cac986279b32edad64b68eefd1c8b3f431689c71
Author: Colin Walters <walters verbum org>
Date:   Mon Jul 18 15:11:17 2011 -0400

    uninstall: Move purely into packagedb
    
    There's no reason anymore for modules to export an 'uninstall'
    operation that just calls back into packagedb.  Just get rid of it.

 jhbuild/commands/uninstall.py |    8 ++---
 jhbuild/modtypes/autotools.py |   13 --------
 jhbuild/modtypes/waf.py       |    7 ----
 jhbuild/moduleset.py          |    2 +-
 jhbuild/utils/packagedb.py    |   68 ++++++++++++++++++++--------------------
 5 files changed, 38 insertions(+), 60 deletions(-)
---
diff --git a/jhbuild/commands/uninstall.py b/jhbuild/commands/uninstall.py
index 949da0e..e77f8d6 100644
--- a/jhbuild/commands/uninstall.py
+++ b/jhbuild/commands/uninstall.py
@@ -48,12 +48,10 @@ class cmd_uninstall(Command):
         packagedb = module_set.packagedb
         for module in module_list[:]:
             if not packagedb.check(module.name):
+                logging.warn(_('Module %(mod)r is not installed') % {'mod': module.name })
                 module_list.remove(module)
+            else:
+                packagedb.uninstall(module.name)
 
-        config.nonetwork = True
-        config.nopoison = True
-
-        build = jhbuild.frontends.get_buildscript(config, module_list, module_set=module_set)
-        return build.build(phases=['uninstall'])
 
 register_command(cmd_uninstall)
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index d1a5cb0..9cd038a 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -285,19 +285,6 @@ class AutogenModule(Package, DownloadableModule):
                     extra_env = self.extra_env)
     do_distclean.depends = [PHASE_CONFIGURE]
 
-    def skip_uninstall(self, buildscript, last_phase):
-        srcdir = self.get_srcdir(buildscript)
-        if not os.path.exists(srcdir):
-            return True
-        if not os.path.exists(os.path.join(srcdir, self.makefile)):
-            return True
-        return False
-
-    def do_uninstall(self, buildscript):
-        buildscript.set_action(_('Uninstalling'), self)
-        # Since we are supports_install_destdir = True, just delegate to packagedb
-        buildscript.moduleset.packagedb.uninstall(self.name, buildscript)
-
     def xml_tag_and_attrs(self):
         return ('autotools',
                 [('autogenargs', 'autogenargs', ''),
diff --git a/jhbuild/modtypes/waf.py b/jhbuild/modtypes/waf.py
index 8ff6ddd..198c467 100644
--- a/jhbuild/modtypes/waf.py
+++ b/jhbuild/modtypes/waf.py
@@ -132,13 +132,6 @@ class WafModule(Package, DownloadableModule):
         self.process_install(buildscript, self.get_revision())
     do_install.depends = [PHASE_BUILD]
 
-    def do_uninstall(self, buildscript):
-        buildscript.set_action(_('Uninstalling'), self)
-        cmd = [self.waf_cmd, 'uninstall']
-        buildscript.execute(cmd, cwd=self.get_builddir(buildscript))
-        buildscript.moduleset.packagedb.remove(self.name)
-    do_install.depends = [PHASE_BUILD]
-
     def xml_tag_and_attrs(self):
         return 'waf', [('id', 'name', None),
                        ('waf-command', 'waf_cmd', 'waf')]
diff --git a/jhbuild/moduleset.py b/jhbuild/moduleset.py
index 781d805..cfdf620 100644
--- a/jhbuild/moduleset.py
+++ b/jhbuild/moduleset.py
@@ -58,7 +58,7 @@ class ModuleSet:
         if os.path.isfile(legacy_pkgdb_path):
             os.rename(legacy_pkgdb_path, new_pkgdb_path)
 
-        self.packagedb = packagedb.PackageDB(new_pkgdb_path)
+        self.packagedb = packagedb.PackageDB(new_pkgdb_path, config)
 
     def add(self, module):
         '''add a Module object to this set of modules'''
diff --git a/jhbuild/utils/packagedb.py b/jhbuild/utils/packagedb.py
index b8db0e7..b74fba2 100644
--- a/jhbuild/utils/packagedb.py
+++ b/jhbuild/utils/packagedb.py
@@ -80,8 +80,9 @@ class PackageEntry:
         return entry_node
 
 class PackageDB:
-    def __init__(self, dbfile):
+    def __init__(self, dbfile, config):
         self.dbfile = dbfile
+        self.config = config
         self._read_cache()
 
     def _read_cache(self):
@@ -177,42 +178,41 @@ class PackageDB:
             if entry.version != version: return None
         return entry.metadata['installed-date']
 
-    def uninstall(self, package_name, buildscript):
+    def uninstall(self, package_name):
         '''Remove a module from the install cache.'''
-        if package_name in self.entries:
-            entry = self.entries[package_name]
-            if entry.manifest is None:
-                buildscript.message("warning: no manifest known for '%s', not deleting files")
+        entry = self.entries[package_name]
+
+        if entry.manifest is None:
+            logging.error(_("no manifest for '%s', can't uninstall.  Try building again, then uninstalling."))
+            return
+
+        directories = []
+        for path in entry.manifest:
+            assert os.path.isabs(path)
+            if os.path.isdir(path):
+                directories.append(path)
             else:
-                directories = []
-                for path in entry.manifest:
-                    assert os.path.isabs(path)
-                    if os.path.isdir(path):
-                        directories.append(path)
-                    else:
-                        try:
-                            os.unlink(path)
-                            logging.info(_("Deleted: %s" % (path, )))
-                        except OSError, e:
-                            logging.warn(_("Failed to delete %(file)r: %(msg)s") % { 'file': path,
-                                                                                     'msg': e.strerror})
+                try:
+                    os.unlink(path)
+                    logging.info(_("Deleted: %s" % (path, )))
+                except OSError, e:
+                    logging.warn(_("Failed to delete %(file)r: %(msg)s") % { 'file': path,
+                                                                             'msg': e.strerror})
                         
-                for directory in directories:
-                    if not directory.startswith(buildscript.config.prefix):
-                        # Skip non-prefix directories; otherwise we
-                        # may try to remove the user's ~ or something
-                        # (presumably we'd fail, but better not to try)
-                        continue
-                    try:
-                        os.rmdir(directory)
-                        logging.info(_("Deleted: %s" % (path, )))
-                    except OSError, e:
-                        # Allow multiple components to use directories
-                        pass
-            del self.entries[package_name]
-            self._write_cache()
-        else:
-            buildscript.message("warning: no package known for '%s'")
+        for directory in directories:
+            if not directory.startswith(self.config.prefix):
+                # Skip non-prefix directories; otherwise we
+                # may try to remove the user's ~ or something
+                # (presumably we'd fail, but better not to try)
+                continue
+            try:
+                os.rmdir(directory)
+                logging.info(_("Deleted: %s" % (directory, )))
+            except OSError, e:
+                # Allow multiple components to use directories
+                pass
+        del self.entries[package_name]
+        self._write_cache()
 
 if __name__ == '__main__':
     db = PackageDB(sys.argv[1])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]