summaryrefslogtreecommitdiff
path: root/humanify
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-12 08:10:42 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-12 08:24:06 +0200
commit466fcd268e53743ca7414f1fe969a74cd0ac1ee1 (patch)
tree18056390e7f507c1f40b38edfaa4c218b840f0e7 /humanify
parent2a562fd5a7d935d3743f6746927236b40f891a5c (diff)
downloadextrautils-466fcd268e53743ca7414f1fe969a74cd0ac1ee1.tar.gz
drop old crap
Diffstat (limited to 'humanify')
-rwxr-xr-xhumanify90
1 files changed, 0 insertions, 90 deletions
diff --git a/humanify b/humanify
deleted file mode 100755
index 32454fc..0000000
--- a/humanify
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/python
-# Copyright 2011 Lars Wirzenius
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-
-import cliapp
-import sys
-
-
-class Humanify(cliapp.Application):
-
- iso_prefixes = [
- (1000**8, 'Y'),
- (1000**7, 'Z'),
- (1000**6, 'E'),
- (1000**5, 'P'),
- (1000**4, 'T'),
- (1000**3, 'G'),
- (1000**2, 'M'),
- (1000, 'k'),
- (1, ''),
- ]
- iec_prefixes = [
- (1024**8, 'Yi'),
- (1024**7, 'Zi'),
- (1024**6, 'Ei'),
- (1024**5, 'Pi'),
- (1024**4, 'Ti'),
- (1024**3, 'Gi'),
- (1024**2, 'MI'),
- (1024, 'Ki'),
- (1, ''),
- ]
-
- def add_settings(self):
- self.settings.boolean(['binary', 'iec'],
- 'use 10-based, not 2-based prefixes '
- '(ISO vs IEC)')
- self.settings.boolean(['bits'], 'inputs give numbers of bits')
-
- def process_args(self, args):
- self.units = self.determine_units()
-
- if args:
- for arg in args:
- self.humanify(arg)
- else:
- for line in sys.stdin:
- self.humanify(float(line.strip()))
-
- def determine_units(self):
- if self.settings['binary']:
- prefixes = self.iec_prefixes
- else:
- prefixes = self.iso_prefixes
- if self.settings['bits']:
- suffix = 'b'
- else:
- suffix = 'B'
- return [(factor, prefix + suffix) for factor, prefix in prefixes]
-
- def humanify(self, arg):
- self.output.write('%s\n' % self._humanify(float(arg), self.units))
-
- def _humanify(self, value, units):
- assert units
- if value >= units[0][0]:
- return '%.0f %s' % (round(float(value) / units[0][0]),
- units[0][1])
- for factor, unit in units:
- size = float(value) / float(factor)
- if 1 <= size < 1000:
- return '%.0f %s' % (round(size), unit)
- return '%.0f %s' % (round(float(value) / units[-1][0]), units[-1][1])
-
-
-if __name__ == '__main__':
- Humanify().run()