def getSettings(path): settings = Config(['']) settings.load(path) assert settings.headerGet("/server/@admin") in ( "yes", "true" ), "set <server admin='yes'> in %s to enable this CGI. It means anyone with access to the CGI will be able to inject arbitrary SQL code in the MySQL server" % path return settings
def run(settingsFile, configFile, dataDir): settings = Config([""]) settings.load(settingsFile) config = Config([""]) config.load(configFile) (host, port) = settings.headerGet("/settings/servers").split(" ")[0].split(":") client = DummyPokerClientFactory(settings, config, dataDir) reactor.connectTCP(host, int(port), client) reactor.run()
class Main: "Poker gameplay" def __init__(self, configfile, settingsfile): self.settings = Config(['']) self.settings.load(settingsfile) self.shutting_down = False if self.settings.header: rcdir = self.configureDirectory() self.dirs = split(self.settings.headerGet("/settings/path")) self.config = Config([''] + self.dirs) self.config.load(configfile) self.verbose = self.settings.headerGetInt("/settings/@verbose") self.poker_factory = None def configOk(self): return self.settings.header and self.config.header def shutdown(self, signal, stack_frame): self.shutting_down = True self.poker_factory.display.finish() reactor.stop() if self.verbose: print "received signal %s, exiting" % signal def configureDirectory(self): settings = self.settings if not settings.headerGet("/settings/user/@path"): print """ No <user path="user/settings/path" /> found in file %s. Using current directory instead. """ % settings.path return rcdir = expanduser(settings.headerGet("/settings/user/@path")) if not exists(rcdir): os.mkdir(rcdir) def run(self): settings = self.settings config = self.config signal.signal(signal.SIGINT, self.shutdown) if os.name == "posix": signal.signal(signal.SIGQUIT, self.shutdown) signal.signal(signal.SIGTERM, self.shutdown) poker_factory = None try: poker_factory = PokerClientFactory2D(settings=settings, config=config) self.poker_factory = poker_factory if poker_factory.display: reactor.run() else: raise Exception, "PokerClientFactory2D instance has no display" except: print_exc() if poker_factory: if poker_factory.children: poker_factory.children.killall() if poker_factory.display: poker_factory.display.finish() poker_factory.display = None
class Main: "Poker gameplay" def __init__(self, configfile, settingsfile): self.settings = Config(['']) self.settings.load(settingsfile) self.shutting_down = False if self.settings.header: rcdir = self.configureDirectory() self.dirs = split(self.settings.headerGet("/settings/path")) self.config = Config([''] + self.dirs) self.config.load(configfile) self.verbose = self.settings.headerGetInt("/settings/@verbose") self.poker_factory = None def configOk(self): return self.settings.header and self.config.header def shutdown(self, signal, stack_frame): self.shutting_down = True self.poker_factory.display.finish() reactor.stop() if self.verbose: print "received signal %s, exiting" % signal def configureDirectory(self): settings = self.settings if not settings.headerGet("/settings/user/@path"): print """ No <user path="user/settings/path" /> found in file %s. Using current directory instead. """ % settings.path return rcdir = expanduser(settings.headerGet("/settings/user/@path")) if not exists(rcdir): os.mkdir(rcdir) def run(self): settings = self.settings config = self.config signal.signal(signal.SIGINT, self.shutdown) if os.name == "posix": signal.signal(signal.SIGQUIT, self.shutdown) signal.signal(signal.SIGTERM, self.shutdown) poker_factory = None try: poker_factory = PokerClientFactory2D(settings = settings, config = config) self.poker_factory = poker_factory if poker_factory.display: reactor.run() else: raise Exception, "PokerClientFactory2D instance has no display" except: print_exc() if poker_factory: if poker_factory.children: poker_factory.children.killall() if poker_factory.display: poker_factory.display.finish() poker_factory.display = None