[jhbuild] packagedb: Make "entries" into private member, add public get() method



commit 8fb9e60c9de32389965dc1343fd3a57d26472722
Author: Colin Walters <walters verbum org>
Date:   Sun Jul 31 16:55:07 2011 -0400

    packagedb: Make "entries" into private member, add public get() method
    
    This will make it easier to change the internals later.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=312910

 jhbuild/commands/base.py         |    2 +-
 jhbuild/frontends/buildscript.py |    3 ++-
 jhbuild/utils/packagedb.py       |   28 ++++++++++++++++------------
 3 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/jhbuild/commands/base.py b/jhbuild/commands/base.py
index 5817743..29dcbcc 100644
--- a/jhbuild/commands/base.py
+++ b/jhbuild/commands/base.py
@@ -173,7 +173,7 @@ def check_bootstrap_updateness(config):
 
     updated_modules = []
     for module in module_set.modules.values():
-        pkg = packagedb.entries.get(module.name)
+        pkg = packagedb.get(module.name)
         if pkg is None:
             continue
         p_version = pkg.version
diff --git a/jhbuild/frontends/buildscript.py b/jhbuild/frontends/buildscript.py
index d025be4..66570d3 100644
--- a/jhbuild/frontends/buildscript.py
+++ b/jhbuild/frontends/buildscript.py
@@ -225,7 +225,8 @@ class BuildScript:
             # Skip if somehow the module isn't really installed
             if self.moduleset.packagedb.installdate(module_name) is None:
                 continue
-            pkg = self.moduleset.packagedb.entries[module_name]
+            pkg = self.moduleset.packagedb.get(module_name)
+            assert pkg is not None
 
             # Skip this if the packagedb doesn't have a manifest; this
             # can happen with old packagedb.xml files.
diff --git a/jhbuild/utils/packagedb.py b/jhbuild/utils/packagedb.py
index 8a76109..35d3fdb 100644
--- a/jhbuild/utils/packagedb.py
+++ b/jhbuild/utils/packagedb.py
@@ -121,7 +121,7 @@ class PackageDB:
         self._read_cache()
 
     def _read_cache(self):
-        self.entries = {}
+        self._entries = {}
         try:
             f = open(self.dbfile)
         except OSError, e:
@@ -136,12 +136,12 @@ class PackageDB:
             if node.tag != 'entry':
                 continue
             entry = PackageEntry.from_xml(node, self.manifests_dir)
-            self.entries[entry.package] = entry
+            self._entries[entry.package] = entry
 
     def _write_cache(self):
         pkgdb_node = ET.Element('packagedb')
         doc = ET.ElementTree(pkgdb_node)
-        for package,entry in self.entries.iteritems():
+        for package,entry in self._entries.iteritems():
             node = entry.to_xml(doc)
             pkgdb_node.append(node)
 
@@ -189,33 +189,37 @@ class PackageDB:
             contents[i] = '/' + subpath[pathlen:]
         return contents
 
+    def get(self, package):
+        '''Return entry if package is installed, otherwise return None.'''
+        return self._entries.get(package)
+
     def add(self, package, version, destdir):
         '''Add a module to the install cache.'''
         now = time.time()
         metadata = {'installed-date': now}
-        self.entries[package] = PackageEntry(package, version, metadata, self.manifests_dir)
-        self.entries[package].manifest = self._accumulate_dirtree_contents(destdir)
+        self._entries[package] = PackageEntry(package, version, metadata, self.manifests_dir)
+        self._entries[package].manifest = self._accumulate_dirtree_contents(destdir)
         self._write_cache()
 
     def check(self, package, version=None):
         '''Check whether a particular module is installed.'''
-        if not self.entries.has_key(package): return False
-        entry = self.entries[package]
+        if not self._entries.has_key(package): return False
+        entry = self._entries[package]
         if version is not None:
             if entry.version != version: return False
         return True
 
     def installdate(self, package, version=None):
         '''Get the install date for a particular module.'''
-        if not self.entries.has_key(package): return None
-        entry = self.entries[package]
+        if not self._entries.has_key(package): return None
+        entry = self._entries[package]
         if version:
             if entry.version != version: return None
         return entry.metadata['installed-date']
 
     def uninstall(self, package_name):
         '''Remove a module from the install cache.'''
-        entry = self.entries[package_name]
+        entry = self._entries[package_name]
 
         if entry.manifest is None:
             logging.error(_("no manifest for '%s', can't uninstall.  Try building again, then uninstalling.") % (package_name,))
@@ -246,9 +250,9 @@ class PackageDB:
             except OSError, e:
                 # Allow multiple components to use directories
                 pass
-        del self.entries[package_name]
+        del self._entries[package_name]
         self._write_cache()
 
 if __name__ == '__main__':
     db = PackageDB(sys.argv[1])
-    print "%r" % (db.entries, )
+    print "%r" % (db._entries, )



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