# Path: yithlibraryserver/scripts/utils.py
# def safe_print(value):
#     if PY3:  # pragma: no cover
#         print(value)
#     else:  # pragma: no cover
#         print(value.encode('utf-8'))
# 
# Path: yithlibraryserver/scripts/utils.py
# def get_user_display_name(user):
#     return '%s %s <%s>' % (user.get('first_name', ''),
#                            user.get('last_name', ''),
#                            user.get('email', ''))


import optparse
import textwrap
import sys
from pyramid.paster import bootstrap
from yithlibraryserver.scripts.utils import safe_print
from yithlibraryserver.scripts.utils import get_user_display_name
    for user in db.users.find():
        add_attribute(db.users, user, get_user_display_name(user),
                      'send_passwords_periodically', True)


def migrate():
    usage = "migrate: %prog config_uri migration_name"
    description = "Add a 'send_email_periodically' preference to every user."
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description)
        )
    options, args = parser.parse_args(sys.argv[1:])
    if len(args) != 2:
        safe_print('You must provide two arguments. '
                   'The first one is the config file and the '
                   'second one is the migration name.')
        return 2
    config_uri = args[0]
    migration_name = args[1]
    env = bootstrap(config_uri)
    settings, closer = env['registry'].settings, env['closer']

    try:
        db = settings['mongodb'].get_database()

        if migration_name in migration_registry:
            migration = migration_registry[migration_name]
            migration(db)
        else:

# Path: yithlibraryserver/scripts/utils.py
# def safe_print(value):
#     if PY3:  # pragma: no cover
#         print(value)
#     else:  # pragma: no cover
#         print(value.encode('utf-8'))
# 
# Path: yithlibraryserver/scripts/utils.py
# def get_user_display_name(user):
#     return '%s %s <%s>' % (user.get('first_name', ''),
#                            user.get('last_name', ''),
#                            user.get('email', ''))


# Path: yithlibraryserver/scripts/migrations.py
import optparse
import textwrap
import sys
from pyramid.paster import bootstrap
from yithlibraryserver.scripts.utils import safe_print
from yithlibraryserver.scripts.utils import get_user_display_name

    for user in db.users.find():
        add_attribute(db.users, user, get_user_display_name(user),
                      'send_passwords_periodically', True)


def migrate():
    usage = "migrate: %prog config_uri migration_name"
    description = "Add a 'send_email_periodically' preference to every user."
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description)
        )
    options, args = parser.parse_args(sys.argv[1:])
    if len(args) != 2:
        safe_print('You must provide two arguments. '
                   'The first one is the config file and the '
                   'second one is the migration name.')
        return 2
    config_uri = args[0]
    migration_name = args[1]
    env = bootstrap(config_uri)
    settings, closer = env['registry'].settings, env['closer']

    try:
        db = settings['mongodb'].get_database()

        if migration_name in migration_registry:
            migration = migration_registry[migration_name]
            migration(db)
        else:

            safe_print('The migration "%s" does not exist.' % migration_name)