"""cubicweb-clt handlers for twisted"""importsysfromcubicweb.toolsutilsimportCommandHandlerfromcubicweb.web.webctlimportWebCreateHandler# trigger configuration registrationimportcubicweb.etwist.twconfig# pylint: disable-msg=W0611classTWCreateHandler(WebCreateHandler):cfgname='twisted'defbootstrap(self,cubes,inputlevel=0):"""bootstrap this configuration"""print'** twisted configuration'mainpyfile=self.config.server_file()mainpy=open(mainpyfile,'w')mainpy.write('''from cubicweb.etwist import serverapplication = server.main(%r, %r)'''%(self.config.appid,self.config.name))mainpy.close()print'application\'s twisted file %s generated'%mainpyfilesuper(TWCreateHandler,self).bootstrap(cubes,inputlevel)classTWStartHandler(CommandHandler):cmdname='start'cfgname='twisted'defstart_command(self,config,debug):command=['%s `which twistd`'%sys.executable]forctl_opt,server_optin(('pid-file','pidfile'),('uid','uid'),('log-file','logfile',)):value=config[ctl_opt]ifnotvalueor(debugandctl_opt=='log-file'):continuecommand.append('--%s%s'%(server_opt,value))ifdebug:command.append('-n')ifconfig['profile']:command.append('-p %s --savestats'%config['profile'])command.append('-oy')command.append(self.config.server_file())return' '.join(command)classTWStopHandler(CommandHandler):cmdname='stop'cfgname='twisted'try:fromcubicweb.serverimportserverctlclassAllInOneCreateHandler(serverctl.RepositoryCreateHandler,TWCreateHandler):"""configuration to get a web application running in a twisted web server integrating a repository server in the same process """cfgname='all-in-one'defbootstrap(self,cubes,inputlevel=0):"""bootstrap this configuration"""serverctl.RepositoryCreateHandler.bootstrap(self,cubes,inputlevel)TWCreateHandler.bootstrap(self,cubes,inputlevel)classAllInOneStartHandler(TWStartHandler):cmdname='start'cfgname='all-in-one'subcommand='cubicweb-twisted'classAllInOneStopHandler(serverctl.RepositoryStopHandler):cmdname='stop'cfgname='all-in-one'subcommand='cubicweb-twisted'exceptImportError:pass