summaryrefslogtreecommitdiffstats
path: root/livecd.py
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2007-09-17 18:32:04 +0000
committerJeremy Katz <katzj@redhat.com>2007-09-17 18:32:04 +0000
commit292450c3f2e9f3c2a68a12f55029688627da14e2 (patch)
tree6ff398a9cdbd3ee4770254bb057645f65dfde458 /livecd.py
parent8f4e2b05a27aa793c8319f226cf7c5354724c49a (diff)
downloadanaconda-292450c3f2e9f3c2a68a12f55029688627da14e2.tar.gz
anaconda-292450c3f2e9f3c2a68a12f55029688627da14e2.tar.xz
anaconda-292450c3f2e9f3c2a68a12f55029688627da14e2.zip
2007-09-17 Jeremy Katz <katzj@redhat.com>
* livecd.py (getLiveSizeMB): Find the size based on reading from the filesystem with dumpe2fs; basic patch from Douglas McClendon, cleaned up a smidge by me
Diffstat (limited to 'livecd.py')
-rw-r--r--livecd.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/livecd.py b/livecd.py
index afa69fcae..ebbc74654 100644
--- a/livecd.py
+++ b/livecd.py
@@ -133,24 +133,19 @@ class LiveCDImageMethod(installmethod.InstallMethod):
return self.osimg
def getLiveSizeMB(self):
- lnk = os.readlink(self.osimg)
- if lnk[0] != "/":
- lnk = os.path.join(os.path.dirname(self.osimg), lnk)
- blk = os.path.basename(lnk)
-
- if not os.path.exists("/sys/block/%s/size" %(blk,)):
- log.debug("Unable to determine the actual size of the live image")
- return 0
-
- size = open("/sys/block/%s/size" %(blk,), "r").read()
- try:
- size = int(size)
- except ValueError:
- log.debug("Unable to handle live size conversion: %s" %(size,))
- return 0
-
- return (size * 512) / 1024 / 1024
-
+ def parseField(output, field):
+ for line in output.split("\n"):
+ if line.startswith(field + ":"):
+ return line[len(field) + 1:].strip()
+ raise KeyError("Failed to find field '%s' in output" % field)
+
+ output = subprocess.Popen(['/sbin/dumpe2fs', '-h', self.osimg],
+ stdout=subprocess.PIPE,
+ stderr=open('/dev/null', 'w')
+ ).communicate()[0]
+ blkcnt = int(parseField(output, "Block count"))
+ blksize = int(parseField(output, "Block size"))
+ return blkcnt * blksize / 1024 / 1024
class LiveCDCopyBackend(backend.AnacondaBackend):
def __init__(self, method, instPath):