aboutsummaryrefslogtreecommitdiff
path: root/mcwrapper/prints.py
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-03-31 00:29:17 +0200
committerKarel Kočí <cynerd@email.cz>2016-03-31 00:29:17 +0200
commit2a8ad733fb5dc2e763256207332e42c90a3d6a6d (patch)
tree662f4ada3b65780660a43a868e7ae97181da0792 /mcwrapper/prints.py
parent7c635fe498b2c7d158a44ceaa525fe7317adb079 (diff)
downloadmcserver-wrapper-2a8ad733fb5dc2e763256207332e42c90a3d6a6d.tar.gz
mcserver-wrapper-2a8ad733fb5dc2e763256207332e42c90a3d6a6d.tar.bz2
mcserver-wrapper-2a8ad733fb5dc2e763256207332e42c90a3d6a6d.zip
Setting up Python package
Adding support for installing using pip. This will be default way to install mcwrapper.
Diffstat (limited to 'mcwrapper/prints.py')
-rw-r--r--mcwrapper/prints.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/mcwrapper/prints.py b/mcwrapper/prints.py
new file mode 100644
index 0000000..cb19358
--- /dev/null
+++ b/mcwrapper/prints.py
@@ -0,0 +1,32 @@
+# vim: expandtab ft=python ts=4 sw=4 sts=4:
+import sys
+import time
+
+verbose_level = 0
+
+
+def __print_message__(message, file=sys.stdout, notime=False):
+ if notime:
+ print(message, file=file)
+ else:
+ print('[' + time.strftime('%H:%M:%S') + '] ' + message, file=file)
+
+
+def info(message, minverbose=0, notime=False):
+ "Prints message to stdout if minverbose >= verbose_level"
+ if verbose_level >= minverbose:
+ __print_message__(message, notime=notime)
+
+
+def warning(message, minverbose=-1, notime=False):
+ "Prints message to stderr if minverbose >= verbose_level"
+ if verbose_level >= minverbose:
+ __print_message__(message, file=sys.stderr, notime=notime)
+
+
+def error(message, minverbose=-2, errcode=-1, notime=False):
+ "Prints message to stderr if minverbose >= verbose_level"
+ if verbose_level >= minverbose:
+ __print_message__(message, file=sys.stderr, notime=notime)
+ sys.exit(errcode)
+