diff --git a/setup.py b/setup.py index d7e47df..c916921 100644 --- a/setup.py +++ b/setup.py @@ -17,8 +17,7 @@ setup(name = "trimage", license = "MIT license", package_dir = {'trimage' : 'src/trimage'}, packages = ["trimage", - "trimage.filesize", - "trimage.ThreadPool",], + "trimage.ThreadPool"], package_data = {"trimage" : ["pixmaps/*.*"] }, data_files=[('share/icons/hicolor/scalable/apps', ['desktop/trimage.svg']), ('share/applications', ['desktop/trimage.desktop']), diff --git a/src/trimage/filesize/PKG-INFO b/src/trimage/filesize/PKG-INFO deleted file mode 100644 index fe3aadb..0000000 --- a/src/trimage/filesize/PKG-INFO +++ /dev/null @@ -1,71 +0,0 @@ -Metadata-Version: 1.0 -Name: hurry.filesize -Version: 0.9 -Summary: A simple Python library for human readable file sizes (or anything sized in bytes). -Home-page: UNKNOWN -Author: Martijn Faassen, Startifact -Author-email: faassen@startifact.com -License: ZPL 2.1 -Description: hurry.filesize - ============== - - hurry.filesize a simple Python library that can take a number of bytes and - returns a human-readable string with the size in it, in kilobytes (K), - megabytes (M), etc. - - The default system it uses is "traditional", where multipliers of 1024 - increase the unit size:: - - >>> from hurry.filesize import size - >>> size(1024) - '1K' - - An alternative, slightly more verbose system:: - - >>> from hurry.filesize import alternative - >>> size(1, system=alternative) - '1 byte' - >>> size(10, system=alternative) - '10 bytes' - >>> size(1024, system=alternative) - '1 KB' - - A verbose system:: - - >>> from hurry.filesize import verbose - >>> size(10, system=verbose) - '10 bytes' - >>> size(1024, system=verbose) - '1 kilobyte' - >>> size(2000, system=verbose) - '1 kilobyte' - >>> size(3000, system=verbose) - '2 kilobytes' - >>> size(1024 * 1024, system=verbose) - '1 megabyte' - >>> size(1024 * 1024 * 3, system=verbose) - '3 megabytes' - - You can also use the SI system, where multipliers of 1000 increase the unit - size:: - - >>> from hurry.filesize import si - >>> size(1000, system=si) - '1K' - - - Changes - ======= - - 0.9 (2009-03-11) - ---------------- - - * Initial public release. - - Download - ======== - -Keywords: file size bytes -Platform: UNKNOWN -Classifier: Programming Language :: Python -Classifier: Topic :: Software Development :: Libraries :: Python Modules diff --git a/src/trimage/filesize/README.txt b/src/trimage/filesize/README.txt deleted file mode 100644 index 6a0fad6..0000000 --- a/src/trimage/filesize/README.txt +++ /dev/null @@ -1,50 +0,0 @@ -hurry.filesize -============== - -hurry.filesize a simple Python library that can take a number of bytes and -returns a human-readable string with the size in it, in kilobytes (K), -megabytes (M), etc. - -The default system it uses is "traditional", where multipliers of 1024 -increase the unit size:: - - >>> from hurry.filesize import size - >>> size(1024) - '1K' - -An alternative, slightly more verbose system:: - - >>> from hurry.filesize import alternative - >>> size(1, system=alternative) - '1 byte' - >>> size(10, system=alternative) - '10 bytes' - >>> size(1024, system=alternative) - '1 KB' - -A verbose system:: - - >>> from hurry.filesize import verbose - >>> size(10, system=verbose) - '10 bytes' - >>> size(1024, system=verbose) - '1 kilobyte' - >>> size(2000, system=verbose) - '1 kilobyte' - >>> size(3000, system=verbose) - '2 kilobytes' - >>> size(1024 * 1024, system=verbose) - '1 megabyte' - >>> size(1024 * 1024 * 3, system=verbose) - '3 megabytes' - -You can also use the SI system, where multipliers of 1000 increase the unit -size:: - - >>> from hurry.filesize import si - >>> size(1000, system=si) - '1K' - - -http://pypi.python.org/pypi/hurry.filesize - diff --git a/src/trimage/filesize/__init__.py b/src/trimage/filesize/__init__.py deleted file mode 100644 index e926dd0..0000000 --- a/src/trimage/filesize/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .filesize import size -from .filesize import traditional, alternative, verbose, iec, si diff --git a/src/trimage/filesize/filesize.py b/src/trimage/filesize/filesize.py deleted file mode 100644 index 4246868..0000000 --- a/src/trimage/filesize/filesize.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python3 - -''' -hurry.filesize - -@author: Martijn Faassen, Startifact -@license: ZPL 2.1 -''' - -traditional = [ - (1024 ** 5, 'P'), - (1024 ** 4, 'T'), - (1024 ** 3, 'G'), - (1024 ** 2, 'M'), - (1024 ** 1, 'K'), - (1024 ** 0, 'B'), - ] - -alternative = [ - (1024 ** 5, ' PB'), - (1024 ** 4, ' TB'), - (1024 ** 3, ' GB'), - (1024 ** 2, ' MB'), - (1024 ** 1, ' KB'), - (1024 ** 0, (' byte', ' bytes')), - ] - -verbose = [ - (1024 ** 5, (' petabyte', ' petabytes')), - (1024 ** 4, (' terabyte', ' terabytes')), - (1024 ** 3, (' gigabyte', ' gigabytes')), - (1024 ** 2, (' megabyte', ' megabytes')), - (1024 ** 1, (' kilobyte', ' kilobytes')), - (1024 ** 0, (' byte', ' bytes')), - ] - -iec = [ - (1024 ** 5, 'Pi'), - (1024 ** 4, 'Ti'), - (1024 ** 3, 'Gi'), - (1024 ** 2, 'Mi'), - (1024 ** 1, 'Ki'), - (1024 ** 0, ''), - ] - -si = [ - (1000 ** 5, 'P'), - (1000 ** 4, 'T'), - (1000 ** 3, 'G'), - (1000 ** 2, 'M'), - (1000 ** 1, 'K'), - (1000 ** 0, 'B'), - ] - - - -def size(bytes, system=traditional): - """Human-readable file size. - - Using the traditional system, where a factor of 1024 is used:: - - >>> size(10) - '10B' - >>> size(100) - '100B' - >>> size(1000) - '1000B' - >>> size(2000) - '1K' - >>> size(10000) - '9K' - >>> size(20000) - '19K' - >>> size(100000) - '97K' - >>> size(200000) - '195K' - >>> size(1000000) - '976K' - >>> size(2000000) - '1M' - - Using the SI system, with a factor 1000:: - - >>> size(10, system=si) - '10B' - >>> size(100, system=si) - '100B' - >>> size(1000, system=si) - '1K' - >>> size(2000, system=si) - '2K' - >>> size(10000, system=si) - '10K' - >>> size(20000, system=si) - '20K' - >>> size(100000, system=si) - '100K' - >>> size(200000, system=si) - '200K' - >>> size(1000000, system=si) - '1M' - >>> size(2000000, system=si) - '2M' - - """ - for factor, suffix in system: - if bytes >= factor: - break - amount = int(bytes/factor) - if isinstance(suffix, tuple): - singular, multiple = suffix - if amount == 1: - suffix = singular - else: - suffix = multiple - return str(amount) + suffix diff --git a/src/trimage/tools.py b/src/trimage/tools.py new file mode 100644 index 0000000..398df9e --- /dev/null +++ b/src/trimage/tools.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 + + +def human_readable_size(num, suffix='B'): + for unit in ['','K','M','G','T','P','E','Z']: + if abs(num) < 1024.0: + return "%3.1f%s%s" % (num, unit, suffix) + num /= 1024.0 + return "%.1f%s%s" % (num, 'Y', suffix) diff --git a/src/trimage/trimage.py b/src/trimage/trimage.py index bbe4017..b550a4e 100644 --- a/src/trimage/trimage.py +++ b/src/trimage/trimage.py @@ -15,8 +15,8 @@ from optparse import OptionParser from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * -from filesize import * +from tools import human_readable_size from queue import Queue from ThreadPool import ThreadPool from multiprocessing import cpu_count @@ -356,9 +356,9 @@ class ImageRow: self.image = image d = { 'shortname': lambda i: self.statusStr() % i.shortname, - 'oldfilesizestr': lambda i: size(i.oldfilesize, system=alternative) + 'oldfilesizestr': lambda i: human_readable_size(i.oldfilesize) if i.compressed else "", - 'newfilesizestr': lambda i: size(i.newfilesize, system=alternative) + 'newfilesizestr': lambda i: human_readable_size(i.newfilesize) if i.compressed else "", 'ratiostr': lambda i: "%.1f%%" % (100 - (float(i.newfilesize) / i.oldfilesize * 100))