def init_slapd(cls): for path in ('/usr/sbin/slapd', '/usr/sbin/slapadd', '/usr/bin/ldapmodify'): if not os.path.exists(path): raise unittest.SkipTest('%s not found' % path) from cubicweb.cwctl import init_cmdline_log_threshold init_cmdline_log_threshold(cls.config, cls.loglevel) cls._tmpdir = create_slapd_configuration(cls)
def run(self, args): from cubicweb.cwctl import init_cmdline_log_threshold from cubicweb.server.repository import Repository config = ServerConfiguration.config_for(args[0]) # Log to stdout, since the this command runs in the foreground. config.global_set_option('log-file', None) init_cmdline_log_threshold(config, self['loglevel']) repo = Repository(config, sched.scheduler()) repo.bootstrap() try: repo.run_scheduler() finally: repo.shutdown()
def run(self, args): from cubicweb import repoapi from cubicweb.cwctl import init_cmdline_log_threshold config = ServerConfiguration.config_for(args[0]) config.global_set_option('log-file', None) config.log_format = '%(levelname)s %(name)s: %(message)s' init_cmdline_log_threshold(config, self['loglevel']) repo = repoapi.get_repository(config=config) repo.hm.call_hooks('server_maintenance', repo=repo) errors = False with repo.internal_cnx() as cnx: sources = [] if len(args) >= 2: for name in args[1:]: try: source = repo.source_by_uri(name) except ValueError: cnx.error('no source named %r' % name) errors = True else: sources.append(source) else: for uri, source in repo.sources_by_uri.items(): if (uri != 'system' and repo.config.source_enabled(source) and source.config['synchronize']): sources.append(source) for source in sources: try: stats = source.pull_data(cnx, force=self['force'], raise_on_error=True) except Exception: cnx.exception('while trying to update source %s', source) errors = True else: for key, val in stats.items(): if val: print(key, ':', val) if errors: raise ExecutionError('All sources where not synced')
def pyramid_instance(self, appid): self._needreload = False autoreload = self['reload'] or self['debug'] cwconfig = self.cwconfig filelist_path = os.path.join(cwconfig.apphome, '.pyramid-reload-files.list') pyramid_ini_path = os.path.join(cwconfig.apphome, "pyramid.ini") if not os.path.exists(pyramid_ini_path): _generate_pyramid_ini_file(pyramid_ini_path) if autoreload and not os.environ.get(self._reloader_environ_key): return self.restart_with_reloader(filelist_path) if autoreload: _turn_sigterm_into_systemexit() self.debug('Running reloading file monitor') extra_files = [sys.argv[0]] extra_files.extend(self.configfiles(cwconfig)) extra_files.extend(self.i18nfiles(cwconfig)) self.install_reloader(self['reload-interval'], extra_files, filelist_path=filelist_path) # if no loglevel is specified and --debug is here, set log level at debug if self['loglevel'] is None and self['debug']: init_cmdline_log_threshold(self.cwconfig, 'debug') # if the debugtoolbar is activated, test if it's importable if self['toolbar']: try: import pyramid_debugtoolbar # noqa except ImportError: print( "Error: you've tried to activate the pyramid debugtoolbar but it failed to " "import, make sure it's correctly installed by doing a " "'pip install pyramid_debugtoolbar'.\nYou can find more information on the " "official documentation: " "https://docs.pylonsproject.org/projects/pyramid_debugtoolbar/en/latest/" ) sys.exit(1) if self['debug']: # this is for injecting those into generated html: # > cubicweb-generated-by="module.Class" cubicweb-from-source="/path/to/file.py:42" inject_html_generating_call_on_w() app = wsgi_application_from_cwconfig( cwconfig, profile=self['profile'], profile_output=self['profile-output'], profile_dump_every=self['profile-dump-every'], debugtoolbar=self['toolbar']) host = cwconfig['interface'] port = cwconfig['port'] or 8080 url_scheme = ('https' if cwconfig['base-url'].startswith('https') else 'http') repo = app.application.registry['cubicweb.repository'] try: waitress.serve(app, host=host, port=port, url_scheme=url_scheme, clear_untrusted_proxy_headers=True) finally: repo.shutdown() if self._needreload: return 3 return 0
def pyramid_instance(self, appid): self._needreload = False debugmode = self['debug-mode'] or self['debug'] autoreload = self['reload'] or self['debug'] daemonize = not (self['no-daemon'] or debugmode or autoreload) cwconfig = cwcfg.config_for(appid, debugmode=debugmode) filelist_path = os.path.join(cwconfig.apphome, '.pyramid-reload-files.list') pyramid_ini_path = os.path.join(cwconfig.apphome, "pyramid.ini") if not os.path.exists(pyramid_ini_path): _generate_pyramid_ini_file(pyramid_ini_path) if autoreload and not os.environ.get(self._reloader_environ_key): return self.restart_with_reloader(filelist_path) if autoreload: _turn_sigterm_into_systemexit() self.debug('Running reloading file monitor') extra_files = [sys.argv[0]] extra_files.extend(self.configfiles(cwconfig)) extra_files.extend(self.i18nfiles(cwconfig)) self.install_reloader(self['reload-interval'], extra_files, filelist_path=filelist_path) if daemonize: self.daemonize(cwconfig['pid-file']) self.record_pid(cwconfig['pid-file']) if self['dbglevel']: self['loglevel'] = 'debug' set_debug('|'.join('DBG_' + x.upper() for x in self['dbglevel'])) init_cmdline_log_threshold(cwconfig, self['loglevel']) app = wsgi_application_from_cwconfig( cwconfig, profile=self['profile'], profile_output=self['profile-output'], profile_dump_every=self['profile-dump-every']) host = cwconfig['interface'] port = cwconfig['port'] or 8080 url_scheme = ('https' if cwconfig['base-url'].startswith('https') else 'http') repo = app.application.registry['cubicweb.repository'] warnings.warn( 'the "pyramid" command does not start repository "looping tasks" ' 'anymore; use the standalone "scheduler" command if needed') try: waitress.serve(app, host=host, port=port, url_scheme=url_scheme, clear_untrusted_proxy_headers=True) finally: repo.shutdown() if self._needreload: return 3 return 0