gmyth-stream/server/0.2/lib/utils.py
branchtrunk
changeset 605 4dd9bf602c18
parent 577 7dc357cbaa40
child 651 76a3f315ef42
     1.1 --- a/gmyth-stream/server/0.2/lib/utils.py	Thu Apr 19 22:38:46 2007 +0100
     1.2 +++ b/gmyth-stream/server/0.2/lib/utils.py	Mon Apr 30 18:16:36 2007 +0100
     1.3 @@ -15,10 +15,10 @@
     1.4  
     1.5  log = logging.getLogger("gms.utils")
     1.6  
     1.7 -__all__ = ("which", "load_plugins", "PluginSet")
     1.8 +__all__ = ("which", "load_plugins", "PluginSet", "getHTML")
     1.9  
    1.10  def which(app):
    1.11 -    """function to implement which(1) unix command"""
    1.12 +    """Function to implement which(1) unix command"""
    1.13      pl = os.environ["PATH"].split(os.pathsep)
    1.14      for p in pl:
    1.15          path = os.path.join(p, app)
    1.16 @@ -121,6 +121,7 @@
    1.17  
    1.18  
    1.19  def load_plugins(directory, basetype):
    1.20 +    """Function to load plugins from a given directory"""
    1.21      tn = basetype.__name__
    1.22      log.debug("Loading plugins from %s, type=%s" % (directory, tn))
    1.23  
    1.24 @@ -146,3 +147,15 @@
    1.25  
    1.26      return plugins
    1.27  # load_plugins()
    1.28 +
    1.29 +def getHTML(html_file, params={}):
    1.30 +    """This function parses a file 'html_file.html' with the given
    1.31 +    parameters and returns a formated web-page"""
    1.32 +    try:
    1.33 +        filename = os.path.join(sys.path[0], "html", html_file + ".html")
    1.34 +        html = open(filename).read() % params
    1.35 +        return html
    1.36 +    except Exception, e:
    1.37 +        return "HTML format error. Wrong keys: %s" % e
    1.38 +
    1.39 +# getHTML