diff options
author | Peter Jones <pjones@redhat.com> | 2005-03-09 19:02:01 +0000 |
---|---|---|
committer | Peter Jones <pjones@redhat.com> | 2005-03-09 19:02:01 +0000 |
commit | e14283d0aa1cf90589887303a00cdf0c4e021c20 (patch) | |
tree | 3d154677a1fe0913176c603e4ea1a901febd23e9 /iutil.py | |
parent | cbb7f69791ad327425911d80b407dbc7838dd256 (diff) | |
download | anaconda-e14283d0aa1cf90589887303a00cdf0c4e021c20.tar.gz anaconda-e14283d0aa1cf90589887303a00cdf0c4e021c20.tar.xz anaconda-e14283d0aa1cf90589887303a00cdf0c4e021c20.zip |
make everything appropriate in iutil return Size objects.
remove comments about the scale of the value returned.
Diffstat (limited to 'iutil.py')
-rw-r--r-- | iutil.py | 51 |
1 files changed, 24 insertions, 27 deletions
@@ -17,6 +17,7 @@ import types, os, sys, isys, select, string, stat, signal import os.path from rhpl.log import log from flags import flags +from rhpl.storage.constructors import * def getArch (): arch = os.uname ()[4] @@ -190,13 +191,12 @@ def copyFile(source, to, pw = None): if pw: win.pop() -# return size of directory (and subdirs) in kilobytes +# return size of directory (and subdirs) def getDirSize(dir): def getSubdirSize(dir): - # returns size in bytes mydev = os.lstat(dir)[stat.ST_DEV] - dsize = 0 + dsize = Bytes(0) for f in os.listdir(dir): curpath = '%s/%s' % (dir, f) sinfo = os.lstat(curpath) @@ -209,9 +209,9 @@ def getDirSize(dir): pass return dsize - return getSubdirSize(dir)/1024 + return getSubdirSize(dir) -# this is in kilobytes - returns amount of RAM not used by /tmp +# returns amount of RAM not used by /tmp def memAvailable(): tram = memInstalled() @@ -221,7 +221,6 @@ def memAvailable(): return tram - ramused -# this is in kilobytes def memInstalled(): if not os.access('/proc/e820info', os.R_OK): f = open("/proc/meminfo", "r") @@ -231,39 +230,37 @@ def memInstalled(): for l in lines: if l.startswith("MemTotal:"): fields = string.split(l) - mem = fields[1] + mem = kBytes(long(fields[1])) break else: f = open("/proc/e820info", "r") lines = f.readlines() - mem = 0 + mem = Bytes(0) for line in lines: fields = string.split(line) if fields[3] == "(usable)": - mem = mem + (string.atol(fields[0], 16) / 1024) + mem += kBytes(long(string.atol(fields[0], 16))) - return int(mem) + return mem # try to keep 2.4 kernel swapper happy! def swapSuggestion(quiet=0): - mem = memInstalled()/1024 - mem = ((mem/16)+1)*16 + mem = memInstalled() + mem = ((mem/16)+MBytes(1))*16 if not quiet: - log("Detected %sM of memory", mem) + log("Detected %s of memory", mem) - if mem < 128: - minswap = 96 - maxswap = 192 - else: - if mem > 1000: - minswap = 1000 - maxswap = 2000 - else: - minswap = mem - maxswap = 2*mem + minswap = MBytes(1000) + maxswap = MBytes(2000) + if mem < MBytes(128): + minswap.setMBytes(96) + maxswap.setMBytes(192) + elif mem <= MBytes(1000): + minswap.setMBytes(mem) + maxswap.setMBytes(2*mem) if not quiet: - log("Swap attempt of %sM to %sM", minswap, maxswap) + log("Swap attempt of %s to %s", minswap, maxswap) return (minswap, maxswap) @@ -403,9 +400,9 @@ def swapAmount(): for l in lines: if l.startswith("SwapTotal:"): fields = string.split(l) - return int(fields[1]) - return 0 - + return = kBytes(long(fields[1])) + return Bytes(0) + def copyDeviceNode(src, dest): """Copies the device node at src to dest by looking at the type of device, major, and minor of src and doing a new mknod at dest""" |