#52 changelog: Format all sizes for readability
Merged 8 years ago by lsedlar. Opened 8 years ago by lsedlar.
lsedlar/compose-utils format-all-sizes  into  master

file modified
+9 -7
@@ -24,13 +24,15 @@ 

      units = ('KiB', 'MiB', 'GiB', 'TiB')

      size = float(size)

      chosen = 'B'

+     prec = 0

      for unit in units:

          if size > 1024:

+             prec = 2

              size = size / 1024

              chosen = unit

          else:

              break

-     return '%.2f %s' % (size, chosen)

+     return '{0:.{1}f} {2}'.format(size, prec, chosen)

  

  

  def to_utf8(text):
@@ -455,7 +457,7 @@ 

              result.append("Summary: %s" % i["summary"])

              if not shorten:

                  result.append("RPMs:    %s" % " ".join(sorted(i["rpms"])))

-             result.append("Size:    %s bytes" % i["size"])

+             result.append("Size:    %s" % formatsize(i["size"]))

              result.append("")

          result.append("")

  
@@ -465,7 +467,7 @@ 

              if not shorten:

                  result.append("Summary: %s" % i["summary"])

                  result.append("RPMs:    %s" % " ".join(sorted(i["rpms"])))

-             result.append("Size:    %s bytes" % i["size"])

+             result.append("Size:    %s" % formatsize(i["size"]))

              result.append("")

          result.append("")

  
@@ -481,8 +483,8 @@ 

              if i["dropped_rpms"]:

                  result.append("Dropped RPMs: %s" % " ".join(i["dropped_rpms"]))

              if not shorten:

-                 result.append("Size:         %s bytes" % i["size"])

-             result.append("Size change:  %s bytes" % i["size_change"])

+                 result.append("Size:         %s" % formatsize(i["size"]))

+             result.append("Size change:  %s" % formatsize(i["size_change"]))

              if i["changelog"]:

                  result.append("Changelog:")

                  for entry in i["changelog"]:
@@ -504,8 +506,8 @@ 

              if i["dropped_rpms"]:

                  result.append("Dropped RPMs: %s" % " ".join(i["dropped_rpms"]))

              if not shorten:

-                 result.append("Size:         %s bytes" % i["size"])

-             result.append("Size change:  %s bytes" % i["size_change"])

+                 result.append("Size:         %s" % formatsize(i["size"]))

+             result.append("Size change:  %s" % formatsize(i["size_change"]))

              if i["changelog"]:

                  result.append("Changelog:")

                  for entry in i["changelog"]:

@@ -6,10 +6,10 @@ 

  Upgraded packages:   1

  Downgraded packages: 1

  

- Size of added packages:      10.00 B

- Size of dropped packages:    15.00 B

- Size of upgraded packages:   20.00 B

- Size of downgraded packages: 25.00 B

+ Size of added packages:      10 B

+ Size of dropped packages:    15 B

+ Size of upgraded packages:   20 B

+ Size of downgraded packages: 25 B

  

- Size change of upgraded packages:   4.00 B

- Size change of downgraded packages: 6.00 B

+ Size change of upgraded packages:   4 B

+ Size change of downgraded packages: 6 B

@@ -13,14 +13,14 @@ 

  Package: compose-utils-0.1.9-1.fc25

  Summary: compose-utils summary

  RPMs:    compose-utils

- Size:    11 bytes

+ Size:    11 B

  

  

  ===== DROPPED PACKAGES =====

  Package: fedpkg-1.22-1.fc25

  Summary: fedpkg summary

  RPMs:    fedpkg

- Size:    12 bytes

+ Size:    12 B

  

  

  ===== UPGRADED PACKAGES =====
@@ -30,8 +30,8 @@ 

  RPMs:         pungi pungi-utils

  Added RPMs:   pungi-utils

  Dropped RPMs: pungi-ostree

- Size:         13 bytes

- Size change:  5 bytes

+ Size:         13 B

+ Size change:  5 B

  Changelog:

    * Pungi changed.

    * A lot.
@@ -45,8 +45,8 @@ 

  RPMs:         pyrpkg

  Added RPMs:   pyrpkg

  Dropped RPMs: rpkg

- Size:         14 bytes

- Size change:  6 bytes

+ Size:         14 B

+ Size change:  6 B

  Changelog:

    Rpkg changed as well.

  

@@ -12,12 +12,12 @@ 

  ===== ADDED PACKAGES =====

  Package: compose-utils-0.1.9-1.fc25

  Summary: compose-utils summary

- Size:    11 bytes

+ Size:    11 B

  

  

  ===== DROPPED PACKAGES =====

  Package: fedpkg-1.22-1.fc25

- Size:    12 bytes

+ Size:    12 B

  

  

  ===== UPGRADED PACKAGES =====
@@ -25,7 +25,7 @@ 

  Old package:  pungi-4.1.9-1.fc25

  Added RPMs:   pungi-utils

  Dropped RPMs: pungi-ostree

- Size change:  5 bytes

+ Size change:  5 B

  Changelog:

    * Pungi changed.

    * A lot.
@@ -37,7 +37,7 @@ 

  Old package:  rpkg-1.41-2.fc25

  Added RPMs:   pyrpkg

  Dropped RPMs: rpkg

- Size change:  6 bytes

+ Size change:  6 B

  Changelog:

    Rpkg changed as well.

  

Even size change for a package should be formatted with bigger unit than bytes. The formatting function is also updated to not print decimal places when the unit used is actually B (as at that point there can never be anything else than .00).

Fixes: https://pagure.io/compose-utils/issue/50

Looks great, thank you!

rebased

8 years ago

Pull-Request has been merged by lsedlar

8 years ago