From 68fb88cc63a278fac68d2ac7928e424c3d8f69e8 Mon Sep 17 00:00:00 2001 From: Schrolli Date: Thu, 2 Jul 2015 15:16:24 +0200 Subject: [PATCH] move helper functions in seperate folder and split to logical files --- includes/helper/__init__.py | 0 includes/helper/timeHandler.py | 49 +++++++++++++++++++ .../{helper.py => helper/wildcardHandler.py} | 28 ++--------- plugins/MySQL/boswatch.sql | 3 ++ 4 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 includes/helper/__init__.py create mode 100644 includes/helper/timeHandler.py rename includes/{helper.py => helper/wildcardHandler.py} (70%) diff --git a/includes/helper/__init__.py b/includes/helper/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/includes/helper/timeHandler.py b/includes/helper/timeHandler.py new file mode 100644 index 0000000..7c45fb4 --- /dev/null +++ b/includes/helper/timeHandler.py @@ -0,0 +1,49 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- +# + +""" +little Helper to get easy the curent date or time +for direct use in plugins to save code + +@author: Bastian Schroll +""" + +import logging + +import time + + +def curtime(format="%d.%m.%Y %H:%M:%S"): + """ + Returns formated date and/or time + see: https://docs.python.org/2/library/time.html#time.strftime + + @type format: string + @param format: Python time Format-String + + @return: Formated Time and/or Date + @exception: Exception if Error in format + """ + try: + return time.strftime(format) + except: + logging.warning("error in time-format-string") + logging.debug("error in time-format-string", exc_info=True) + + +def getDate(): + """ + Returns the date + + @return: Formated date + """ + return curtime("%d.%m.%Y") + +def getTime(): + """ + Returns the time + + @return: Formated time + """ + return curtime("%H:%M:%S") diff --git a/includes/helper.py b/includes/helper/wildcardHandler.py similarity index 70% rename from includes/helper.py rename to includes/helper/wildcardHandler.py index 2b549e2..be7f984 100644 --- a/includes/helper.py +++ b/includes/helper/wildcardHandler.py @@ -3,33 +3,15 @@ # """ -little Helper functions -mainly for direct use in plugins to save code +little Helper to replace fast and easy the standard wildcards +for direct use in plugins to save code -@author: Bastian Schroll +@author: Bastian Schroll """ import logging -import time - - -def curtime(format="%d.%m.%Y %H:%M:%S"): - """ - Returns formated date and/or time - see: https://docs.python.org/2/library/time.html#time.strftime - - @type format: string - @param format: Python time Format-String - - @return: Formated Time and/or Date - @exception: Exception if Error in format - """ - try: - return time.strftime(format) - except: - logging.warning("error in time-format-string") - logging.debug("error in time-format-string", exc_info=True) +from includes.helper import timeHandler def replaceWildcards(text,data): @@ -46,7 +28,7 @@ def replaceWildcards(text,data): """ try: # replace date and time wildcards - text = text.replace("%TIME%", curtime("%H:%M:%S")).replace("%DATE%", curtime("%d.%m.%Y")) + text = text.replace("%TIME%", timeHandler.getTime()).replace("%DATE%", timeHandler.getDate()) # replace FMS data if "fms" in data: text = text.replace("%FMS%", data["fms"]) diff --git a/plugins/MySQL/boswatch.sql b/plugins/MySQL/boswatch.sql index 0427f8e..cf91616 100644 --- a/plugins/MySQL/boswatch.sql +++ b/plugins/MySQL/boswatch.sql @@ -1,3 +1,6 @@ +-- MySQL Database Structure for the BOSWatch MySQL Plugin +-- @author: Bastian Schroll + -- phpMyAdmin SQL Dump -- version 3.4.11.1deb2+deb7u1 -- http://www.phpmyadmin.net