File: Module.py

package info (click to toggle)
cherokee 0.7.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,808 kB
  • ctags: 6,577
  • sloc: ansic: 45,071; python: 9,628; sh: 9,468; makefile: 1,639; xml: 61; perl: 32
file content (26 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import imp, sys

class Module:
    def __init__ (self, id, cfg, prefix, submit_url):
        self._id        = id
        self._cfg       = cfg
        self._prefix    = prefix
        self.submit_url = submit_url

def module_obj_factory (name, cfg, prefix, submit_url, **kwargs):
    # Assemble module name
    mod_name = reduce (lambda x,y: x+y, map(lambda x: x.capitalize(), name.split('_')))

    # Load the module source file
    mod = imp.load_source (name, "Module%s.py" % (mod_name))
    sys.modules[name] = mod

    # Instance the object
    src = "mod_obj = mod.Module%s(cfg, prefix, submit_url)" % (mod_name)
    exec(src)

    # Add properties
    for prop in kwargs:
        mod_obj.__dict__[prop] = kwargs[prop]

    return mod_obj