diff --git a/initdb.py b/initdb.py index a111375..b14d026 100755 --- a/initdb.py +++ b/initdb.py @@ -7,7 +7,6 @@ import re import string from sys import exit from concurrent.futures import ThreadPoolExecutor -from multiprocessing import cpu_count import asyncio # installed packages @@ -17,9 +16,8 @@ import sqlalchemy as sa # this project from models import Base, Student -pool = ThreadPoolExecutor() #cpu_count() -# replace password by hash for a single student dict +# replace password by hash for a single student def hashpw(student): pw = student.get('pw', student['uid']).encode('utf-8') print('.', end='', flush=True) @@ -53,11 +51,10 @@ def parse_commandline_arguments(): action='store_true', help='initialize database with a few fake students') - # FIXME - # argparser.add_argument('--pw', - # default='', - # type=str, - # help='default password') + argparser.add_argument('--pw', + default='', + type=str, + help='default password') argparser.add_argument('csvfile', nargs='?', @@ -97,8 +94,12 @@ elif args.demo: {'uid': '1903', 'name': 'John von Neumann'}] students.append({'uid': '0', 'name': 'Admin'}) +if args.pw: + for s in students: + s['pw'] = args.pw + print(f'Generating {len(students)} bcrypt password hashes.') -executor = ThreadPoolExecutor(cpu_count()) +executor = ThreadPoolExecutor() event_loop = asyncio.get_event_loop() event_loop.run_until_complete(hash_all_passwords(executor, students)) event_loop.close() -- libgit2 0.21.2