def display_op(op): timestamp = white(op['date'].strftime(DATE_FORMAT)) label = white(op['type'].title()) + ' ' echo('{label:.<70} [{date}]'.format(label=label, date=timestamp)) format_output(op['output'], success=op['success'], traceback=op.get('traceback'))
def config(): '''Display some details about the local configuration''' if hasattr(current_app, 'settings_file'): log.info('Loaded configuration from %s', current_app.settings_file) log.info(white('Current configuration')) for key in sorted(current_app.config): echo('{0}: {1}'.format(white(key), current_app.config[key]))
def config(): '''Display some details about the local configuration''' if hasattr(current_app, 'settings_file'): log.info('Loaded configuration from %s', current_app.settings_file) log.info(white('Current configuration')) for key in sorted(current_app.config): if key.startswith('__') or not key.isupper(): continue echo('{0}: {1}'.format(white(key), current_app.config[key]))
def list(): '''List all known metrics''' for cls, metrics in registry.items(): echo(white(cls.__name__)) for metric in metrics.keys(): echo('> {0}'.format(metric))
def config(): '''Display the LDAP configuration''' header('Current configuration') for key in sorted(manager.config): if key.startswith('LDAP_'): echo(b'{key}: {value}'.format(key=white(key), value=safe_unicode(manager.config[key])))
def check(): '''Check the LDAP configuration''' bind_dn = manager.config.get('LDAP_BIND_USER_DN', None) if not bind_dn: exit_with_error('Missing LDAP_BIND_USER_DN setting') header('Trying to connect with bind user') try: who_am_i = manager.connection.extend.standard.who_am_i() success('Bind DN successfully connected') echo('Bind DN user is "{}"'.format(white(safe_unicode(who_am_i)))) except Exception as e: exit_with_error('Unable to connect', e) header('Trying to authenticate an user') email = prompt(white('User email')) password = prompt(white('User password'), hide_input=True) result = manager.authenticate(email, password) if result.status == AuthenticationResponseStatus.success: success('User successfully connected') echo('Authenticated user is "{email} ({dn})"'.format( email=white(safe_unicode(result.user_id)), dn=white(safe_unicode(result.user_dn)) )) echo('User has the following remote attributes:') for key, value in result.user_info.items(): echo(b'{key}: {value}'.format(key=white(safe_unicode(key)), value=safe_unicode(value))) echo('Local user will be created with the following values:') for key, value in manager.extract_user_infos(result.user_info).items(): echo(b'{key}: {value}'.format(key=white(safe_unicode(key)), value=safe_unicode(value))) else: exit_with_error('Unable to authenticate user "{0}"'.format(safe_unicode(email))) success('LDAP configuration is working')
def scheduled(): ''' List scheduled jobs. ''' for job in sorted(schedulables(), key=lambda s: s.name): for task in PeriodicTask.objects(task=job.name): label = job_label(task.task, task.args, task.kwargs) echo( SCHEDULE_LINE.format(name=white(task.name), label=label, schedule=task.schedule_display))
def scheduled(): ''' List scheduled jobs. ''' for job in sorted(schedulables(), key=lambda s: s.name): for task in PeriodicTask.objects(task=job.name): label = job_label(task.task, task.args, task.kwargs) echo(SCHEDULE_LINE.format( name=white(task.name.encode('utf8')), label=label, schedule=task.schedule_display ).encode('utf8'))
def plugins(): '''Display some details about the local plugins''' plugins = current_app.config['PLUGINS'] for name, description in entrypoints.ENTRYPOINTS.items(): echo('{0} ({1})'.format(white(description), name)) if name == 'udata.themes': actives = [current_app.config['THEME']] elif name == 'udata.avatars': actives = [avatar_config('provider')] else: actives = plugins for ep in sorted(entrypoints.iter_all(name), key=by_name): echo('> {0}: {1}'.format(ep.name, is_active(ep, actives)))
def render(): '''Force (re)rendering stored images''' print(cyan('Rendering images')) count = Counter() total = Counter() organizations = Organization.objects(logo__exists=True) total['orgs'] = organizations.count() print(white('Processing {0} organizations logos'.format(total['orgs']))) for org in organizations: count['orgs'] += render_or_skip(org, 'logo') users = User.objects(avatar__exists=True) total['users'] = users.count() print(white('Processing {0} user avatars'.format(total['users']))) for user in users: count['users'] += render_or_skip(user, 'avatar') posts = Post.objects(image__exists=True) total['posts'] = posts.count() print(white('Processing {0} post images'.format(total['posts']))) for post in posts: count['posts'] += render_or_skip(post, 'image') reuses = Reuse.objects(image__exists=True) total['reuses'] = reuses.count() print(white('Processing {0} reuse images'.format(total['reuses']))) for reuse in reuses: count['reuses'] += render_or_skip(reuse, 'image') print(white('Summary:')) print(''' Organization logos: {count[orgs]}/{total[orgs]} User avatars: {count[users]}/{total[users]} Post images: {count[posts]}/{total[posts]} Reuse images: {count[reuses]}/{total[reuses]} '''.format(count=count, total=total)) print(green('Images rendered'))