Exemplo n.º 1
0
def db(cmd, database=None, showall=False, version='8.4'):
    """Manipulates databases. Commands: createall, dropall"""
    if database is None:
        database = app.config['POSTGRESQL_DATABASE_DB']

    if showall:
        out = dict(stdin=None, stdout=None, stderr=None)
    else:
        out = dict(stdin=PIPE, stdout=PIPE, stderr=PIPE)

    if cmd == 'createall':
        if prompt_bool("You really want to destroy %s?" % database):
            sys.stdout.write("  [DROP] database %s..." % database)
            print 'ok' if call(["dropdb", database], **out) == 0 else 'error'

            sys.stdout.write("[CREATE] database %s..." % database)
            print 'ok' if call(["createdb", database], **out) == 0 else 'error'

            sys.stdout.write("[CREATE] PL/pgSQL language...")
            print 'ok' if call(["createlang", "plpgsql", database], **out) == 0 else 'error'

            if version == '8.4':
                sqls = sql_files_84
            else:
                sqls = sql_files_91

            for sql_file in sqls:
                sys.stdout.write("  [EXEC] SQL file %s..." % sql_file)
                print 'ok' if call(["psql", "-d", database, "-f", sql_file], **out) == 0 else 'error'

    elif cmd == 'dropall':
        if prompt_bool("You really want to destroy %s?" % database):
            sys.stdout.write("  [DROP] database %s..." % database)
            print 'ok' if call(["dropdb", database], **out) == 0 else 'error'
Exemplo n.º 2
0
def initdb():
    """Init/reset database."""

    if not prompt_bool("Are you sure? You will lose all your data!"):
        return

    db.drop_all()
    db.create_all()

    demo = User(
        username=u'demo',
        email='*****@*****.**',
        password='******',
        role_id=USER,
        status_id=ACTIVE,
        user_detail=UserDetail(
            first_name=u'Demo',
            last_name=u'Dude',
            gender=u'female',
            dob=datetime.date(1985, 02, 17),
            phone=1234567890,
            bio=u'Demo dude is pretty sweet.',
            url=u'http://www.example.com/demo',
        ),
    )
Exemplo n.º 3
0
def initdb():
    """Init/reset database."""

    if not prompt_bool("Are you sure? You will lose all your data!"):
        return

    db.drop_all()
    db.create_all()

    demo = User(
            username=u'demo',
            email='*****@*****.**',
            password='******',
            role_id=USER,
            status_id=ACTIVE,
            user_detail=UserDetail(
                first_name=u'Demo',
                last_name=u'Dude',
                gender=u'female',
                dob=datetime.date(1985, 02, 17),
                phone=1234567890,
                bio=u'Demo dude is pretty sweet.',
                url=u'http://www.example.com/demo',
                ),
            )
Exemplo n.º 4
0
def newdb():
    """Deletes the database, and creates a new empty one."""
    if prompt_bool("Are you sure you want to lose all your data"):
        try:
            os.remove('test.db')
        except OSError:
            print "Database did not exist"
    init_db()
Exemplo n.º 5
0
def dropdb():
    """ Management function to drob DB. Requires root admin access. """
    if prompt_bool("Are you sure you want to loose all data?"):
        if password_valid(): 
            models.db.drop_all()
            print 'Database dropped'
        else:
            print 'Database operation aborted.'
Exemplo n.º 6
0
def clear_db():
    """Drops and creates all db tables. (DESTRUCTIVE)."""

    if prompt_bool("May I drop and re-create all database tables"):
        app.logger.info('dropping all tables...')
        db.drop_all()
        app.logger.info('creating all tables...')
        db.create_all()
Exemplo n.º 7
0
def deladmin():
    """ Management function to delete admins. """
    if password_valid(): 
        username = None
        while username is None:
            username = prompt("Please enter admin username").strip()
        user = admin_models.Admin.query.filter_by(username=username).first()
        if user:
            if prompt_bool("Are you sure you want to delete user %s"%user.name):
                models.db.session.delete(user)
                models.db.session.commit()
        else:
            print "User does not exist"
Exemplo n.º 8
0
def testvals():
    """ Management function to create test DB. Requires root admin access. """
    if prompt_bool("Are you sure you want to loose all data?"):
        if password_valid():
            try:
                from tracker import testing
            except ImportError:
                print "Unable to load module 'testing' from tracker\
                      required to build test db"
                return 1
            testing.populate_test_db() 
            print "Test values populated"
        else:
            print 'Database operation aborted.'
Exemplo n.º 9
0
def drop_db():
    " Drop all tables. "

    from ..ext import db

    if prompt_bool("Are you sure? You will lose all your data!"):
        db.drop_all()

        # Evolution support
        from flask import current_app
        from flaskext.evolution import db as evolution_db
        evolution_db.init_app(current_app)
        evolution_db.drop_all()

        print "Database clearing"
Exemplo n.º 10
0
def mailall():
    "Sends an email to all users"

    subject = prompt("Subject")
    message = prompt("Message")
    from_address = prompt("From", default="*****@*****.**")
    if prompt_bool("Are you sure ? Email will be sent to everyone!"):
        with mail.connect() as conn:
            for user in User.query:
                message = Message(subject=subject,
                                  body=message,
                                  sender=from_address,
                                  recipients=[user.email])

                conn.send(message)
Exemplo n.º 11
0
def mailall():
    "Sends an email to all users"
    
    subject = prompt("Subject")
    message = prompt("Message")
    from_address = prompt("From", default="*****@*****.**")
    if prompt_bool("Are you sure ? Email will be sent to everyone!"):
        with mail.connect() as conn:
            for user in User.query:
                message = Message(subject=subject,
                                  body=message,
                                  sender=from_address,
                                  recipients=[user.email])

                conn.send(message)
Exemplo n.º 12
0
def dropall():
    """清理数据库数据"""
    if prompt_bool("Are you sure? You will lose all your DATA!"):
        db.drop_all()
Exemplo n.º 13
0
def dropall():
    if prompt_bool(u"警告:你将要删除全部的数据!你确定否?"):
        db.drop_all()
Exemplo n.º 14
0
Arquivo: manage.py Projeto: julen/tzos
def dropall():
    '''Deletes all the SQL database data.'''

    if prompt_bool('Are you sure? This will delete all the data.'):
        db.drop_all()
Exemplo n.º 15
0
def dropall():
    "Drops all database tables"

    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()
Exemplo n.º 16
0
def drop_all():
    '''Drop PostgreSQL tables'''
    from cadorsfeed import db
    import cadorsfeed.models
    if prompt_bool("Are you sure you want to drop the database tables"):
        db.drop_all()
Exemplo n.º 17
0
def dropall():
    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()
Exemplo n.º 18
0
def dropall():
    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()
Exemplo n.º 19
0
def dropall():
    "Drops all database tables"
    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()
Exemplo n.º 20
0
def dropall():
    """删除所有的表"""
    if prompt_bool("Are you sure? you will lost all your data"):
        db.drop_all()
        manager.app.logger.debug("drop all database")