<commit_before>import prettytable

from collections import OrderedDict

from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand

from nodeconductor.structure import models

User = get_user_model()

USER_COLUMNS = OrderedDict([
    # (Column name, User fields)
    ('Full name, Civil number', ('full_name', 'civil_number')),
    ('Email, Phone nr.', ('email', 'phone_number')),
    ('Job title', ('job_title',)),
    ('Staff, Support', ('is_staff', 'is_support',)),
])

# in chars
COLUMN_MAX_WIDTH = 25


def format_string_to_column_size(string):
    if len(string) <= COLUMN_MAX_WIDTH:
        return string

    return '\n'.join(string[i:i + COLUMN_MAX_WIDTH] for i in range(0, len(string), COLUMN_MAX_WIDTH))


def to_string(value):
    if isinstance(value, bool):
        return 'Yes' if value else 'No'
    elif isinstance(value, int):
        return str(value)
    elif isinstance(value, basestring):
        return format_string_to_column_size(value)
    elif isinstance(value, list):
        strings = [to_string(v) for v in value]
        result = ', '.join(strings)
        if len(result) > COLUMN_MAX_WIDTH:
            return '\n'.join(strings)
        return result

    return format_string_to_column_size(str(value))


class Command(BaseCommand):
    help = "Dumps information about users, their organizations and projects."

    def add_arguments(self, parser):
        parser.add_argument(
            '-o', '--output',
            dest='output', default=None,
            help='Specifies file to which the output is written. The output will be printed to stdout by default.',
        )<commit_msg>Workaround for broken unicode encoding<commit_after>import prettytable

from collections import OrderedDict

from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand

from nodeconductor.structure import models

User = get_user_model()

USER_COLUMNS = OrderedDict([
    # (Column name, User fields)
    ('Full name, Civil number', ('full_name', 'civil_number')),
    ('Email, Phone nr.', ('email', 'phone_number')),
    ('Job title', ('job_title',)),
    ('Staff, Support', ('is_staff', 'is_support',)),
])

# in chars
COLUMN_MAX_WIDTH = 25


def format_string_to_column_size(string):
    if len(string) <= COLUMN_MAX_WIDTH:
        return string

    formatted = '\n'.join(string[i:i + COLUMN_MAX_WIDTH] for i in range(0, len(string), COLUMN_MAX_WIDTH))
    if isinstance(formatted, str):
        formatted = unicode(formatted, errors='replace')
    return formatted


def to_string(value):
    if isinstance(value, bool):
        return 'Yes' if value else 'No'
    elif isinstance(value, int):
        return str(value)
    elif isinstance(value, basestring):
        return format_string_to_column_size(value)
    elif isinstance(value, list):
        strings = [to_string(v) for v in value]
        result = ', '.join(strings)
        if len(result) > COLUMN_MAX_WIDTH:
            return '\n'.join(strings)
        return result

    return format_string_to_column_size(str(value))


class Command(BaseCommand):
    help = "Dumps information about users, their organizations and projects."

    def add_arguments(self, parser):
        parser.add_argument(
            '-o', '--output',
            dest='output', default=None,
            help='Specifies file to which the output is written. The output will be printed to stdout by default.',
        )
{'fraction_non_alphanumeric': 0.1139716517211455, 'fraction_numerical': 0.0017356089094590686, 'mean_word_length': 3.4619354838709677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5759064', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1014, 'n_words': 294}