def __init__(self, context): self.context = context childContext = Context(context) childContext.addService(Logger("SecurityDBApi")) self.securityApi = SecurityDBApi(childContext) self.securityTokenFactory = SecurityTokenFactory( childContext, CherryPySecurityTokenImpl) self.siteDBApi = self.securityApi.api context.addService(self.securityApi) context.addService(self.siteDBApi) context.addService(self.securityTokenFactory) RedirectorToLogin.context = staticmethod(lambda: self.context) RedirectToLocalPage.context = staticmethod(lambda: self.context) RedirectAway.context = staticmethod(lambda: self.context)
def __loadControllers(self): for plugin in self.context.PluginManager().plugins("/Controllers"): # Each plugin lives in his own context, with his own logger. pluginContext = Context(self.context) name = plugin.implementation.__name__ self.logger.message("Controller %s loaded." % name) pluginContext.addService(Logger(name)) try: controller = plugin.createInstance(pluginContext) controller.options = plugin.options self.controllers.append(controller) except Exception, e: message = "An error was found while loading the controller: %s." % name exceptionStrings = traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback) self.logger.debug(message + "\t".join(exceptionStrings)) self.logger.warning("Controller %s not activated." % name)
import codecs if __name__ == "__main__": parser = OptionParser() parser.add_option("-f", "--file", help="input HN shadow passwd", default="passwd", dest="source") parser.add_option("-d", "--db", help="target SiteDB database", default="sitedb_test.db", dest="db") options, args = parser.parse_args() context = Context() context.addService(Logger("importHNShadow")) api = SecurityDBApi(context) context.Logger().message("HN file is " + options.source) shadowFile = codecs.open(options.source, "r", "ascii", "replace") for line in shadowFile: contact = line.split(":") if " " in contact[4]: forename, surname = contact[4].split(" ", 1) else: forename, surname = (contact[4], contact[4]) api.importHNAccount(username=contact[0].encode("ascii", "replace"), passwd=contact[1], forename=forename.encode("ascii", "replace"), email=contact[7].strip(), surname=surname.encode("ascii", "replace"))