Esempio n. 1
0
    def write_fstab(self, xml):
        if not self.exists("etc"):
            self.mkdir("etc")

        f = self.open("etc/fstab", "w")
        if xml.tgt.has("fstab"):
            for fs in xml.tgt.node("fstab"):
                fstab = fstabentry(xml, fs)
                f.write(fstab.get_str())
            f.close()
Esempio n. 2
0
    def write_fstab(self, xml):
        if not self.exists("etc"):
            self.mkdir("etc")

        f = self.open("etc/fstab", "w")
        if xml.tgt.has("fstab"):
            for fs in xml.tgt.node("fstab"):
                fstab = fstabentry(xml, fs)
                f.write (fstab.get_str ())
            f.close()
Esempio n. 3
0
def do_hdimg(xml, target, rfs, grub_version, grub_fw_type=None):

    # pylint: disable=too-many-arguments
    # pylint: disable=too-many-locals
    # pylint: disable=too-many-branches

    # list of created files
    img_files = []

    # Check whether we have any images first
    if not xml.tgt.has("images"):
        return img_files

    # Build a dictonary of mount points
    fslabel = {}
    mountpoints = mountpoint_dict()

    for fs in xml.tgt.node("fstab"):
        if fs.tag != "bylabel":
            continue

        # Create fstabentry Object
        e = fstabentry(xml, fs)

        # register it with mountpoints,
        # this also sets the id field
        mountpoints.register(e)

        fslabel[fs.text("label")] = e

    # Get the sorted list of mountpoints
    fslist = mountpoints.depthlist()

    # create directories, where we want our
    # filesystems later
    fspath = os.path.join(target, "filesystems")
    do('mkdir -p %s' % fspath)

    imagemnt = os.path.join(target, "imagemnt")
    do('mkdir -p %s' % imagemnt)

    # now move all mountpoints into own directories
    # begin from deepest mountpoints
    for l in reversed(fslist):
        do('mkdir -p "%s"' % os.path.join(fspath, l.id))
        do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
        if rfs.listdir(l.mountpoint):
            do('mv "%s"/* "%s"' %
               (rfs.fname(l.mountpoint), os.path.join(fspath, l.id)),
               allow_fail=True)

    try:
        # Now iterate over all images and create filesystems and partitions
        for i in xml.tgt.node("images"):
            if i.tag == "msdoshd":
                img = do_image_hd(i, fslabel, target, grub_version,
                                  grub_fw_type)
                img_files.append(img)

            if i.tag == "gpthd":
                img = do_image_hd(i, fslabel, target, grub_version,
                                  grub_fw_type)
                img_files.append(img)

            if i.tag == "mtd":
                imgs = mkfs_mtd(i, fslabel, target)
                img_files.extend(imgs)
    finally:
        # Put back the filesystems into /target
        # most shallow fs first...
        for i in fslist:
            if len(os.listdir(os.path.join(fspath, i.id))) > 0:
                do('mv "%s"/* "%s"' %
                   (os.path.join(fspath, i.id), rfs.fname(i.mountpoint)),
                   allow_fail=True)

    # Files are now moved back. ubinize needs files in place, so we run it now.
    for i in xml.tgt.node("images"):
        if i.tag == "mtd":
            imgs = build_image_mtd(i, target)
            img_files.extend(imgs)

    # dd binary blobs onto images
    for i in xml.tgt.node("images"):
        if (i.tag == "msdoshd") or (i.tag == "gpthd"):
            add_binary_blob(i, target)

    # use set() to remove duplicates, but
    # return a list
    return list(set(img_files))
Esempio n. 4
0
def do_hdimg(outf, xml, target, rfs, grub_version):
    # list of created files
    img_files = []

    # Check whether we have any images first
    if not xml.tgt.has("images"):
        return img_files

    # Build a dictonary of mount points
    fslabel = {}
    for fs in xml.tgt.node("fstab"):
        if fs.tag != "bylabel":
            continue

        fslabel[fs.text("label")] = fstabentry(xml, fs)

    # Build a sorted list of mountpoints
    fslist = fslabel.values()
    fslist.sort( key = lambda x: x.mountdepth() )

    # now move all mountpoints into own directories
    # begin from deepest mountpoints

    fspath = os.path.join(target, "filesystems")
    outf.do( 'mkdir -p %s' % fspath )

    imagemnt = os.path.join(target, "imagemnt")
    outf.do( 'mkdir -p %s' % imagemnt )

    for l in reversed(fslist):
        outf.do( 'mkdir -p "%s"' % os.path.join( fspath, l.label ) )
        outf.do( 'mkdir -p "%s"' % rfs.fname('') + l.mountpoint )
        if len(rfs.listdir( l.mountpoint )) > 0:
            outf.do( 'mv "%s"/* "%s"' % ( rfs.fname(l.mountpoint), os.path.join(
                fspath, l.label ) ), allow_fail=True )

    try:
        # Now iterate over all images and create filesystems and partitions
        for i in xml.tgt.node("images"):
            if i.tag == "msdoshd":
                img = do_image_hd( outf, i, fslabel, target, grub_version )
                img_files.append (img)

            if i.tag == "gpthd":
                img = do_image_hd( outf, i, fslabel, target, grub_version )
                img_files.append (img)

            if i.tag == "mtd":
                imgs = mkfs_mtd( outf, i, fslabel, rfs, target )
                img_files.extend (imgs)
    finally:
        # Put back the filesystems into /target
        # most shallow fs first...
        for i in fslist:
            if len(os.listdir(os.path.join( fspath, i.label ))) > 0:
                outf.do( 'mv "%s"/* "%s"' % ( os.path.join( fspath, i.label ),
                    rfs.fname(i.mountpoint) ), allow_fail=True )

    # Files are now moved back. ubinize needs files in place, so we run it now.
    for i in xml.tgt.node("images"):
        if i.tag == "mtd":
            imgs = build_image_mtd( outf, i, target )
            img_files.extend (imgs)

    gz_img_files = []
    for i in set(img_files):
        try:
            outf.do ( 'gzip "%s"' % os.path.join (target, i))
            # only add gz to gz_img_files, if no exception is thrown
            gz_img_files.append( i+".gz" )
        except CommandError:
            pass

    return gz_img_files
Esempio n. 5
0
def do_hdimg(outf, xml, target, rfs, grub_version):
    # list of created files
    img_files = []

    # Check whether we have any images first
    if not xml.tgt.has("images"):
        return img_files

    # Build a dictonary of mount points
    fslabel = {}
    for fs in xml.tgt.node("fstab"):
        if fs.tag != "bylabel":
            continue

        fslabel[fs.text("label")] = fstabentry(xml, fs)

    # Build a sorted list of mountpoints
    fslist = fslabel.values()
    fslist.sort(key=lambda x: x.mountdepth())

    # now move all mountpoints into own directories
    # begin from deepest mountpoints

    fspath = os.path.join(target, "filesystems")
    outf.do('mkdir -p %s' % fspath)

    imagemnt = os.path.join(target, "imagemnt")
    outf.do('mkdir -p %s' % imagemnt)

    for l in reversed(fslist):
        outf.do('mkdir -p "%s"' % os.path.join(fspath, l.label))
        outf.do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
        if len(rfs.listdir(l.mountpoint)) > 0:
            outf.do('mv "%s"/* "%s"' %
                    (rfs.fname(l.mountpoint), os.path.join(fspath, l.label)),
                    allow_fail=True)

    try:
        # Now iterate over all images and create filesystems and partitions
        for i in xml.tgt.node("images"):
            if i.tag == "msdoshd":
                img = do_image_hd(outf, i, fslabel, target, grub_version)
                img_files.append(img)

            if i.tag == "gpthd":
                img = do_image_hd(outf, i, fslabel, target, grub_version)
                img_files.append(img)

            if i.tag == "mtd":
                imgs = mkfs_mtd(outf, i, fslabel, rfs, target)
                img_files.extend(imgs)
    finally:
        # Put back the filesystems into /target
        # most shallow fs first...
        for i in fslist:
            if len(os.listdir(os.path.join(fspath, i.label))) > 0:
                outf.do(
                    'mv "%s"/* "%s"' %
                    (os.path.join(fspath, i.label), rfs.fname(i.mountpoint)),
                    allow_fail=True)

    # Files are now moved back. ubinize needs files in place, so we run it now.
    for i in xml.tgt.node("images"):
        if i.tag == "mtd":
            imgs = build_image_mtd(outf, i, target)
            img_files.extend(imgs)

    gz_img_files = []
    for i in set(img_files):
        try:
            outf.do('gzip "%s"' % os.path.join(target, i))
            # only add gz to gz_img_files, if no exception is thrown
            gz_img_files.append(i + ".gz")
        except CommandError:
            pass

    return gz_img_files
Esempio n. 6
0
File: hdimg.py Progetto: zumbi/elbe
def do_hdimg(outf, xml, target, rfs, grub_version):
    # list of created files
    img_files = []

    # Check whether we have any images first
    if not xml.tgt.has("images"):
        return img_files

    # Build a dictonary of mount points
    fslabel = {}
    mountpoints = mountpoint_dict()

    for fs in xml.tgt.node("fstab"):
        if fs.tag != "bylabel":
            continue

        # Create fstabentry Object
        e = fstabentry(xml, fs)

        # register it with mountpoints,
        # this also sets the id field
        mountpoints.register(e)

        fslabel[fs.text("label")] = e

    # Get the sorted list of mountpoints
    fslist = mountpoints.depthlist()

    # create directories, where we want our
    # filesystems later
    fspath = os.path.join(target, "filesystems")
    outf.do('mkdir -p %s' % fspath)

    imagemnt = os.path.join(target, "imagemnt")
    outf.do('mkdir -p %s' % imagemnt)

    # now move all mountpoints into own directories
    # begin from deepest mountpoints
    for l in reversed(fslist):
        outf.do('mkdir -p "%s"' % os.path.join(fspath, l.id))
        outf.do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
        if len(rfs.listdir(l.mountpoint)) > 0:
            outf.do('mv "%s"/* "%s"' %
                    (rfs.fname(l.mountpoint), os.path.join(fspath, l.id)),
                    allow_fail=True)

    try:
        # Now iterate over all images and create filesystems and partitions
        for i in xml.tgt.node("images"):
            if i.tag == "msdoshd":
                img = do_image_hd(outf, i, fslabel, target, grub_version)
                img_files.append(img)

            if i.tag == "gpthd":
                img = do_image_hd(outf, i, fslabel, target, grub_version)
                img_files.append(img)

            if i.tag == "mtd":
                imgs = mkfs_mtd(outf, i, fslabel, rfs, target)
                img_files.extend(imgs)
    finally:
        # Put back the filesystems into /target
        # most shallow fs first...
        for i in fslist:
            if len(os.listdir(os.path.join(fspath, i.id))) > 0:
                outf.do('mv "%s"/* "%s"' %
                        (os.path.join(fspath, i.id), rfs.fname(i.mountpoint)),
                        allow_fail=True)

    # Files are now moved back. ubinize needs files in place, so we run it now.
    for i in xml.tgt.node("images"):
        if i.tag == "mtd":
            imgs = build_image_mtd(outf, i, target)
            img_files.extend(imgs)

    # dd binary blobs onto images
    for i in xml.tgt.node("images"):
        if (i.tag == "msdoshd") or (i.tag == "gpt"):
            add_binary_blob(outf, i, target)

    gz_img_files = []
    for i in set(img_files):
        try:
            outf.do('gzip -f "%s"' % os.path.join(target, i))
            # only add gz to gz_img_files, if no exception is thrown
            gz_img_files.append(i + ".gz")
        except CommandError:
            pass

    return gz_img_files
Esempio n. 7
0
def do_hdimg(outf, xml, target, rfs, grub_version, grub_fw_type=None):

    # pylint: disable=too-many-arguments
    # pylint: disable=too-many-locals
    # pylint: disable=too-many-branches

    # list of created files
    img_files = []

    # Check whether we have any images first
    if not xml.tgt.has("images"):
        return img_files

    # Build a dictonary of mount points
    fslabel = {}
    mountpoints = mountpoint_dict()

    for fs in xml.tgt.node("fstab"):
        if fs.tag != "bylabel":
            continue

        # Create fstabentry Object
        e = fstabentry(xml, fs)

        # register it with mountpoints,
        # this also sets the id field
        mountpoints.register(e)

        fslabel[fs.text("label")] = e

    # Get the sorted list of mountpoints
    fslist = mountpoints.depthlist()

    # create directories, where we want our
    # filesystems later
    fspath = os.path.join(target, "filesystems")
    outf.do('mkdir -p %s' % fspath)

    imagemnt = os.path.join(target, "imagemnt")
    outf.do('mkdir -p %s' % imagemnt)

    # now move all mountpoints into own directories
    # begin from deepest mountpoints
    for l in reversed(fslist):
        outf.do('mkdir -p "%s"' % os.path.join(fspath, l.id))
        outf.do('mkdir -p "%s"' % rfs.fname('') + l.mountpoint)
        if rfs.listdir(l.mountpoint):
            outf.do('mv "%s"/* "%s"' % (rfs.fname(l.mountpoint), os.path.join(
                fspath, l.id)), allow_fail=True)

    try:
        # Now iterate over all images and create filesystems and partitions
        for i in xml.tgt.node("images"):
            if i.tag == "msdoshd":
                img = do_image_hd(
                    outf,
                    i,
                    fslabel,
                    target,
                    grub_version,
                    grub_fw_type)
                img_files.append(img)

            if i.tag == "gpthd":
                img = do_image_hd(
                    outf,
                    i,
                    fslabel,
                    target,
                    grub_version,
                    grub_fw_type)
                img_files.append(img)

            if i.tag == "mtd":
                imgs = mkfs_mtd(outf, i, fslabel, target)
                img_files.extend(imgs)
    finally:
        # Put back the filesystems into /target
        # most shallow fs first...
        for i in fslist:
            if len(os.listdir(os.path.join(fspath, i.id))) > 0:
                outf.do(
                    'mv "%s"/* "%s"' %
                    (os.path.join(
                        fspath, i.id), rfs.fname(
                        i.mountpoint)), allow_fail=True)

    # Files are now moved back. ubinize needs files in place, so we run it now.
    for i in xml.tgt.node("images"):
        if i.tag == "mtd":
            imgs = build_image_mtd(outf, i, target)
            img_files.extend(imgs)

    # dd binary blobs onto images
    for i in xml.tgt.node("images"):
        if (i.tag == "msdoshd") or (i.tag == "gpthd"):
            add_binary_blob(outf, i, target)

    # use set() to remove duplicates, but
    # return a list
    return list(set(img_files))