Exemple #1
0
def create_database(argv):
    set_app(config.ProductiveConfig)
    app.app_context().push()
    db.create_all()
    db.session.commit()
    rank1 = Rank(name='Member', debt_limit=-2000)
    rank2 = Rank(name='Alumni', debt_limit=-2000)
    rank3 = Rank(name='Contender', debt_limit=0)
    rank4 = Rank(name='Inactive', debt_limit=0, active=False)
    try:
        for r in (rank1, rank2, rank3, rank4):
            db.session.add(r)
        db.session.commit()
    except IntegrityError:
        os.remove(config.ProductiveConfig.DATABASE_PATH)
        sys.exit('ERROR: Could not create database!')

    # Handle the user.
    try:
        opts, _ = getopt.getopt(argv, 'f:l:p:')
        for opt, arg in opts:
            if opt == '-f':
                firstname = arg
            elif opt == '-l':
                lastname = arg
            elif opt == '-p':
                password = arg
    except getopt.GetoptError:
        firstname, lastname, password = input_user()
    user = {
        'firstname': firstname,
        'lastname': lastname,
        'password': password,
        'password_repeat': password
    }
    try:
        insert_user(user)
    except exc.PasswordTooShort:
        os.remove(config.ProductiveConfig.DATABASE_PATH)
        sys.exit(('ERROR: Password to short. Needs at least {} characters.' +
                  ' Aborting setup.').format(
                      config.BaseConfig.MINIMUM_PASSWORD_LENGTH))

    # Get the User
    user = User.query.filter_by(id=1).first()

    # Add User as Admin (is_admin, admin_id)
    user.set_admin(True, 1)

    # Verify the user (admin_id, rank_id)
    user.verify(1, 1)
    db.session.commit()
Exemple #2
0
    sys.exit('No configuration file was found. Please make sure, '
             'that you renamed or copied the sample configuration '
             'configuration.example.py and adapted it to your needs.')

import argparse
from shopdb.api import app, db, set_app
from dev import insert_dev_data
from flask_cors import CORS

parser = argparse.ArgumentParser(description='Starting script shop.db')
parser.add_argument('--mode', choices=['development', 'local'])
args = parser.parse_args()

if args.mode == 'development':
    print('Starting shop-db in developing mode')
    set_app(config.DevelopmentConfig)
    app.app_context().push()
    db.create_all()
    insert_dev_data(db)

elif args.mode == 'local':
    print('Starting shop-db on the local database')
    set_app(config.ProductiveConfig)
    CORS(app, expose_headers='*')
    app.app_context().push()

else:
    parser.print_help()
    sys.exit(f'{args.mode}: invalid operating mode')

app.run(host=app.config['HOST'], port=app.config['PORT'])
Exemple #3
0
 def create_app(self):
     return set_app(config.UnittestConfig)
Exemple #4
0

if __name__ == '__main__':
    # Check whether the productive database exists.
    if not os.path.isfile(config.ProductiveConfig.DATABASE_PATH):
        sys.exit('No database found. Please read the documentation and use '
                 'the setupdb.py script to initialize shop-db.')

    parser = ArgumentParser(description='Starting shop-db2 with a gunicorn server')
    parser.add_argument('--loglevel', help='select the log level', default='WARNING',
                        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'])

    args = parser.parse_args()

    # Overwrite the app configuration with the productive settings.
    set_app(config.ProductiveConfig)

    # Logging
    app.logger.handlers = logging.getLogger('gunicorn.error').handlers
    app.logger.setLevel(logging.getLevelName(args.loglevel))

    # Set the gunicorn options.
    options = {
        'bind': '%s:%s' % (app.config['HOST'], app.config['PORT']),
        # BEGIN OF WARNING
        # DO NOT CHANGE THIS VALUE, THE APPLICATION IS NOT DESIGNED FOR
        # MULTITHREADING AND ERRORS MAY OCCUR IN THE DATABASE!!!
        'workers': 1,
        # END WARNING
    }