示例#1
0
def main(args):
    manager = CodaLabManager()
    model = manager.model()

    # Get the the message
    subject = args.subject
    with open(args.body_file) as f:
        body_template = f.read()
    mime_type = 'html' if args.body_file.endswith('.html') else 'plain'

    # Figure out who we want to send
    to_send_list = get_to_send_list(model, args.threshold)
    sent_list = get_sent_list(args.sent_file)
    sent_emails = set(info['email'] for info in sent_list)
    pending_to_send_list = [info for info in to_send_list if info['email'] not in sent_emails]
    print 'Already sent %d emails, %d to go' % (len(sent_list), len(pending_to_send_list))

    for i, info in enumerate(pending_to_send_list):
        if args.only_email and args.only_email != info['email']:
            continue

        # Derived fields
        info['greeting_name'] = info['first_name'] or info['last_name'] or info['user_name']
        info['full_name'] = ' '.join([x for x in [info['first_name'], info['last_name']] if x])
        info['email_description'] = '%s <%s>' % (info['full_name'], info['email']) if info['full_name'] else info['email']
        info['sent_time'] = time.time()

        print 'Sending %s/%s (%s>=%s, doit=%s): [%s] %s' % \
            (i, len(pending_to_send_list), info['notifications'], args.threshold, args.doit, info['user_name'], info['email_description'])

        # Apply template to get body of message
        body = body_template
        for field, value in info.items():
            body = body.replace('{{' + field + '}}', unicode(value or ''))

        if args.verbose >= 1:
            print 'To      : %s' % info['email_description']
            print 'Subject : %s' % subject
            print body
            print '-------'

        if not args.doit:
            continue

        # Send the actual email
        manager.emailer.send_email(
            recipient=info['email_description'],
            subject=subject,
            body=body,
            mime_type=mime_type,
        )

        # Record that we sent
        with open(args.sent_file, 'a') as f:
            print >>f, json.dumps(info)
            f.flush()
示例#2
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    manager = CodaLabManager()
    engine = manager.model().engine

    connection = engine.connect()
    context.configure(connection=connection, target_metadata=target_metadata)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
示例#3
0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    manager = CodaLabManager()
    url = manager.model().engine.url
    context.configure(url=url, target_metadata=target_metadata)

    with context.begin_transaction():
        context.run_migrations()
示例#4
0
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    manager = CodaLabManager()
    url = manager.model().engine.url
    context.configure(url=url, target_metadata=target_metadata)

    with context.begin_transaction():
        context.run_migrations()
示例#5
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    manager = CodaLabManager()
    engine = manager.model().engine

    connection = engine.connect()
    context.configure(
                connection=connection,
                target_metadata=target_metadata
                )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
示例#6
0
class DryRunAbort(Exception):
    """Raised at end of transaction of dry run."""
    def __str__(self):
        return """
        This was a dry run, no migration occurred. To perform full migration,
        run again with `-f':

            %s -f
        """.rstrip() % sys.argv[0]


dry_run = False if len(sys.argv) > 1 and sys.argv[1] == '-f' else True

manager = CodaLabManager()
model = manager.model()
CODALAB_HOME = manager.codalab_home

# Turn on query logging
model.engine.echo = True


###############################################################
# Configure connection to Django database
###############################################################
django_config = read_json_or_die(os.path.join(CODALAB_HOME,
                                              'website-config.json'))

# Use default settings as defined in codalab-worksheets
if 'database' not in django_config:
    django_config['database'] = {
示例#7
0
#!./venv/bin/python
"""
Script that creates the root user.
"""
import sys

sys.path.append('.')

import getpass

from codalab.lib import crypt_util
from codalab.lib.codalab_manager import CodaLabManager
from codalab.objects.user import User

manager = CodaLabManager()
model = manager.model()

username = manager.root_user_name()
user_id = manager.root_user_id()

if len(sys.argv) == 2:
    password = sys.argv[1]
else:
    while True:
        password = getpass.getpass()
        if getpass.getpass('Config password: '******'Passwords don\'t match. Try again.'
        print
def main(args):
    manager = CodaLabManager()
    model = manager.model()

    # Get the the message
    subject = args.subject
    with open(args.body_file) as f:
        body_template = f.read()
    mime_type = 'html' if args.body_file.endswith('.html') else 'plain'

    # Figure out who we want to send
    to_send_list = get_to_send_list(model, args.threshold)
    sent_list = get_sent_list(args.sent_file)
    sent_emails = set(info['email'] for info in sent_list)
    pending_to_send_list = [info for info in to_send_list if info['email'] not in sent_emails]
    print('Already sent %d emails, %d to go' % (len(sent_list), len(pending_to_send_list)))

    for i, info in enumerate(pending_to_send_list):
        if args.only_email and args.only_email != info['email']:
            continue

        # Derived fields
        info['greeting_name'] = info['first_name'] or info['last_name'] or info['user_name']
        info['full_name'] = ' '.join([x for x in [info['first_name'], info['last_name']] if x])
        info['email_description'] = (
            '%s <%s>' % (info['full_name'], info['email']) if info['full_name'] else info['email']
        )
        info['sent_time'] = time.time()

        print(
            'Sending %s/%s (%s>=%s, doit=%s): [%s] %s'
            % (
                i,
                len(pending_to_send_list),
                info['notifications'],
                args.threshold,
                args.doit,
                info['user_name'],
                info['email_description'],
            )
        )

        # Apply template to get body of message
        body = body_template
        for field, value in info.items():
            body = body.replace('{{' + field + '}}', unicode(value or ''))

        if args.verbose >= 1:
            print('To      : %s' % info['email_description'])
            print('Subject : %s' % subject)
            print(body)
            print('-------')

        if not args.doit:
            continue

        # Send the actual email
        manager.emailer.send_email(
            recipient=info['email_description'], subject=subject, body=body, mime_type=mime_type
        )

        # Record that we sent
        with open(args.sent_file, 'a') as f:
            print >> f, json.dumps(info)
            f.flush()
def main(args):
    manager = CodaLabManager()

    # Get the the message
    subject = args.subject
    with open(args.body_file) as f:
        body_template = f.read()

    if args.body_file.endswith('.md'):
        body_template = f"""
            <div style='margin:auto; width: 100%; max-width: 600px'>
                <img src=https://worksheets.codalab.org/img/codalab-logo.png style='max-width: 100%;' />
                <h1>CodaLab Worksheets</h1>
                {markdown2.markdown(body_template)}<br><br>
                <small>If you'd like stop receiving these emails, please <a href='https://worksheets.codalab.org/account/profile'>update your account settings on CodaLab</a>.</small>
            </div>
        """

    mime_type = ('html' if args.body_file.endswith('.html')
                 or args.body_file.endswith('.md') else 'plain')

    # Figure out who we want to send
    to_send_list = ([{
        'email': e,
        'first_name': '',
        'last_name': '',
        'user_name': '',
        'notifications': 2
    } for e in args.emails.split(",")] if args.emails else get_to_send_list(
        manager.model(), args.threshold))
    sent_list = get_sent_list(args.sent_file)
    sent_emails = set(info['email'] for info in sent_list)
    pending_to_send_list = [
        info for info in to_send_list if info['email'] not in sent_emails
    ]
    print('Already sent %d emails, %d to go' %
          (len(sent_list), len(pending_to_send_list)))

    for i, info in enumerate(pending_to_send_list):
        if args.only_email and args.only_email != info['email']:
            continue

        # Derived fields
        info['greeting_name'] = info['first_name'] or info[
            'last_name'] or info['user_name']
        info['full_name'] = ' '.join(
            [x for x in [info['first_name'], info['last_name']] if x])
        info['email_description'] = ('%s <%s>' %
                                     (info['full_name'], info['email'])
                                     if info['full_name'] else info['email'])
        info['sent_time'] = time.time()

        print(('Sending %s/%s (%s>=%s, doit=%s): [%s] %s' % (
            i,
            len(pending_to_send_list),
            info['notifications'],
            args.threshold,
            args.doit,
            info['user_name'],
            info['email_description'],
        )))

        # Apply template to get body of message
        body = body_template
        for field, value in info.items():
            body = body.replace('{{' + field + '}}', str(value or ''))

        if args.verbose >= 1:
            print('To      : %s' % info['email_description'])
            print('Subject : %s' % subject)
            print(body)
            print('-------')

        if not args.doit:
            continue

        # Send the actual email
        manager.emailer.send_email(recipient=info['email_description'],
                                   subject=subject,
                                   body=body,
                                   mime_type=mime_type)

        # Record that we sent
        with open(args.sent_file, 'a') as f:
            print(json.dumps(info), file=f)
            f.flush()