772 raise ConfigurationError( |
772 raise ConfigurationError( |
773 'unknown configuration key "%s" for mode %s' % (key, appcfg.name)) |
773 'unknown configuration key "%s" for mode %s' % (key, appcfg.name)) |
774 appcfg.save() |
774 appcfg.save() |
775 |
775 |
776 |
776 |
777 # WSGI ######### |
|
778 |
|
779 WSGI_CHOICES = {} |
|
780 try: |
|
781 from cubicweb.wsgi import server as stdlib_server |
|
782 except ImportError: |
|
783 pass |
|
784 else: |
|
785 WSGI_CHOICES['stdlib'] = stdlib_server |
|
786 try: |
|
787 from cubicweb.wsgi import wz |
|
788 except ImportError: |
|
789 pass |
|
790 else: |
|
791 WSGI_CHOICES['werkzeug'] = wz |
|
792 try: |
|
793 from cubicweb.wsgi import tnd |
|
794 except ImportError: |
|
795 pass |
|
796 else: |
|
797 WSGI_CHOICES['tornado'] = tnd |
|
798 |
|
799 |
|
800 def wsgichoices(): |
|
801 return tuple(WSGI_CHOICES) |
|
802 |
|
803 |
|
804 if WSGI_CHOICES: |
|
805 class WSGIStartHandler(InstanceCommand): |
|
806 """Start an interactive wsgi server """ |
|
807 name = 'wsgi' |
|
808 actionverb = 'started' |
|
809 arguments = '<instance>' |
|
810 |
|
811 @property |
|
812 def options(self): |
|
813 return ( |
|
814 ("debug", |
|
815 {'short': 'D', 'action': 'store_true', |
|
816 'default': False, |
|
817 'help': 'start server in debug mode.'}), |
|
818 ('method', |
|
819 {'short': 'm', |
|
820 'type': 'choice', |
|
821 'metavar': '<method>', |
|
822 'default': 'stdlib', |
|
823 'choices': wsgichoices(), |
|
824 'help': 'wsgi utility/method'}), |
|
825 ('loglevel', |
|
826 {'short': 'l', |
|
827 'type': 'choice', |
|
828 'metavar': '<log level>', |
|
829 'default': None, |
|
830 'choices': ('debug', 'info', 'warning', 'error'), |
|
831 'help': 'debug if -D is set, error otherwise', |
|
832 }), |
|
833 ) |
|
834 |
|
835 def wsgi_instance(self, appid): |
|
836 config = cwcfg.config_for(appid, debugmode=self['debug']) |
|
837 init_cmdline_log_threshold(config, self['loglevel']) |
|
838 assert config.name == 'all-in-one' |
|
839 meth = self['method'] |
|
840 server = WSGI_CHOICES[meth] |
|
841 return server.run(config) |
|
842 |
|
843 CWCTL.register(WSGIStartHandler) |
|
844 |
|
845 |
|
846 for cmdcls in (ListCommand, |
777 for cmdcls in (ListCommand, |
847 CreateInstanceCommand, DeleteInstanceCommand, |
778 CreateInstanceCommand, DeleteInstanceCommand, |
848 UpgradeInstanceCommand, |
779 UpgradeInstanceCommand, |
849 ListVersionsInstanceCommand, |
780 ListVersionsInstanceCommand, |
850 ShellCommand, |
781 ShellCommand, |