def __init__(self, device): DiscInfo.__init__(self) self.context = 'video' self.offset = 0 if mediainfo.DEBUG > 1: print 'trying lsdvd for scanning the disc' if os.path.isdir(device): self.valid = self.isDVDdir(device) else: self.valid = self.isDisc(device) if self.valid and self.tracks: self.keys.append('length') self.length = 0 first = 0 for t in self.tracks: self.length += t.length if not first: first = t.length if self.length/len(self.tracks) == first: # badly mastered dvd self.length = first if mediainfo.DEBUG > 1: print 'lsdvd detection ok' self.mime = 'video/dvd' self.type = 'DVD' self.subtype = 'video'
def __init__(self, device): DiscInfo.__init__(self) self.context = 'video' self.offset = 0 if mediainfo.DEBUG > 1: print 'trying lsdvd for scanning the disc' if os.path.isdir(device): self.valid = self.isDVDdir(device) else: self.valid = self.isDisc(device) if self.valid and self.tracks: self.keys.append('length') self.length = 0 first = 0 for t in self.tracks: self.length += t.length if not first: first = t.length if self.length / len(self.tracks) == first: # badly mastered dvd self.length = first if mediainfo.DEBUG > 1: print 'lsdvd detection ok' self.mime = 'video/dvd' self.type = 'DVD' self.subtype = 'video'
def __init__(self,device): DiscInfo.__init__(self) self.context = 'unknown' self.offset = 0 self.valid = self.isDisc(device) self.mime = 'unknown/unknown' self.type = 'CD' self.subtype = 'data'
def __init__(self, device): DiscInfo.__init__(self) self.context = 'unknown' self.offset = 0 self.valid = self.isDisc(device) self.mime = 'unknown/unknown' self.type = 'CD' self.subtype = 'data'
def __init__(self,device): DiscInfo.__init__(self) self.context = 'video' self.offset = 0 self.valid = self.isDisc(device) self.mime = 'video/vcd' self.type = 'CD' self.subtype = 'video'
def __init__(self, device): DiscInfo.__init__(self) self.context = 'video' self.offset = 0 self.valid = self.isDisc(device) self.mime = 'video/vcd' self.type = 'CD' self.subtype = 'video'
def isDisc(self, device): if DiscInfo.isDisc(self, device) != 2: return 0 # brute force reading of the device to find out if it is a DVD f = open(device, 'rb') f.seek(32768, 0) buffer = f.read(60000) if buffer.find('UDF') == -1: f.close() return 0 # seems to be a DVD, read a little bit more buffer += f.read(550000) f.close() if buffer.find('VIDEO_TS') == -1 and \ buffer.find('VIDEO_TS.IFO') == -1 and \ buffer.find('OSTA UDF Compliant') == -1: return 0 ret = self.lsdvd(device) if not ret: # we are very sure this is a DVD, maybe the drive was not # ready, let's try again return self.lsdvd(device) return 1
def isDisc(self, device): if DiscInfo.isDisc(self, device) != 2: return 0 # brute force reading of the device to find out if it is a DVD f = open(device,'rb') f.seek(32768, 0) buffer = f.read(60000) if buffer.find('UDF') == -1: f.close() return 0 # seems to be a DVD, read a little bit more buffer += f.read(550000) f.close() if buffer.find('VIDEO_TS') == -1 and \ buffer.find('VIDEO_TS.IFO') == -1 and \ buffer.find('OSTA UDF Compliant') == -1: return 0 ret = self.lsdvd(device) if not ret: # we are very sure this is a DVD, maybe the drive was not # ready, let's try again return self.lsdvd(device) return 1
def isDisc(self, device): if DiscInfo.isDisc(self, device) != 2: return 0 # brute force reading of the device to find out if it is a DVD f = open(device,'rb') f.seek(32768, 0) buffer = f.read(60000) if buffer.find('UDF') == -1: f.close() return 0 # seems to be a DVD, read a little bit more buffer += f.read(550000) f.close() if buffer.find('VIDEO_TS') == -1 and buffer.find('VIDEO_TS.IFO') == -1 and \ buffer.find('OSTA UDF Compliant') == -1: return 0 # OK, try libdvdread title_num = ifoparser.open(device) if not title_num: return 0 for title in range(1, title_num+1): ti = DVDTitle(title) ti.trackno = title ti.trackof = title_num self.appendtrack(ti) ifoparser.close() return 1
def isDisc(self, device): if DiscInfo.isDisc(self, device) != 2: return 0 # brute force reading of the device to find out if it is a DVD f = open(device, 'rb') f.seek(32768, 0) buffer = f.read(60000) if buffer.find('UDF') == -1: f.close() return 0 # seems to be a DVD, read a little bit more buffer += f.read(550000) f.close() if buffer.find('VIDEO_TS') == -1 and buffer.find('VIDEO_TS.IFO') == -1 and \ buffer.find('OSTA UDF Compliant') == -1: return 0 # OK, try libdvdread title_num = ifoparser.open(device) if not title_num: return 0 for title in range(1, title_num + 1): ti = DVDTitle(title) ti.trackno = title ti.trackof = title_num self.appendtrack(ti) ifoparser.close() return 1
def isDisc(self, device): type = None if DiscInfo.isDisc(self, device) != 2: return 0 # brute force reading of the device to find out if it is a VCD f = open(device,'rb') f.seek(32768, 0) buffer = f.read(60000) f.close() if buffer.find('SVCD') > 0 and buffer.find('TRACKS.SVD') > 0 and \ buffer.find('ENTRIES.SVD') > 0: type = 'SVCD' elif buffer.find('INFO.VCD') > 0 and buffer.find('ENTRIES.VCD') > 0: type = 'VCD' else: return 0 # read the tracks to generate the title list device = open(device) (first, last) = cdrom.toc_header(device) lmin = 0 lsec = 0 num = 0 for i in range(first, last + 2): if i == last + 1: min, sec, frames = cdrom.leadout(device) else: min, sec, frames = cdrom.toc_entry(device, i) if num: vi = mediainfo.VideoInfo() # XXX add more static information here, it's also possible # XXX to scan for more informations like fps # XXX Settings to MPEG1/2 is a wild guess, maybe the track # XXX isn't playable at all (e.g. the menu) if type == 'VCD': vi.codec = 'MPEG1' else: vi.codec = 'MPEG2' vi.length = (min-lmin) * 60 + (sec-lsec) self.tracks.append(vi) num += 1 lmin, lsec = min, sec device.close() return 1
def isDisc(self, device): type = None if DiscInfo.isDisc(self, device) != 2: return 0 # brute force reading of the device to find out if it is a VCD f = open(device, 'rb') f.seek(32768, 0) buffer = f.read(60000) f.close() if buffer.find('SVCD') > 0 and buffer.find('TRACKS.SVD') > 0 and \ buffer.find('ENTRIES.SVD') > 0: type = 'SVCD' elif buffer.find('INFO.VCD') > 0 and buffer.find('ENTRIES.VCD') > 0: type = 'VCD' else: return 0 # read the tracks to generate the title list device = open(device) (first, last) = cdrom.toc_header(device) lmin = 0 lsec = 0 num = 0 for i in range(first, last + 2): if i == last + 1: min, sec, frames = cdrom.leadout(device) else: min, sec, frames = cdrom.toc_entry(device, i) if num: vi = mediainfo.VideoInfo() # XXX add more static information here, it's also possible # XXX to scan for more informations like fps # XXX Settings to MPEG1/2 is a wild guess, maybe the track # XXX isn't playable at all (e.g. the menu) if type == 'VCD': vi.codec = 'MPEG1' else: vi.codec = 'MPEG2' vi.length = (min - lmin) * 60 + (sec - lsec) self.tracks.append(vi) num += 1 lmin, lsec = min, sec device.close() return 1
def isDisc(self, device): if DiscInfo.isDisc(self, device) != 2: return 0 return 1
def run(self, ybo, product, version, release, variant="", bugurl="", isfinal=False, workdir=None, outputdir=None, buildarch=None, volid=None, domacboot=False, doupgrade=True, remove_temp=False, installpkgs=None, ssss=None, size=2, add_templates=None, add_template_vars=None, add_arch_templates=None, add_arch_template_vars=None, template_tempdir=None): assert self._configured installpkgs = installpkgs or [] # get lorax version try: import pylorax.version except ImportError: vernum = "devel" else: vernum = pylorax.version.num if domacboot: try: runcmd(["rpm", "-q", "hfsplus-tools"]) except CalledProcessError: logger.critical("you need to install hfsplus-tools to create mac images") sys.exit(1) # set up work directory self.workdir = workdir or tempfile.mkdtemp(prefix="pylorax.work.") if not os.path.isdir(self.workdir): os.makedirs(self.workdir) # set up log directory logdir = '/var/log/lorax' if not os.path.isdir(logdir): os.makedirs(logdir) self.init_stream_logging() self.init_file_logging(logdir) logger.debug("version is {0}".format(vernum)) logger.debug("using work directory {0.workdir}".format(self)) logger.debug("using log directory {0}".format(logdir)) # set up output directory self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.") if not os.path.isdir(self.outputdir): os.makedirs(self.outputdir) logger.debug("using output directory {0.outputdir}".format(self)) # do we have root privileges? logger.info("checking for root privileges") if not os.geteuid() == 0: logger.critical("no root privileges") sys.exit(1) # is selinux disabled? # With selinux in enforcing mode the rpcbind package required for # dracut nfs module, which is in turn required by anaconda module, # will not get installed, because it's preinstall scriptlet fails, # resulting in an incomplete initial ramdisk image. # The reason is that the scriptlet runs tools from the shadow-utils # package in chroot, particularly groupadd and useradd to add the # required rpc group and rpc user. This operation fails, because # the selinux context on files in the chroot, that the shadow-utils # tools need to access (/etc/group, /etc/passwd, /etc/shadow etc.), # is wrong and selinux therefore disallows access to these files. logger.info("checking the selinux mode") if selinux.is_selinux_enabled() and selinux.security_getenforce(): logger.critical("selinux must be disabled or in Permissive mode") sys.exit(1) # do we have a proper yum base object? logger.info("checking yum base object") if not isinstance(ybo, yum.YumBase): logger.critical("no yum base object") sys.exit(1) self.inroot = ybo.conf.installroot logger.debug("using install root: {0}".format(self.inroot)) if not buildarch: buildarch = get_buildarch(ybo) logger.info("setting up build architecture") self.arch = ArchData(buildarch) for attr in ('buildarch', 'basearch', 'libdir'): logger.debug("self.arch.%s = %s", attr, getattr(self.arch,attr)) logger.info("setting up build parameters") product = DataHolder(name=product, version=version, release=release, variant=variant, bugurl=bugurl, isfinal=isfinal) self.product = product logger.debug("product data: %s" % product) # NOTE: if you change isolabel, you need to change pungi to match, or # the pungi images won't boot. isolabel = volid or "{0.name} {0.version} {1.basearch}".format(self.product, self.arch) if len(isolabel) > 32: logger.fatal("the volume id cannot be longer than 32 characters") sys.exit(1) templatedir = self.conf.get("lorax", "sharedir") # NOTE: rb.root = ybo.conf.installroot (== self.inroot) rb = RuntimeBuilder(product=self.product, arch=self.arch, yum=ybo, templatedir=templatedir, installpkgs=installpkgs, add_templates=add_templates, add_template_vars=add_template_vars) logger.info("installing runtime packages") rb.yum.conf.skip_broken = self.conf.getboolean("yum", "skipbroken") rb.install() # write .buildstamp buildstamp = BuildStamp(self.product.name, self.product.version, self.product.bugurl, self.product.isfinal, self.arch.buildarch) buildstamp.write(joinpaths(self.inroot, ".buildstamp")) if self.debug: rb.writepkglists(joinpaths(logdir, "pkglists")) rb.writepkgsizes(joinpaths(logdir, "original-pkgsizes.txt")) logger.info("doing post-install configuration") rb.postinstall() # write .discinfo discinfo = DiscInfo(self.product.release, self.arch.basearch) discinfo.write(joinpaths(self.outputdir, ".discinfo")) logger.info("backing up installroot") installroot = joinpaths(self.workdir, "installroot") linktree(self.inroot, installroot) logger.info("generating kernel module metadata") rb.generate_module_data() logger.info("cleaning unneeded files") rb.cleanup() if self.debug: rb.writepkgsizes(joinpaths(logdir, "final-pkgsizes.txt")) logger.info("creating the runtime image") runtime = "images/install.img" compression = self.conf.get("compression", "type") compressargs = self.conf.get("compression", "args").split() if self.conf.getboolean("compression", "bcj"): if self.arch.bcj: compressargs += ["-Xbcj", self.arch.bcj] else: logger.info("no BCJ filter for arch %s", self.arch.basearch) rb.create_runtime(joinpaths(installroot,runtime), compression=compression, compressargs=compressargs) logger.info("preparing to build output tree and boot images") treebuilder = TreeBuilder(product=self.product, arch=self.arch, inroot=installroot, outroot=self.outputdir, ssss=ssss, runtime=runtime, isolabel=isolabel, domacboot=domacboot, doupgrade=doupgrade, templatedir=templatedir, add_templates=add_arch_templates, add_template_vars=add_arch_template_vars, workdir=self.workdir) logger.info("rebuilding initramfs images") dracut_args = ["--xz", "--install", "/.buildstamp", "--no-early-microcode"] anaconda_args = dracut_args + ["--add", "anaconda pollcdrom"] # ppc64 cannot boot an initrd > 32MiB so remove some drivers if self.arch.basearch in ("ppc64", "ppc64le"): dracut_args.extend(["--omit-drivers", REMOVE_PPC64_DRIVERS]) # Only omit dracut modules from the initrd so that they're kept for # upgrade.img anaconda_args.extend(["--omit", REMOVE_PPC64_MODULES]) treebuilder.rebuild_initrds(add_args=anaconda_args) if doupgrade: # Build upgrade.img. It'd be nice if these could coexist in the same # image, but that would increase the size of the anaconda initramfs, # which worries some people (esp. PPC tftpboot). So they're separate. try: # If possible, use the 'redhat-upgrade-tool' plymouth theme themes = runcmd_output(['plymouth-set-default-theme', '--list'], root=installroot) if 'redhat-upgrade-tool' in themes.splitlines(): os.environ['PLYMOUTH_THEME_NAME'] = 'redhat-upgrade-tool' except RuntimeError: pass upgrade_args = dracut_args + ["--add", "system-upgrade convertfs"] treebuilder.rebuild_initrds(add_args=upgrade_args, prefix="upgrade") logger.info("populating output tree and building boot images") treebuilder.build() # write .treeinfo file and we're done treeinfo = TreeInfo(self.product.name, self.product.version, self.product.variant, self.arch.basearch) for section, data in treebuilder.treeinfo_data.items(): treeinfo.add_section(section, data) treeinfo.write(joinpaths(self.outputdir, ".treeinfo")) # cleanup if remove_temp: remove(self.workdir)
def run(self, ybo, product, version, release, variant="", bugurl="", isfinal=False, workdir=None, outputdir=None, buildarch=None, volid=None, domacboot=False, doupgrade=True, remove_temp=False): assert self._configured # get lorax version try: import pylorax.version except ImportError: vernum = "devel" else: vernum = pylorax.version.num if domacboot: try: runcmd(["rpm", "-q", "hfsplus-tools"]) except CalledProcessError: logger.critical("you need to install hfsplus-tools to create mac images") sys.exit(1) # set up work directory self.workdir = workdir or tempfile.mkdtemp(prefix="pylorax.work.") if not os.path.isdir(self.workdir): os.makedirs(self.workdir) # set up log directory logdir = '/var/log/lorax' if not os.path.isdir(logdir): os.makedirs(logdir) self.init_stream_logging() self.init_file_logging(logdir) logger.debug("version is {0}".format(vernum)) logger.debug("using work directory {0.workdir}".format(self)) logger.debug("using log directory {0}".format(logdir)) # set up output directory self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.") if not os.path.isdir(self.outputdir): os.makedirs(self.outputdir) logger.debug("using output directory {0.outputdir}".format(self)) # do we have root privileges? logger.info("checking for root privileges") if not os.geteuid() == 0: logger.critical("no root privileges") sys.exit(1) # is selinux disabled? # With selinux in enforcing mode the rpcbind package required for # dracut nfs module, which is in turn required by anaconda module, # will not get installed, because it's preinstall scriptlet fails, # resulting in an incomplete initial ramdisk image. # The reason is that the scriptlet runs tools from the shadow-utils # package in chroot, particularly groupadd and useradd to add the # required rpc group and rpc user. This operation fails, because # the selinux context on files in the chroot, that the shadow-utils # tools need to access (/etc/group, /etc/passwd, /etc/shadow etc.), # is wrong and selinux therefore disallows access to these files. logger.info("checking the selinux mode") if selinux.is_selinux_enabled() and selinux.security_getenforce(): logger.critical("selinux must be disabled or in Permissive mode") sys.exit(1) # do we have a proper yum base object? logger.info("checking yum base object") if not isinstance(ybo, yum.YumBase): logger.critical("no yum base object") sys.exit(1) self.inroot = ybo.conf.installroot logger.debug("using install root: {0}".format(self.inroot)) if not buildarch: buildarch = get_buildarch(ybo) logger.info("setting up build architecture") self.arch = ArchData(buildarch) for attr in ('buildarch', 'basearch', 'libdir'): logger.debug("self.arch.%s = %s", attr, getattr(self.arch,attr)) logger.info("setting up build parameters") product = DataHolder(name=product, version=version, release=release, variant=variant, bugurl=bugurl, isfinal=isfinal) self.product = product logger.debug("product data: %s" % product) # NOTE: if you change isolabel, you need to change pungi to match, or # the pungi images won't boot. isolabel = volid or "{0.name} {0.version} {1.basearch}".format(self.product, self.arch) if len(isolabel) > 32: logger.fatal("the volume id cannot be longer than 32 characters") sys.exit(1) templatedir = self.conf.get("lorax", "sharedir") # NOTE: rb.root = ybo.conf.installroot (== self.inroot) rb = RuntimeBuilder(product=self.product, arch=self.arch, yum=ybo, templatedir=templatedir) logger.info("installing runtime packages") rb.yum.conf.skip_broken = self.conf.getboolean("yum", "skipbroken") rb.install() # write .buildstamp buildstamp = BuildStamp(self.product.name, self.product.version, self.product.bugurl, self.product.isfinal, self.arch.buildarch) buildstamp.write(joinpaths(self.inroot, ".buildstamp")) if self.debug: rb.writepkglists(joinpaths(logdir, "pkglists")) rb.writepkgsizes(joinpaths(logdir, "original-pkgsizes.txt")) logger.info("doing post-install configuration") rb.postinstall() # write .discinfo discinfo = DiscInfo(self.product.release, self.arch.basearch) discinfo.write(joinpaths(self.outputdir, ".discinfo")) logger.info("backing up installroot") installroot = joinpaths(self.workdir, "installroot") linktree(self.inroot, installroot) logger.info("generating kernel module metadata") rb.generate_module_data() logger.info("cleaning unneeded files") rb.cleanup() if self.debug: rb.writepkgsizes(joinpaths(logdir, "final-pkgsizes.txt")) logger.info("creating the runtime image") runtime = "images/install.img" compression = self.conf.get("compression", "type") compressargs = self.conf.get("compression", "args").split() if self.conf.getboolean("compression", "bcj"): if self.arch.bcj: compressargs += ["-Xbcj", self.arch.bcj] else: logger.info("no BCJ filter for arch %s", self.arch.basearch) rb.create_runtime(joinpaths(installroot,runtime), compression=compression, compressargs=compressargs) logger.info("preparing to build output tree and boot images") treebuilder = TreeBuilder(product=self.product, arch=self.arch, inroot=installroot, outroot=self.outputdir, runtime=runtime, isolabel=isolabel, domacboot=domacboot, doupgrade=doupgrade, templatedir=templatedir) logger.info("rebuilding initramfs images") dracut_args = ["--xz", "--install", "/.buildstamp"] anaconda_args = dracut_args + ["--add", "anaconda pollcdrom"] # ppc64 cannot boot an initrd > 32MiB so remove some drivers if self.arch.basearch in ("ppc64", "ppc64le"): dracut_args.extend(["--omit-drivers", REMOVE_PPC64_DRIVERS]) # Only omit dracut modules from the initrd so that they're kept for # upgrade.img anaconda_args.extend(["--omit", REMOVE_PPC64_MODULES]) treebuilder.rebuild_initrds(add_args=anaconda_args) if doupgrade: # Build upgrade.img. It'd be nice if these could coexist in the same # image, but that would increase the size of the anaconda initramfs, # which worries some people (esp. PPC tftpboot). So they're separate. try: # If possible, use the 'redhat-upgrade-tool' plymouth theme themes = runcmd_output(['plymouth-set-default-theme', '--list'], root=installroot) if 'redhat-upgrade-tool' in themes.splitlines(): os.environ['PLYMOUTH_THEME_NAME'] = 'redhat-upgrade-tool' except RuntimeError: pass upgrade_args = dracut_args + ["--add", "system-upgrade convertfs"] treebuilder.rebuild_initrds(add_args=upgrade_args, prefix="upgrade") logger.info("populating output tree and building boot images") treebuilder.build() # write .treeinfo file and we're done treeinfo = TreeInfo(self.product.name, self.product.version, self.product.variant, self.arch.basearch) for section, data in treebuilder.treeinfo_data.items(): treeinfo.add_section(section, data) treeinfo.write(joinpaths(self.outputdir, ".treeinfo")) # cleanup if remove_temp: remove(self.workdir)