summaryrefslogtreecommitdiff
path: root/lib/param/param.py
diff options
context:
space:
mode:
authorPepper <pepper@scannerjammer.com>2015-09-27 00:03:42 -0400
committerPepper <pepper@scannerjammer.com>2015-09-27 00:03:42 -0400
commit30126dfc2877a82b8af02d68ca3b155068d551dd (patch)
treea706d699cd1e1f50c2007e69d6ca9ba96819eaed /lib/param/param.py
parentff31f2c4cf1792df351359f1749f63b3d0cce23b (diff)
done linting...just need to wrap up and publish
Diffstat (limited to 'lib/param/param.py')
-rw-r--r--lib/param/param.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/param/param.py b/lib/param/param.py
new file mode 100644
index 0000000..d1e1446
--- /dev/null
+++ b/lib/param/param.py
@@ -0,0 +1,59 @@
+"""param base class lives here, used for inheritance only"""
+import time
+import sys
+
+from config import WORKING_DIR
+
+class BadParamError(Exception):
+ pass
+
+
+class Param(object):
+ """Defines the param base class, this class is used for inheritance only"""
+ def __init__(self, classname="", **kwargs):
+ self.value = None
+ self._working_dir = WORKING_DIR
+ self._now = kwargs.get("now", str(int(time.time())))
+ self._classname = classname
+ for key, value in kwargs.items():
+ setattr(self, key, value)
+
+ def __nonzero__(self):
+ return True if self.value else False
+
+ def __str__(self):
+ return str(self.value)
+
+ def __eq__(self, other):
+ return self.value == other
+
+ def __ne__(self, other):
+ return self.value != other
+
+ def set_val(self, value):
+ try:
+ self.value = value
+ except Exception as e:
+ self.err_warn("Unable to set value {}".format(value))
+
+ def err_warn(self, s, error=None):
+ self._error_log(s, error=error)
+ raise BadParamError("%s - %s" % (self._classname, s))
+
+ def __getattr__(self, key):
+ try:
+ return self.__getattribute__(key)
+ except AttributeError:
+ return None
+
+ def err_fatal(self, s, error=None):
+ self._log(s, error, fatal=True)
+ sys.exit(1)
+
+ def _error_log(self, s, error=None, fatal=False):
+ message = "ERROR - BAD PARAM"
+ if fatal: message += "- [FATAL] -"
+ sys.stderr.write("{}:{} - {}\n".format(message, self._classname, s))
+ if error:
+ sys.stderr.write("PARAM ERROR: {}\n".format(str(error)))
+