[Uludag-commits] r15258 - in branches/pisi-db/pisi: db operations

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
2 Eyl 2007 Paz 13:24:51 EEST


Author: faik
Date: Sun Sep  2 13:24:51 2007
New Revision: 15258

Modified:
   branches/pisi-db/pisi/db/installdb.py
   branches/pisi-db/pisi/db/packagedb.py
   branches/pisi-db/pisi/operations/upgrade.py
Log:
speed up list_upgradable

"Premature optimization is the root of all evil."

But this pissed me of: pisi.api.list_upgradable was taking around 7.2 seconds.
Now it takes 0.5 seconds in my computer.

The very good thing with this new filesystem-piksemel db shows us that, there
is always a room for optimization. And this is good.


Modified: branches/pisi-db/pisi/db/installdb.py
=================================================================
--- branches/pisi-db/pisi/db/installdb.py	(original)
+++ branches/pisi-db/pisi/db/installdb.py	Sun Sep  2 13:24:51 2007
@@ -18,6 +18,8 @@
 __trans = gettext.translation('pisi', fallback=True)
 _ = __trans.ugettext
 
+import piksemel
+
 # PiSi
 import pisi
 import pisi.context as ctx
@@ -77,6 +79,16 @@
     def has_package(self, package):
         return self.installed_pkgs.has_key(package)
 
+    def get_version(self, package):
+        metadata_xml = os.path.join(self.__package_path(package), ctx.const.metadata_xml)
+        meta_doc = piksemel.parse(metadata_xml)
+        history = meta_doc.getTag("Package").getTag("History")
+        build = meta_doc.getTag("Package").getTagData("Build")
+        version = history.getTag("Update").getTagData("Version")
+        release = history.getTag("Update").getAttribute("release")
+        del meta_doc
+        return version, release, build and int(build)
+
     def get_files(self, package):
         files = pisi.files.Files()
         files_xml = os.path.join(self.__package_path(package), ctx.const.files_xml)

Modified: branches/pisi-db/pisi/db/packagedb.py
=================================================================
--- branches/pisi-db/pisi/db/packagedb.py	(original)
+++ branches/pisi-db/pisi/db/packagedb.py	Sun Sep  2 13:24:51 2007
@@ -77,6 +77,18 @@
         pkg, repo = self.get_package_repo(name, repo)
         return pkg
 
+    def get_version(self, name, repo):
+        if not self.has_package(name, repo):
+            raise Exception(_('Package %s not found.') % name)
+            
+        pkg_doc = piksemel.parseString(self.__package_nodes[repo][name])
+        history = pkg_doc.getTag("History")
+        build = pkg_doc.getTagData("Build")
+        version = history.getTag("Update").getTagData("Version")
+        release = history.getTag("Update").getAttribute("release")
+        del pkg_doc
+        return version, release, build and int(build)
+
     def get_package_repo(self, name, repo):
         if self.__package_nodes.has_key(repo):
             if self.__package_nodes[repo].has_key(name):

Modified: branches/pisi-db/pisi/operations/upgrade.py
=================================================================
--- branches/pisi-db/pisi/operations/upgrade.py	(original)
+++ branches/pisi-db/pisi/operations/upgrade.py	Sun Sep  2 13:24:51 2007
@@ -234,16 +234,16 @@
     if not ctx.installdb.has_package(name):
         return False
 
-    info = ctx.installdb.get_info(name)
-    (version, release, build) = (info.version, info.release, info.build)
+    (version, release, build) = ctx.installdb.get_version(name)
+
     try:
-        pkg = ctx.packagedb.get_package(name, ctx.packagedb.which_repo(name))
+        pkg_version, pkg_release, pkg_build = ctx.packagedb.get_version(name, ctx.packagedb.which_repo(name))
     except KeyboardInterrupt:
         raise
     except Exception: #FIXME: what exception could we catch here, replace with that.
         return False
 
-    if ignore_build or (not build) or (not pkg.build):
-        return pisi.version.Version(release) < pisi.version.Version(pkg.release)
+    if ignore_build or (not build) or (not pkg_build):
+        return pisi.version.Version(release) < pisi.version.Version(pkg_release)
     else:
-        return build < pkg.build
+        return build < pkg_build


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi