[Yum-devel] [PATCH 2/2] Remove some int/long conversions.

Zdeněk Pavlas zpavlas at redhat.com
Wed Jan 18 08:39:17 UTC 2012


Package and metadata sizes should be always 'None',
or an integer (long if >2Gi).  After checking that
size is not None, we should not have to convert.
---
 output.py       |    3 +--
 yum/__init__.py |    3 +--
 yum/yumRepo.py  |   13 +++++--------
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/output.py b/output.py
index d8af2fd..5bf509b 100755
--- a/output.py
+++ b/output.py
@@ -2544,8 +2544,7 @@ to exit.
                 print _("Package        :"), hpkg.ui_nevra
                 print _("State          :"), uistate
                 if hpkg.size is not None:
-                    num = int(hpkg.size)
-                    print _("Size           :"), locale.format("%d", num, True)
+                    print _("Size           :"), locale.format("%d", hpkg.size, True)
                 if hpkg.buildhost is not None:
                     print _("Build host     :"), hpkg.buildhost
                 if hpkg.buildtime is not None:
diff --git a/yum/__init__.py b/yum/__init__.py
index 9584de0..4c68e22 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2033,8 +2033,7 @@ class YumBase(depsolve.Depsolve):
             # if the file is wrong AND it is >= what we expected then it
             # can't be redeemed. If we can, kill it and start over fresh
             cursize = os.stat(fo)[6]
-            totsize = long(po.size)
-            if cursize >= totsize and not po.repo.cache:
+            if cursize >= po.size and not po.repo.cache:
                 # if the path to the file is NOT inside the cachedir then don't
                 # unlink it b/c it is probably a file:// url and possibly
                 # unlinkable
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 62e53f8..1944e07 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -794,12 +794,12 @@ class YumRepository(Repository, config.RepoConf):
         if size:
             dirstat = os.statvfs(os.path.dirname(local))
             avail = dirstat.f_bavail * dirstat.f_bsize
-            if avail < long(size):
+            if avail < size:
                 raise Errors.RepoError, _('''\
 Insufficient space in download directory %s
     * free   %s
     * needed %s'''
-                ) % (os.path.dirname(local), format_number(avail), format_number(long(size)))
+                ) % (os.path.dirname(local), format_number(avail), format_number(size))
 
         if url and scheme != "media":
             ugopts = self._default_grabopts(cache=cache)
@@ -1392,14 +1392,14 @@ Insufficient space in download directory %s
         remote_size = 0
         local_size  = 0
         for (ndata, nmdtype) in downloading_with_size: # Get total size...
-            remote_size += int(ndata.size)
+            remote_size += ndata.size
 
         for (ndata, nmdtype) in downloading_with_size:
             urlgrabber.progress.text_meter_total_size(remote_size, local_size)
             if not self._retrieveMD(nmdtype, retrieve_can_fail=True):
                 self._revertOldRepoXML()
                 return False
-            local_size += int(ndata.size)
+            local_size += ndata.size
         urlgrabber.progress.text_meter_total_size(0)
         for (ndata, nmdtype) in downloading_no_size:
             if not self._retrieveMD(nmdtype, retrieve_can_fail=True):
@@ -1537,9 +1537,6 @@ Insufficient space in download directory %s
         else:
             file = fn
 
-        if size is not None:
-            size = int(size)
-
         try: # get the local checksum
             l_csum = self._checksum(r_ctype, file, datasize=size)
         except Errors.RepoError, e:
@@ -1607,7 +1604,7 @@ Insufficient space in download directory %s
             else:
                 reget = 'simple'
                 if os.path.exists(local):
-                    if os.stat(local).st_size >= int(thisdata.size):
+                    if os.stat(local).st_size >= thisdata.size:
                         misc.unlink_f(local)
             local = self._getFile(relative=remote,
                                   local=local, 
-- 
1.7.4.4



More information about the Yum-devel mailing list