Пример #1
0
                continue
            mode = stat_out.st_mode
            if (stat.S_ISREG(mode) and not (stat_out.st_size == 0)):
                uc_list.append(nc_file)
            else:
                print >> sys.stderr, (sys.argv[0] + ": " + "Couldn't mark " +
                                      nc_file +
                                      " as uncompressed in boot_archive: " +
                                      "not a non-zero-sized regular file")
                status = 1
        if (status != 0):
            raise Exception, (sys.argv[0] + ": Error building "
                              "list of uncompressed boot_archive files.")

    # Get expanded uncompressed list
    exp_uc_flist = find(uc_list)

    #
    # Create set of entries to be compressed by differentiating following sets:
    #  - set describing whole boot archive
    #  - set of entries not eligible for compression
    #
    compress_fset = set(ba_flist) - set(exp_uc_flist)

    #
    # Enumerate through set of entries eligible for compression and compress
    # those entries which meet all of the following criteria:
    #
    #  - it is a regular file
    #  - size > 0
    #  - it is NOT a hardlink
Пример #2
0
def compress(src, dst):
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    """ fiocompress files in the dst. The files listed in
    boot/solaris/filelist.ramdisk and files in usr/kernel are recopied
    because we can't have them compressed.

    Args:
      src : directory files are copied to dst from.
      dst : directory to fiocompress files in.

    Returns: N/A

    Raises: Exception

    """
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    os.chdir(src)

    #
    # Create list of boot archive files/directories.
    # Since passed with '.' relative path, find() generates paths
    # starting with './'
    #
    ba_flist = find(["."])
    errors = False

    #
    # Assemble list of files/directories which are not eligible for compression.
    # Start with the files/dirs in filelist.ramdisk.
    #
    # Make sure that relative path start with './', so that exclusion algorithm
    # below works as expected.
    #
    rdfd = open("boot/solaris/filelist.ramdisk", 'r')
    uc_list = []
    for filename in rdfd:
        if not filename.startswith('./'):
            filename = os.path.join('./', filename)
        uc_list.append(filename.strip())
    rdfd.close()

    # Append ./usr/kernel directory
    uc_list.append("./usr/kernel")

    # Add (regular) files specified in manifest with fiocompress="false"
    # Verify that they are non-zero-length, regular files first.
    manflist = get_manifest_list(
        MANIFEST_READER_OBJ, BOOT_ARCHIVE_CONTENTS_BASE_INCLUDE_NOCOMPRESS)
    if manflist:
        status = 0
        for nc_file in manflist:
            if not nc_file.startswith('./'):
                nc_file = os.path.join('./', nc_file)

            try:
                stat_out = os.lstat(nc_file)
            except OSError, err:
                print >> sys.stderr, (
                    sys.argv[0] + ": Couldn't stat %s to mark as " +
                    "uncompressed in boot_archive: %s") % (nc_file,
                                                           err.strerror)
                status = 1
                continue
            mode = stat_out.st_mode
            if (stat.S_ISREG(mode) and not (stat_out.st_size == 0)):
                uc_list.append(nc_file)
            else:
                print >> sys.stderr, (sys.argv[0] + ": " + "Couldn't mark " +
                                      nc_file +
                                      " as uncompressed in boot_archive: " +
                                      "not a non-zero-sized regular file")
                status = 1
        if (status != 0):
            raise Exception, (sys.argv[0] + ": Error building "
                              "list of uncompressed boot_archive files.")
Пример #3
0
def compress(src, dst):
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    """ fiocompress files in the dst. The files listed in
    boot/solaris/filelist.ramdisk and files in usr/kernel are recopied
    because we can't have them compressed.

    Args:
      src : directory files are copied to dst from.
      dst : directory to fiocompress files in.

    Returns: N/A

    Raises: Exception

    """
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    os.chdir(src)

    #
    # Create list of boot archive files/directories.
    # Since passed with '.' relative path, find() generates paths
    # starting with './'
    #
    ba_flist = find(["."])
    errors = False

    #
    # Assemble list of files/directories which are not eligible for compression.
    # Start with the files/dirs in filelist.ramdisk.
    #
    # Make sure that relative path start with './', so that exclusion algorithm
    # below works as expected.
    #
    rdfd = open("boot/solaris/filelist.ramdisk", 'r')
    uc_list = []
    for filename in rdfd:
        if not filename.startswith('./'):
            filename = os.path.join('./', filename)
        uc_list.append(filename.strip())
    rdfd.close()

    # Append ./usr/kernel directory
    uc_list.append("./usr/kernel")

    # Add (regular) files specified in manifest with fiocompress="false"
    # Verify that they are non-zero-length, regular files first.
    manflist = get_manifest_list(MANIFEST_READER_OBJ,
                                 BOOT_ARCHIVE_CONTENTS_BASE_INCLUDE_NOCOMPRESS)
    if manflist:
        status = 0
        for nc_file in manflist:
            if not nc_file.startswith('./'):
                nc_file = os.path.join('./', nc_file)

            try:
                stat_out = os.lstat(nc_file)
            except OSError as err:
                print((sys.argv[0] +
                    ": Couldn't stat %s to mark as " +
                    "uncompressed in boot_archive: %s") % (
                    nc_file, err.strerror), file=sys.stderr)
                status = 1
                continue
            mode = stat_out.st_mode
            if (stat.S_ISREG(mode) and not (stat_out.st_size == 0)):
                uc_list.append(nc_file)
            else:
                print((sys.argv[0] + ": " +
                    "Couldn't mark " + nc_file +
                    " as uncompressed in boot_archive: " +
                    "not a non-zero-sized regular file"), file=sys.stderr)
                status = 1
        if (status != 0):
            raise Exception(sys.argv[0] + ": Error building "
                "list of uncompressed boot_archive files.")

    # Get expanded uncompressed list
    exp_uc_flist = find(uc_list)

    #
    # Create set of entries to be compressed by differentiating following sets:
    #  - set describing whole boot archive
    #  - set of entries not eligible for compression
    #
    compress_fset = set(ba_flist) - set(exp_uc_flist)

    #
    # Enumerate through set of entries eligible for compression and compress
    # those entries which meet all of the following criteria:
    #
    #  - it is a regular file
    #  - size > 0
    #  - it is NOT a hardlink
    #
    for cfile in compress_fset:
        # strip off the trailing \n
        cpio_file = cfile.strip()

        if os.access(cpio_file, os.F_OK):
            stat_out = os.lstat(cpio_file)
            mode = stat_out.st_mode
            if (stat.S_ISREG(mode) and not (stat_out.st_size == 0)
                and (stat_out.st_nlink < 2)):
                cmd = FIOCOMPRESS + " -mc " + cpio_file + \
                    " " + dst + "/" + cpio_file
                status = os.system(cmd)
                if (status != 0):
                    print((sys.argv[0] +
                        ": error compressing file " +
                        cpio_file + ": " +
                        os.strerror(status >> 8)), file=sys.stderr)
                    errors = True
    if (errors):
        raise Exception(sys.argv[0] + ": Error processing " +
                          "compressed boot_archive files")