def add_copy_spec(self, copyspecs, sizelimit=None, tailit=True, pred=None):
        """Add a file or glob but limit it to sizelimit megabytes. If fname is
        a single file the file will be tailed to meet sizelimit. If the first
        file in a glob is too large it will be tailed to meet the sizelimit.
        """
        if not self.test_predicate(pred=pred):
            self._log_info("skipped copy spec '%s' due to predicate (%s)" %
                           (copyspecs, self.get_predicate(pred=pred)))
            return

        if sizelimit is None:
            sizelimit = self.get_option("log_size")

        if self.get_option('all_logs'):
            sizelimit = None

        if sizelimit:
            sizelimit *= 1024 * 1024  # in MB

        if not copyspecs:
            return False

        if isinstance(copyspecs, six.string_types):
            copyspecs = [copyspecs]

        for copyspec in copyspecs:
            if not (copyspec and len(copyspec)):
                return False

            if self.use_sysroot():
                copyspec = self.join_sysroot(copyspec)

            files = self._expand_copy_spec(copyspec)

            if len(files) == 0:
                continue

            # Files hould be sorted in most-recently-modified order, so that
            # we collect the newest data first before reaching the limit.
            def getmtime(path):
                try:
                    return os.path.getmtime(path)
                except OSError:
                    return 0

            files.sort(key=getmtime, reverse=True)
            current_size = 0
            limit_reached = False
            _file = None

            for _file in files:
                if self._is_forbidden_path(_file):
                    self._log_debug("skipping forbidden path '%s'" % _file)
                    continue
                try:
                    current_size += os.stat(_file)[stat.ST_SIZE]
                except OSError:
                    self._log_info("failed to stat '%s'" % _file)
                if sizelimit and current_size > sizelimit:
                    limit_reached = True
                    break
                self._add_copy_paths([_file])

            if limit_reached and tailit and not _file_is_compressed(_file):
                file_name = _file

                if file_name[0] == os.sep:
                    file_name = file_name.lstrip(os.sep)
                strfile = file_name.replace(os.path.sep, ".") + ".tailed"
                self.add_string_as_file(tail(_file, sizelimit), strfile)
                rel_path = os.path.relpath('/', os.path.dirname(_file))
                link_path = os.path.join(rel_path, 'sos_strings',
                                         self.name(), strfile)
                self.archive.add_link(link_path, _file)
def add_copy_spec ( self , copyspecs , sizelimit = None , tailit = True , pred = None ) : if not self . test_predicate ( pred = pred ) : self . _log_info ( "skipped copy spec '%s' due to predicate (%s)" % ( copyspecs , self . get_predicate ( pred = pred ) ) ) return if sizelimit is None : sizelimit = self . get_option ( "log_size" ) if self . get_option ( 'all_logs' ) : sizelimit = None if sizelimit : sizelimit *= 1024 * 1024 if not copyspecs : return False if isinstance ( copyspecs , six . string_types ) : copyspecs = [ copyspecs ] for copyspec in copyspecs : if not ( copyspec and len ( copyspec ) ) : return False if self . use_sysroot ( ) : copyspec = self . join_sysroot ( copyspec ) files = self . _expand_copy_spec ( copyspec ) if len ( files ) == 0 : continue def getmtime ( path ) : try : return os . path . getmtime ( path ) except OSError : return 0 files . sort ( key = getmtime , reverse = True ) current_size = 0 limit_reached = False _file = None for _file in files : if self . _is_forbidden_path ( _file ) : self . _log_debug ( "skipping forbidden path '%s'" % _file ) continue try : current_size += os . stat ( _file ) [ stat . ST_SIZE ] except OSError : self . _log_info ( "failed to stat '%s'" % _file ) if sizelimit and current_size > sizelimit : limit_reached = True break self . _add_copy_paths ( [ _file ] ) if limit_reached and tailit and not _file_is_compressed ( _file ) : file_name = _file if file_name [ 0 ] == os . sep : file_name = file_name . lstrip ( os . sep ) strfile = file_name . replace ( os . path . sep , "." ) + ".tailed" self . add_string_as_file ( tail ( _file , sizelimit ) , strfile ) rel_path = os . path . relpath ( '/' , os . path . dirname ( _file ) ) link_path = os . path . join ( rel_path , 'sos_strings' , self . name ( ) , strfile ) self . archive . add_link ( link_path , _file )
Add a file or glob but limit it to sizelimit megabytes. If fname is
        a single file the file will be tailed to meet sizelimit. If the first
        file in a glob is too large it will be tailed to meet the sizelimit.