SHARE
TWEET

Foone

a guest Mar 10th, 2008 403 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import os,datetime
  3.  
  4. def is_leap_year():
  5.         today=datetime.date.today()
  6.         try:
  7.                 datetime.date(today.year,2,29) # won't work if this isn't a leap year
  8.                 return True
  9.         except ValueError:
  10.                 return False
  11.  
  12. def get_xkcd394_sizes(filename):
  13.         size=os.path.getsize(filename)
  14.         sizes={}
  15.        
  16.         if is_leap_year():
  17.                 sizes['kB']=int(size/1000) # kilobyte, leap year
  18.         else:
  19.                 sizes['kB']=int(size/1024) # kilobyte, non leap year
  20.        
  21.         sizes['KB']=int(size/1012) # kelly-bootle standard unit
  22.        
  23.         sizes['kb']=size/1024.937528 # intel kilobyte
  24.  
  25.         sizes['KiB']=size/complex(1024,1) # imaginary kilobyte
  26.  
  27.         since_2008 = datetime.date.today().year-2008
  28.         drivemaker=908 - 4 * since_2008
  29.         sizes['Kb']=int(size/drivemaker) # drivemaker's kilobyte
  30.        
  31.         sizes['KBa']=int(size/1152) # baker's kilobyte
  32.        
  33.         return sizes
  34.  
  35. if __name__=='__main__':
  36.         import sys
  37.         for arg in sys.argv[1:]:
  38.                 print arg
  39.                 sizes=get_xkcd394_sizes(arg)
  40.                 for type in 'kB KB KiB kb Kb KBa'.split():
  41.                         print '  %s %s' % (sizes.get(type,''),type)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top