From 0f10f13141ea0432bb067e7eaefd07817dcff161 Mon Sep 17 00:00:00 2001
From: Manuel Kaufmann <humitos@gmail.com>
Date: Thu, 17 Jan 2013 15:12:06 -0300
Subject: [PATCH Browse] 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 <humitos@gmail.com>
---
downloadmanager.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/downloadmanager.py b/downloadmanager.py
index 36bcd43..2fdbaa5 100644
a
|
b
|
DS_DBUS_PATH = '/org/laptop/sugar/DataStore' |
38 | 38 | _active_downloads = [] |
39 | 39 | _dest_to_window = {} |
40 | 40 | |
41 | | SPACE_THRESHOLD = 52428800 |
| 41 | SPACE_THRESHOLD = 52428800 # 50 Mb |
42 | 42 | |
43 | 43 | def format_float(f): |
44 | 44 | return "%0.2f" % f |
… |
… |
class Download(object): |
114 | 114 | 'to download') |
115 | 115 | |
116 | 116 | total_size_mb = total_size / 1024.0 ** 2 |
117 | | free_space_mb = self._free_available_space( |
118 | | path=self.temp_path) - SPACE_THRESHOLD \ |
| 117 | free_space_mb = (self._free_available_space( |
| 118 | path=self.temp_path) - SPACE_THRESHOLD) \ |
119 | 119 | / 1024.0 ** 2 |
120 | 120 | filename = self._download.get_suggested_filename() |
121 | 121 | self._canceled_alert.props.msg = \ |
… |
… |
class Download(object): |
241 | 241 | def enough_space(self, size, path='/'): |
242 | 242 | """Check if there is enough (size) free space on path |
243 | 243 | |
244 | | size -- free space requested in Kb |
| 244 | size -- free space requested in Bytes |
245 | 245 | |
246 | 246 | path -- device where the check will be done. For example: '/tmp' |
247 | 247 | |
… |
… |
class Download(object): |
255 | 255 | return free_space - size > SPACE_THRESHOLD |
256 | 256 | |
257 | 257 | def _free_available_space(self, path='/'): |
| 258 | """Return available space in Bytes |
| 259 | |
| 260 | This method returns the available free space in the 'path' and |
| 261 | returns this amount in Bytes. |
| 262 | """ |
| 263 | |
258 | 264 | s = os.statvfs(path) |
259 | 265 | return s.f_bavail * s.f_frsize |
260 | 266 | |