Hello list,

I have extended the format_filesize() function from utils.py to format the 
bytesize into a correct way.

It now has 3 options, determined by a shell variable BYTEPREFIX

1. If the variable is set to “off”, the string is formatted the usual way. So 
20,000 Bytes are 19.53 “Kilo”bytes (the output is “19.53 KB”)
2. If the variable is set to “decimal”, it uses the SI units in the correct 
way. This way, 20,000 Bytes are exactly 20 Kilobytes. 20,000,000 Bytes are 20 
Megabytes. The output is “20 KB” and so on.
3. If the variable is set to “binary”, it uses the Binary prefixes (Kibi, 
Mebi, Gibi). So 20,000 Bytes will become 19.53 Kibibyte. The output then 
is “19.53 KiB”.

If BYTEPREFIX is not set, it automatically assumes the setting “off”.

The function needs the os module for os.environ[], but I think this is already 
imported in gpodder?

I have done this via a shell variable, because I think, it would be nice if 
the user could globally change the setting and then all applications with 
this feature would use the setting. I do not think it is very convenient if 
the user has to switch the setting each time in every appplication. This way, 
he could set the BYTEPREFIX variable and all applications could benefit. 

I know that the function might now be a bit cumbersome, but this is more or 
less my first “real” programmed function. 

If somebody could look over the function and see if there are some flaws I did 
not see?

Also I only made a “dry run” of the function, I did not include it in gpodder. 
So I do not know if it works :D 

Thanks

Gerrit Sangel

Attachment: filesize.py
Description: application/python

_______________________________________________
gpodder-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/gpodder-devel

Reply via email to