Simone Tiraboschi has uploaded a new change for review.

Change subject: upload: making it faster on el6
......................................................................

upload: making it faster on el6

Removing at all the usage of tarlib and gzip with are
really slow on Python 2.6

Change-Id: Ie7a1cf9757429e8cf77745b39a4c1b9efeab6169
Bug-Url: https://bugzilla.redhat.com/1150922
Signed-off-by: Simone Tiraboschi <stira...@redhat.com>
---
M src/__main__.py
1 file changed, 23 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-image-uploader 
refs/changes/76/33976/1

diff --git a/src/__main__.py b/src/__main__.py
index 29cc7cf..6ed3d8b 100644
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -14,7 +14,6 @@
 import uuid
 import re
 import getpass
-import tarfile
 import time
 from lxml import etree
 from ovf import ovfenvelope
@@ -716,21 +715,31 @@
         Checks to see if there is enough room to decompress the tgz into
         dest_dir
         """
-        tar = tarfile.open(ovf_file, "r:gz")
         size_in_bytes = 0
-        try:
-            for tarinfo in tar:
-                if tarinfo.isreg():
-                    size_in_bytes += tarinfo.size
-        except:
+        exttar = subprocess.Popen(
+            ['tar', '-tvzf', ovf_file],
+            shell=False,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+        )
+        outerr = exttar.communicate()
+        if outerr[1] != '':
             logging.error(
                 _(
                     "Unable to calculate the decompressed size of %s."
                 ) % ovf_file
             )
-            return (False, -1)
-        finally:
-            tar.close()
+            return False, -1
+        for line in outerr[0].splitlines():
+            try:
+                size_in_bytes += int(line.split()[2])
+            except (ValueError, IndexError):
+                logging.error(
+                    _(
+                        "Unable to calculate the decompressed size of %s."
+                    ) % ovf_file
+                )
+                return False, -1
 
         dest_dir_stat = os.statvfs(dest_dir)
         dest_dir_size = (dest_dir_stat.f_bavail * dest_dir_stat.f_frsize)
@@ -750,9 +759,9 @@
         )
 
         if dest_dir_size > size_in_bytes:
-            return (True, size_in_bytes)
+            return True, size_in_bytes
         else:
-            return (False, size_in_bytes)
+            return False, size_in_bytes
 
     def space_test_nfs(self, remote_dir, desired_size, uid, gid):
         """
@@ -828,10 +837,10 @@
         logging.debug("euid(%s) egid(%s)" % (os.geteuid(), os.getegid()))
         umask_save = os.umask(0137)  # Set to 660
         try:
-            src = open(src_file_name, 'r')
+            src = open(src_file_name, 'rb')
             os.setegid(gid)
             os.seteuid(uid)
-            dest = open(dest_file_name, 'w')
+            dest = open(dest_file_name, 'wb')
             self.copyfileobj_sparse(src, dest)
         except Exception, e:
             retVal = False


-- 
To view, visit http://gerrit.ovirt.org/33976
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7a1cf9757429e8cf77745b39a4c1b9efeab6169
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-image-uploader
Gerrit-Branch: master
Gerrit-Owner: Simone Tiraboschi <stira...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to