move helper functions in seperate folder and split to logical files

This commit is contained in:
Schrolli 2015-07-02 15:16:24 +02:00
parent 3b66a1d952
commit 68fb88cc63
4 changed files with 57 additions and 23 deletions

View file

View file

@ -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")

View file

@ -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"])

View file

@ -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