Example #1
0
def populate_tables():
    start_time = time.time()
    sys.stderr.write("populate_tables: starting\n")
    user_manager = UserManager(
        SQLAlchemyAdapter(db, UserModel, UserAuthClass=UserAuthModel), app)
    admin_defaults = daconfig.get('default admin account', dict())
    if 'email' not in admin_defaults:
        admin_defaults['email'] = os.getenv('DA_ADMIN_EMAIL',
                                            '*****@*****.**')
    if 'nickname' not in admin_defaults:
        admin_defaults['nickname'] = 'admin'
    if 'first_name' not in admin_defaults:
        admin_defaults['first_name'] = word('System')
    if 'last_name' not in admin_defaults:
        admin_defaults['last_name'] = word('Administrator')
    if 'password' not in admin_defaults:
        admin_defaults['password'] = os.getenv('DA_ADMIN_PASSWORD', 'password')
    cron_defaults = daconfig.get(
        'default cron account', {
            'nickname': 'cron',
            'email': '*****@*****.**',
            'first_name': 'Cron',
            'last_name': 'User'
        })
    cron_defaults['active'] = False
    user_role = get_role(db, 'user')
    admin_role = get_role(db, 'admin')
    cron_role = get_role(db, 'cron')
    customer_role = get_role(db, 'customer')
    developer_role = get_role(db, 'developer')
    advocate_role = get_role(db, 'advocate')
    trainer_role = get_role(db, 'trainer')
    for user in UserModel.query.all():
        if len(user.roles) == 0:
            user.roles.append(user_role)
            db.session.commit()
    admin = get_user(db, admin_role, admin_defaults)
    cron = get_user(db, cron_role, cron_defaults)
    if admin.confirmed_at is None:
        admin.confirmed_at = datetime.datetime.now()
    if cron.confirmed_at is None:
        cron.confirmed_at = datetime.datetime.now()
    db.session.commit()
    add_dependencies(admin.id)
    git_packages = Package.query.filter_by(type='git')
    for package in git_packages:
        if package.name in [
                'docassemble', 'docassemble.base', 'docassemble.webapp',
                'docassemble.demo'
        ]:
            package.giturl = None
            package.gitsubdir = None
            package.type = 'pip'
            if daconfig.get('stable version', False):
                package.limitation = '<1.1.0'
            db.session.commit()
    sys.stderr.write("populate_tables: ending after " +
                     str(time.time() - start_time) + "\n")
    return
def populate_tables():
    user_manager = UserManager(
        SQLAlchemyAdapter(db, UserModel, UserAuthClass=UserAuthModel), app)
    admin_defaults = daconfig.get('default admin account', dict())
    if 'email' not in admin_defaults:
        admin_defaults['email'] = '*****@*****.**'
    if 'nickname' not in admin_defaults:
        admin_defaults['nickname'] = 'admin'
    if 'first_name' not in admin_defaults:
        admin_defaults['first_name'] = word('System')
    if 'last_name' not in admin_defaults:
        admin_defaults['last_name'] = word('Administrator')
    cron_defaults = daconfig.get(
        'default cron account', {
            'nickname': 'cron',
            'email': '*****@*****.**',
            'first_name': 'Cron',
            'last_name': 'User'
        })
    cron_defaults['active'] = False
    user_role = get_role(db, 'user')
    admin_role = get_role(db, 'admin')
    cron_role = get_role(db, 'cron')
    customer_role = get_role(db, 'customer')
    developer_role = get_role(db, 'developer')
    advocate_role = get_role(db, 'advocate')
    trainer_role = get_role(db, 'trainer')
    admin = get_user(db, admin_role, admin_defaults)
    cron = get_user(db, cron_role, cron_defaults)
    if admin.confirmed_at is None:
        admin.confirmed_at = datetime.datetime.now()
    if cron.confirmed_at is None:
        cron.confirmed_at = datetime.datetime.now()
    db.session.commit()
    add_dependencies(admin.id)
    git_packages = Package.query.filter_by(type='git')
    for package in git_packages:
        if package.name in [
                'docassemble', 'docassemble.base', 'docassemble.webapp',
                'docassemble.demo'
        ]:
            package.giturl = None
            package.gitsubdir = None
            package.type = 'pip'
            db.session.commit()
    # docassemble_git_url = daconfig.get('docassemble git url', 'https://github.com/jhpyle/docassemble')
    # installed_packages = get_installed_distributions()
    # existing_packages = [package.name for package in Package.query.all()]
    # for package in installed_packages:
    #     if package.key in existing_packages:
    #         continue
    #     package_auth = PackageAuth(user_id=admin.id)
    #     if package.key in ['docassemble', 'docassemble.base', 'docassemble.webapp', 'docassemble.demo']:
    #         package_entry = Package(name=package.key, package_auth=package_auth, giturl=docassemble_git_url, packageversion=package.version, gitsubdir=re.sub(r'\.', '_', package.key), type='git', core=True)
    #     else:
    #         package_entry = Package(name=package.key, package_auth=package_auth, packageversion=package.version, type='pip', core=True)
    #     db.session.add(package_auth)
    #     db.session.add(package_entry)
    return
Example #3
0
def populate_tables():
    user_manager = UserManager(SQLAlchemyAdapter(db, UserModel, UserAuthClass=UserAuthModel), app)
    admin_defaults = daconfig.get('default admin account', dict())
    if 'email' not in admin_defaults:
        admin_defaults['email'] = '*****@*****.**'
    if 'nickname' not in admin_defaults:
        admin_defaults['nickname'] = 'admin'
    if 'first_name' not in admin_defaults:
        admin_defaults['first_name'] = word('System')
    if 'last_name' not in admin_defaults:
        admin_defaults['last_name'] = word('Administrator')
    cron_defaults = daconfig.get('default cron account', {'nickname': 'cron', 'email': '*****@*****.**', 'first_name': 'Cron', 'last_name': 'User'})
    cron_defaults['active'] = False
    user_role = get_role(db, 'user')
    admin_role = get_role(db, 'admin')
    cron_role = get_role(db, 'cron')
    customer_role = get_role(db, 'customer')
    developer_role = get_role(db, 'developer')
    advocate_role = get_role(db, 'advocate')
    trainer_role = get_role(db, 'trainer')
    for user in UserModel.query.all():
        if len(user.roles) == 0:
            user.roles.append(user_role)
            db.session.commit()
    admin = get_user(db, admin_role, admin_defaults)
    cron = get_user(db, cron_role, cron_defaults)
    if admin.confirmed_at is None:
        admin.confirmed_at = datetime.datetime.now()
    if cron.confirmed_at is None:
        cron.confirmed_at = datetime.datetime.now()
    db.session.commit()
    add_dependencies(admin.id)
    git_packages = Package.query.filter_by(type='git')
    for package in git_packages:
        if package.name in ['docassemble', 'docassemble.base', 'docassemble.webapp', 'docassemble.demo']:
            package.giturl = None
            package.gitsubdir = None
            package.type = 'pip'
            db.session.commit()
    # docassemble_git_url = daconfig.get('docassemble git url', 'https://github.com/jhpyle/docassemble')
    # installed_packages = get_installed_distributions()
    # existing_packages = [package.name for package in Package.query.all()]
    # for package in installed_packages:
    #     if package.key in existing_packages:
    #         continue
    #     package_auth = PackageAuth(user_id=admin.id)
    #     if package.key in ['docassemble', 'docassemble.base', 'docassemble.webapp', 'docassemble.demo']:
    #         package_entry = Package(name=package.key, package_auth=package_auth, giturl=docassemble_git_url, packageversion=package.version, gitsubdir=re.sub(r'\.', '_', package.key), type='git', core=True)
    #     else:
    #         package_entry = Package(name=package.key, package_auth=package_auth, packageversion=package.version, type='pip', core=True)
    #     db.session.add(package_auth)
    #     db.session.add(package_entry)
    return
Example #4
0
def populate_tables(start_time=None):
    if start_time is None:
        start_time = time.time()
    sys.stderr.write("create_tables.populate_tables: starting after " +
                     str(time.time() - start_time) + "\n")
    UserManager(SQLAlchemyAdapter(db, UserModel, UserAuthClass=UserAuthModel),
                app)
    sys.stderr.write(
        "create_tables.populate_tables: obtained UserManager after " +
        str(time.time() - start_time) + "\n")
    result = {}
    admin_defaults = daconfig.get('default admin account', {})
    if 'email' not in admin_defaults:
        admin_defaults['email'] = os.getenv('DA_ADMIN_EMAIL',
                                            '*****@*****.**')
    if 'nickname' not in admin_defaults:
        admin_defaults['nickname'] = 'admin'
    if 'first_name' not in admin_defaults:
        admin_defaults['first_name'] = word('System')
    if 'last_name' not in admin_defaults:
        admin_defaults['last_name'] = word('Administrator')
    if 'password' not in admin_defaults:
        admin_defaults['password'] = os.getenv('DA_ADMIN_PASSWORD', 'password')
    cron_defaults = daconfig.get(
        'default cron account', {
            'nickname': 'cron',
            'email': '*****@*****.**',
            'first_name': 'Cron',
            'last_name': 'User'
        })
    cron_defaults['active'] = False
    user_role = get_role(db, 'user', result=result)
    admin_role = get_role(db, 'admin', result=result)
    cron_role = get_role(db, 'cron', result=result)
    get_role(db, 'customer', result=result)
    get_role(db, 'developer', result=result)
    get_role(db, 'advocate', result=result)
    get_role(db, 'trainer', result=result)
    if daconfig.get('fix user roles', False):
        sys.stderr.write(
            "create_tables.populate_tables: fixing user roles after " +
            str(time.time() - start_time) + "\n")
        to_fix = []
        for user in db.session.execute(
                select(UserModel).options(db.joinedload(
                    UserModel.roles))).scalars():
            if len(user.roles) == 0:
                to_fix.append(user)
        if len(to_fix) > 0:
            sys.stderr.write(
                "create_tables.populate_tables: found user roles to fix after "
                + str(time.time() - start_time) + "\n")
            for user in to_fix:
                user.roles.append(user_role)
            db.session.commit()
        sys.stderr.write(
            "create_tables.populate_tables: done fixing user roles after " +
            str(time.time() - start_time) + "\n")
    admin = get_user(db, admin_role, admin_defaults, result=result)
    cron = get_user(db, cron_role, cron_defaults, result=result)
    if admin.confirmed_at is None:
        admin.confirmed_at = datetime.datetime.now()
    if cron.confirmed_at is None:
        cron.confirmed_at = datetime.datetime.now()
    if result.get('changed', False):
        db.session.commit()
    sys.stderr.write(
        "create_tables.populate_tables: calling add_dependencies after " +
        str(time.time() - start_time) + "\n")
    add_dependencies(admin.id, start_time=start_time)
    sys.stderr.write(
        "create_tables.populate_tables: add_dependencies finished after " +
        str(time.time() - start_time) + "\n")
    git_packages = db.session.execute(
        select(Package).filter_by(type='git')).scalars().all()
    package_info_changed = False
    for package in git_packages:
        if package.name in [
                'docassemble', 'docassemble.base', 'docassemble.webapp',
                'docassemble.demo'
        ]:
            if package.giturl:
                package.giturl = None
                package_info_changed = True
            if package.gitsubdir:
                package.gitsubdir = None
                package_info_changed = True
            if package.type != 'pip':
                package.type = 'pip'
                package_info_changed = True
            if daconfig.get('stable version', False):
                if package.limitation != '<1.1.0':
                    package.limitation = '<1.1.0'
                    package_info_changed = True
    if package_info_changed:
        db.session.commit()
    sys.stderr.write("create_tables.populate_tables: ending after " +
                     str(time.time() - start_time) + "\n")