From f40101a4800f3799fe6b8844826a80bf0d45dcb2 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 17 Jan 2013 18:12:06 +0000 Subject: Correct amount in free space error message SL #394 Fixed the order of operation to calculate the free space amount to show in the error message. Added some comments on the code about the units (Bytes, Kilobytes) used by each method. Signed-off-by: Manuel Kaufmann Acked-by: Manuel QuiƱones --- (limited to 'downloadmanager.py') diff --git a/downloadmanager.py b/downloadmanager.py index 36bcd43..2fdbaa5 100644 --- a/downloadmanager.py +++ b/downloadmanager.py @@ -38,7 +38,7 @@ DS_DBUS_PATH = '/org/laptop/sugar/DataStore' _active_downloads = [] _dest_to_window = {} -SPACE_THRESHOLD = 52428800 +SPACE_THRESHOLD = 52428800 # 50 Mb def format_float(f): return "%0.2f" % f @@ -114,8 +114,8 @@ class Download(object): 'to download') total_size_mb = total_size / 1024.0 ** 2 - free_space_mb = self._free_available_space( - path=self.temp_path) - SPACE_THRESHOLD \ + free_space_mb = (self._free_available_space( + path=self.temp_path) - SPACE_THRESHOLD) \ / 1024.0 ** 2 filename = self._download.get_suggested_filename() self._canceled_alert.props.msg = \ @@ -241,7 +241,7 @@ class Download(object): def enough_space(self, size, path='/'): """Check if there is enough (size) free space on path - size -- free space requested in Kb + size -- free space requested in Bytes path -- device where the check will be done. For example: '/tmp' @@ -255,6 +255,12 @@ class Download(object): return free_space - size > SPACE_THRESHOLD def _free_available_space(self, path='/'): + """Return available space in Bytes + + This method returns the available free space in the 'path' and + returns this amount in Bytes. + """ + s = os.statvfs(path) return s.f_bavail * s.f_frsize -- cgit v0.9.1