WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Fix problem with Python 2.4 caused by change in error be

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Fix problem with Python 2.4 caused by change in error behaviour
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Thu, 28 Apr 2005 08:59:31 +0000
Delivery-date: Fri, 13 May 2005 20:04:04 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1327.2.12, 2005/04/28 09:59:31+01:00, mjw@xxxxxxxxxxxxxxxxxxx

        Fix problem with Python 2.4 caused by change in error behaviour
        of dircache.listdir. In 2.4 it throws an error on non-existent
        directories instead of returning an empty list.
        See 'Porting to 2.4' in the Python release notes.
        
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>



 XendDB.py |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)


diff -Nru a/tools/python/xen/xend/XendDB.py b/tools/python/xen/xend/XendDB.py
--- a/tools/python/xen/xend/XendDB.py   2005-05-13 16:04:40 -04:00
+++ b/tools/python/xen/xend/XendDB.py   2005-05-13 16:04:40 -04:00
@@ -20,6 +20,12 @@
             self.dbpath = os.path.join(self.dbpath, path)
         pass
 
+    def listdir(self, dpath):
+        try:
+            return dircache.listdir(dpath)
+        except:
+            return []
+
     def filepath(self, path):
         return os.path.join(self.dbpath, path)
         
@@ -52,21 +58,37 @@
         return self.savefile(fpath, sxpr)
     
     def savefile(self, fpath, sxpr):
+        backup = False
         fdir = os.path.dirname(fpath)
         if not os.path.isdir(fdir):
             os.makedirs(fdir)
+        if os.path.exists(fpath):
+            backup = True
+            real_fpath = fpath
+            fpath += ".new."
+            
         fout = file(fpath, "wb+")
         try:
-            t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
-            fout.write("# %s %s\n" % (fpath, t))
-            sxp.show(sxpr, out=fout)
-        finally:
-            fout.close()
+            try:
+                t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+                fout.write("# %s %s\n" % (fpath, t))
+                sxp.show(sxpr, out=fout)
+            finally:
+                fout.close()
+        except:
+            if backup:
+                try:
+                    os.unlink(fpath)
+                except:
+                    pass
+                raise
+        if backup:
+            os.rename(fpath, real_fpath)
 
     def fetchall(self, path):
         dpath = self.filepath(path)
         d = {}
-        for k in dircache.listdir(dpath):
+        for k in self.listdir(dpath):
             try:
                 v = self.fetchfile(os.path.join(dpath, k))
                 d[k] = v
@@ -84,8 +106,7 @@
 
     def ls(self, path):
         dpath = self.filepath(path)
-        return dircache.listdir(dpath)
-            
+        return self.listdir(dpath)
         
 
         

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Fix problem with Python 2.4 caused by change in error behaviour, BitKeeper Bot <=