From 1be08e09ef335e742dffd380babbe300da273140 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 24 Mar 2020 03:17:22 -0500 Subject: [PATCH] reformated sizeutils --- src/utils/sizeutils.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/utils/sizeutils.py b/src/utils/sizeutils.py index da121910..761e3601 100644 --- a/src/utils/sizeutils.py +++ b/src/utils/sizeutils.py @@ -1,19 +1,36 @@ +"""Onionr - Private P2P Communication. + +size related utilities +""" import sqlite3, os from onionrutils import stringvalidators +""" + 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 . +""" + + def human_size(num, suffix='B'): - ''' - Converts from bytes to a human readable format. - ''' + """Convert from bytes to a human readable format.""" for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']: if abs(num) < 1024.0: return "%.1f %s%s" % (num, unit, suffix) num /= 1024.0 return "%.1f %s%s" % (num, 'Yi', suffix) + def size(path='.'): - ''' - Returns the size of a folder's contents in bytes - ''' + """Get size of a folder's contents in bytes.""" total = 0 if os.path.exists(path): if os.path.isfile(path): @@ -24,4 +41,4 @@ def size(path='.'): total += entry.stat().st_size elif entry.is_dir(): total += size(entry.path) - return total \ No newline at end of file + return total