Exemplo n.º 1
0
 def write_results(self, data):
     stdout = self.options.stdout
     keys = (
         "count-immutable-files",
         "count-mutable-files",
         "count-literal-files",
         "count-files",
         "count-directories",
         "size-immutable-files",
         "size-mutable-files",
         "size-literal-files",
         "size-directories",
         "largest-directory",
         "largest-immutable-file",
     )
     width = max([len(k) for k in keys])
     print("Counts and Total Sizes:", file=stdout)
     for k in keys:
         fmt = "%" + str(width) + "s: %d"
         if k in data:
             value = data[k]
             if not k.startswith("count-") and value > 1000:
                 absize = abbreviate_space_both(value)
                 print(fmt % (k, data[k]), "  ", absize, file=stdout)
             else:
                 print(fmt % (k, data[k]), file=stdout)
     if data["size-files-histogram"]:
         print("Size Histogram:", file=stdout)
         prevmax = None
         maxlen = max([
             len(str(maxsize))
             for (minsize, maxsize, count) in data["size-files-histogram"]
         ])
         maxcountlen = max([
             len(str(count))
             for (minsize, maxsize, count) in data["size-files-histogram"]
         ])
         minfmt = "%" + str(maxlen) + "d"
         maxfmt = "%-" + str(maxlen) + "d"
         countfmt = "%-" + str(maxcountlen) + "d"
         linefmt = minfmt + "-" + maxfmt + " : " + countfmt + "    %s"
         for (minsize, maxsize, count) in data["size-files-histogram"]:
             if prevmax is not None and minsize != prevmax + 1:
                 print(" " * (maxlen - 1) + "...", file=stdout)
             prevmax = maxsize
             print(
                 linefmt %
                 (minsize, maxsize, count, abbreviate_space_both(maxsize)),
                 file=stdout)
Exemplo n.º 2
0
 def write_results(self, data):
     stdout = self.options.stdout
     keys = ("count-immutable-files",
             "count-mutable-files",
             "count-literal-files",
             "count-files",
             "count-directories",
             "size-immutable-files",
             "size-mutable-files",
             "size-literal-files",
             "size-directories",
             "largest-directory",
             "largest-immutable-file",
             )
     width = max([len(k) for k in keys])
     print("Counts and Total Sizes:", file=stdout)
     for k in keys:
         fmt = "%" + str(width) + "s: %d"
         if k in data:
             value = data[k]
             if not k.startswith("count-") and value > 1000:
                 absize = abbreviate_space_both(value)
                 print(fmt % (k, data[k]), "  ", absize, file=stdout)
             else:
                 print(fmt % (k, data[k]), file=stdout)
     if data["size-files-histogram"]:
         print("Size Histogram:", file=stdout)
         prevmax = None
         maxlen = max([len(str(maxsize))
                       for (minsize, maxsize, count)
                       in data["size-files-histogram"]])
         maxcountlen = max([len(str(count))
                            for (minsize, maxsize, count)
                            in data["size-files-histogram"]])
         minfmt = "%" + str(maxlen) + "d"
         maxfmt = "%-" + str(maxlen) + "d"
         countfmt = "%-" + str(maxcountlen) + "d"
         linefmt = minfmt + "-" + maxfmt + " : " + countfmt + "    %s"
         for (minsize, maxsize, count) in data["size-files-histogram"]:
             if prevmax is not None and minsize != prevmax+1:
                 print(" "*(maxlen-1) + "...", file=stdout)
             prevmax = maxsize
             print(linefmt % (minsize, maxsize, count,
                                        abbreviate_space_both(maxsize)), file=stdout)
Exemplo n.º 3
0
    def test_space(self):
        tests_si = [
            (None, "unknown"),
            (0, "0 B"),
            (1, "1 B"),
            (999, "999 B"),
            (1000, "1000 B"),
            (1023, "1023 B"),
            (1024, "1.02 kB"),
            (20 * 1000, "20.00 kB"),
            (1024 * 1024, "1.05 MB"),
            (1000 * 1000, "1.00 MB"),
            (1000 * 1000 * 1000, "1.00 GB"),
            (1000 * 1000 * 1000 * 1000, "1.00 TB"),
            (1000 * 1000 * 1000 * 1000 * 1000, "1.00 PB"),
            (1000 * 1000 * 1000 * 1000 * 1000 * 1000, "1.00 EB"),
            (1234567890123456789, "1.23 EB"),
        ]
        for (x, expected) in tests_si:
            got = abbreviate.abbreviate_space(x, SI=True)
            self.failUnlessEqual(got, expected)

        tests_base1024 = [
            (None, "unknown"),
            (0, "0 B"),
            (1, "1 B"),
            (999, "999 B"),
            (1000, "1000 B"),
            (1023, "1023 B"),
            (1024, "1.00 kiB"),
            (20 * 1024, "20.00 kiB"),
            (1000 * 1000, "976.56 kiB"),
            (1024 * 1024, "1.00 MiB"),
            (1024 * 1024 * 1024, "1.00 GiB"),
            (1024 * 1024 * 1024 * 1024, "1.00 TiB"),
            (1000 * 1000 * 1000 * 1000 * 1000, "909.49 TiB"),
            (1024 * 1024 * 1024 * 1024 * 1024, "1.00 PiB"),
            (1024 * 1024 * 1024 * 1024 * 1024 * 1024, "1.00 EiB"),
            (1234567890123456789, "1.07 EiB"),
        ]
        for (x, expected) in tests_base1024:
            got = abbreviate.abbreviate_space(x, SI=False)
            self.failUnlessEqual(got, expected)

        self.failUnlessEqual(abbreviate.abbreviate_space_both(1234567),
                             "(1.23 MB, 1.18 MiB)")