[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH 1/3] Create Size class for specifying device and fs sizes.

On Mon, 6 Sep 2010, Ales Kozumplik wrote:

On 09/04/2010 04:56 AM, dcantrell redhat com wrote:
From: David Cantrell<dcantrell redhat com>

Created a new class called Size under the storage module.  It can
represent sizes where we have traditionally used megabytes.  The size is
stored as bytes in the object, but can convert to any other type unit
supported by the class.

The class also has the humanReadable() method, which will output the
size in a human readable format to a specified number of decimal places,
or fewer if that makes sense in the given situation.

The initialization method also accepts a number of bytes or a string
specification for the size, such as "32 GB" or "640 kb".
pyanaconda/storage/size.py | 230 ++++++++++++++++++++++++++++++++++++++++++++
  1 files changed, 230 insertions(+), 0 deletions(-)
  create mode 100644 pyanaconda/storage/size.py

Ack from me, with a few notes:

+    def _makeSpecs(self, prefix, abbr):
+        """ Internal method used to generate a list of specifiers. """
+        specs = []
+        if prefix:
+            specs.append("%sbytes" % prefix.lower())

Are going to be passing user input through this method at some point? Then you could also add:

           specs.append("%sbyte" % prefix.lower())

i.e. singular form so they can say "1 Megabyte".

Also a good idea.  I expanded the specifier checks to account for singular and
plural forms of the size words, but not enforce the usage.  So things like "50
megabyte" work even though it should be "50 megabytes".  The humanReadable()
function will return the correct singular or plural form in the cases where
there is no abbreviation available.  All the yottabyte users should be

+    def humanReadable(self, places=2):

Maybe this method should be called __str__ ? Or let's just define __str__ that calls self.humanReadable(places=2).

The latter sounds like a good idea, I'll add that for the next round.

David Cantrell <dcantrell redhat com>
Red Hat / Honolulu, HI

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]