Пример #1
0
 def test_bytes_to_human_readable(self):
     # Test if method correctly converts to MB
     for i in range(20):
         bt = random.randint(1048576, 943718400)
         human = bytes_to_human_readable(bt).split(' ')[1]
         self.assertEqual(human, 'MB', msg='Should be MB')
     # Test if method correctly converts to GB
     for i in range(20):
         bt = random.randint(1073741824, 549755813888)
         human = bytes_to_human_readable(bt).split(' ')[1]
         self.assertEqual(human, 'GB', msg='Should be GB')
Пример #2
0
    def _decorate_file_entry(cls, entry) -> tuple:
        """
        Decorates given entry for a file. By decorate it means that creates
        a colored representation of a name of the entry, grabs 
        the date it was last modified and size in bytes and decorates,
        determines file type. collects everything and returns as a list.
        """

        # Gives yellow color to the string & truncate to 32 chars
        current = [stylize("» " + entry.name[:33], fg(226))]

        # Convert last modified time (which is in nanoseconds)
        date = os.stat(entry).st_mtime
        current.append(
            DecoratedData(date, normalize_date('%h %d %Y %H:%M', date)))

        b = os.stat(entry).st_size
        current.append(DecoratedData(b, bytes_to_human_readable(b)))

        # Evaluate the file type
        current.append(magic.from_file(entry.path, mime=True))
        return tuple(current)
Пример #3
0
    def _decorate_dir_entry(cls, entry) -> tuple:
        """
        Decorates given entry for a directory. Decorate means that creates 
        a colored representation of a name of the entry, grabs 
        the date it was last modified and size in bytes and decorates.
        collects everything and returns as a list.
        """

        # Gives orange color to the string & truncate to 32 chars
        current = [stylize("■ " + entry.name[:33] + "/", fg(202))]

        # Get date and convert in to a human readable format
        date = os.stat(entry).st_mtime
        current.append(
            DecoratedData(date, normalize_date('%h %d %Y %H:%M', date)))

        # recursively calculates the total size of a folder
        b = DirectoryFiles().get_dir_size(entry)
        current.append(DecoratedData(b, bytes_to_human_readable(b)))

        current.append('-')  # add directory type identifier
        return tuple(current)