From 9977c5fc43cb4a5b59e75e3056b7aef3a4c697bb Mon Sep 17 00:00:00 2001 From: James Wettenhall Date: Wed, 22 Jul 2015 14:57:39 +1000 Subject: [PATCH] PidIsRunning and HumanReadableSizeString have been moved from mydata/models/upload.py to mydata/utils/__init__.py --- mydata/utils/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mydata/utils/__init__.py b/mydata/utils/__init__.py index e69de29..997484e 100644 --- a/mydata/utils/__init__.py +++ b/mydata/utils/__init__.py @@ -0,0 +1,21 @@ +import psutil + + +def PidIsRunning(pid): + try: + p = psutil.Process(int(pid)) + if p.status == psutil.STATUS_DEAD: + return False + if p.status == psutil.STATUS_ZOMBIE: + return False + return True # Assume other status are valid + except psutil.NoSuchProcess: + return False + + +def HumanReadableSizeString(num): + for x in ['bytes', 'KB', 'MB', 'GB']: + if num < 1024.0 and num > -1024.0: + return "%3.0f %s" % (num, x) + num /= 1024.0 + return "%3.0f %s" % (num, 'TB')