def mountImage(isodir, tree, discnum, messageWindow, discImages={}): if os.path.ismount(tree): raise SystemError, "trying to mount already-mounted iso image!" if discImages == {}: discImages = findIsoImages(isodir, messageWindow) while True: try: isoImage = "%s/%s" % (isodir, discImages[discnum]) isys.losetup("/dev/loop1", isoImage, readOnly = 1) isys.mount("/dev/loop1", tree, fstype = 'iso9660', readOnly = True) break except: ans = messageWindow(_("Missing ISO 9660 Image"), _("The installer has tried to mount " "image #%s, but cannot find it on " "the hard drive.\n\n" "Please copy this image to the " "drive and click Retry. Click Exit " "to abort the installation.") % (discnum,), type="custom", custom_icon="warning", custom_buttons=[_("_Exit"), _("_Retry")]) if ans == 0: sys.exit(0) elif ans == 1: discImages = findIsoImages(isodir, messageWindow) return discImages
def mountMedia(self, cdNum): if self.mediaIsMounted: raise SystemError, "trying to mount already-mounted iso image!" self.mountDirectory() retry = True while retry: try: isoImage = self.isoDir + '/' + self.path + '/' + self.discImages[cdNum] isys.makeDevInode("loop3", "/tmp/loop3") isys.losetup("/tmp/loop3", isoImage, readOnly = 1) isys.mount("loop3", self.tree, fstype = 'iso9660', readOnly = 1); self.mediaIsMounted = cdNum retry = False except: ans = self.messageWindow( _("Missing ISO 9660 Image"), _("The installer has tried to mount " "image #%s, but cannot find it on " "the hard drive.\n\n" "Please copy this image to the " "drive and click Retry. Click Reboot " " to abort the installation.") % (cdNum,), type="custom", custom_icon="warning", custom_buttons=[_("_Reboot"), _("Re_try")]) if ans == 0: sys.exit(0) elif ans == 1: self.discImages = findIsoImages(self.isoPath, self.messageWindow)
def mountImage(self, cdNum): if (self.currentMedia): raise SystemError, "trying to mount already-mounted iso image!" retrymount = True while retrymount: try: isoImage = self.isoPath + '/' + self.discImages[cdNum] isys.makeDevInode("loop3", "/tmp/loop3") isys.losetup("/tmp/loop3", isoImage, readOnly = 1) isys.mount("loop3", "/tmp/isomedia", fstype = 'iso9660', readOnly = 1); self.mntPoint = "/tmp/isomedia/" self.currentMedia = [ cdNum ] retrymount = False except: ans = self.messageWindow( _("Missing ISO 9660 Image"), _("The installer has tried to mount " "image #%s, but cannot find it on " "the server.\n\n" "Please copy this image to the " "remote server's share path and " "click Retry. Click Reboot to " "abort the installation.") % (cdNum,), type="custom", custom_icon="warning", custom_buttons=[_("_Reboot"), _("Re_try")]) if ans == 0: sys.exit(0) elif ans == 1: self.discImages = findIsoImages(self.isoPath, self.messageWindow)
def mountImage(self, cdNum): if (self.imageMounted): raise SystemError, "trying to mount already-mounted iso image!" isoImage = self.isoPath + '/' + self.discImages[cdNum] isys.makeDevInode("loop3", "/tmp/loop3") isys.losetup("/tmp/loop3", isoImage, readOnly = 1) isys.mount("loop3", "/tmp/isomedia", fstype = 'iso9660', readOnly = 1); self.mntPoint = "/tmp/isomedia/" self.imageMounted = cdNum
def mountMedia(self, cdNum): if (self.mediaIsMounted): raise SystemError, "trying to mount already-mounted iso image!" self.mountDirectory() isoImage = self.isoDir + '/' + self.path + '/' + self.discImages[cdNum] isys.makeDevInode("loop3", "/tmp/loop3") isys.losetup("/tmp/loop3", isoImage, readOnly=1) isys.mount("loop3", "/tmp/isomedia", fstype='iso9660', readOnly=1) self.tree = "/tmp/isomedia/" self.mediaIsMounted = cdNum
def findIsoImages(path, messageWindow): flush = os.stat(path) files = os.listdir(path) arch = _arch discImages = {} for file in files: what = path + '/' + file if not isys.isIsoImage(what): continue try: isys.losetup("/dev/loop2", what, readOnly = 1) except SystemError: continue try: isys.mount("/dev/loop2", "/mnt/cdimage", fstype = "iso9660", readOnly = True) for num in range(1, 10): if os.access("/mnt/cdimage/.discinfo", os.R_OK): f = open("/mnt/cdimage/.discinfo") try: f.readline() # skip timestamp f.readline() # skip release description discArch = string.strip(f.readline()) # read architecture discNum = getDiscNums(f.readline().strip()) except: discArch = None discNum = [ 0 ] f.close() if num not in discNum or discArch != arch: continue # if it's disc1, it needs to have images/install.img if (num == 1 and not os.access("/mnt/cdimage/images/install.img", os.R_OK)): log.warning("%s doesn't have a install.img, skipping" %(what,)) continue # we only install binary packages, so let's look for a # product/ dir and hope that this avoids getting # discs from the src.rpm set if not os.path.isdir("/mnt/cdimage/%s" %(productPath,)): log.warning("%s doesn't have binary RPMS, skipping" %(what,)) continue # warn user if images appears to be wrong size if os.stat(what)[stat.ST_SIZE] % 2048: rc = messageWindow(_("Warning"), _("The ISO image %s has a size which is not " "a multiple of 2048 bytes. This may mean " "it was corrupted on transfer to this computer." "\n\n" "It is recommended that you exit and abort your " "installation, but you can choose to continue if " "you think this is in error.") % (file,), type="custom", custom_icon="warning", custom_buttons= [_("_Exit installer"), _("_Continue")]) if rc == 0: sys.exit(0) discImages[num] = file isys.umount("/mnt/cdimage", removeDir=False) except SystemError: pass isys.unlosetup("/dev/loop2") return discImages
def findIsoImages(path, messageWindow): files = os.listdir(path) arch = _arch discImages = {} for file in files: what = path + '/' + file if not isys.isIsoImage(what): continue isys.makeDevInode("loop2", "/tmp/loop2") try: isys.losetup("/tmp/loop2", what, readOnly = 1) except SystemError: continue try: isys.mount("loop2", "/mnt/cdimage", fstype = "iso9660", readOnly = 1) for num in range(1, 10): if os.access("/mnt/cdimage/.discinfo", os.R_OK): f = open("/mnt/cdimage/.discinfo") try: f.readline() # skip timestamp f.readline() # skip release description discArch = string.strip(f.readline()) # read architecture discNum = getDiscNums(f.readline().strip()) except: discArch = None discNum = [ 0 ] f.close() if num not in discNum or discArch != arch: continue # if it's disc1, it needs to have RedHat/base/stage2.img if (num == 1 and not os.access("/mnt/cdimage/%s/base/stage2.img" % (productPath,), os.R_OK)): continue # warn user if images appears to be wrong size if os.stat(what)[stat.ST_SIZE] % 2048: rc = messageWindow(_("Warning"), "The ISO image %s has a size which is not " "a multiple of 2048 bytes. This may mean " "it was corrupted on transfer to this computer." "\n\n" "It is recommended that you reboot and abort your " "installation, but you can choose to continue if " "you think this is in error." % (file,), type="custom", custom_icon="warning", custom_buttons= [_("_Reboot"), _("_Continue")]) if rc == 0: sys.exit(0) discImages[num] = file isys.umount("/mnt/cdimage") except SystemError: pass isys.makeDevInode("loop2", '/tmp/' + "loop2") isys.unlosetup("/tmp/loop2") return discImages
from sys import argv def usage(): print "usage: losetup [-d] /dev/loopN [image]" sys.exit(1) if len(argv) < 3: usage() if argv[1] == "-d" and len(argv[2]) > 4 and argv[2][-5:-1] == "loop": try: isys.makeDevInode(argv[2][-5:], argv[2]) isys.unlosetup(argv[2]) except SystemError, (errno, msg): print msg sys.exit(1) sys.exit(0) if len(argv[1]) > 4 and argv[1][-5:-1] == "loop": try: isys.makeDevInode(argv[1][-5:], argv[1]) isys.losetup(argv[1], argv[2]) except SystemError, (errno, msg): print msg sys.exit(1) sys.exit(0) usage()