Commit 1cb1329f6a9b2bcd210f328e7d92a7bd2c223d1f

Authored by Miguel Barão
1 parent cb220399
Exists in master and in 1 other branch dev

- fixes in initdb, now even slightly faster.

Showing 1 changed file with 10 additions and 9 deletions   Show diff stats
@@ -7,7 +7,6 @@ import re @@ -7,7 +7,6 @@ import re
7 import string 7 import string
8 from sys import exit 8 from sys import exit
9 from concurrent.futures import ThreadPoolExecutor 9 from concurrent.futures import ThreadPoolExecutor
10 -from multiprocessing import cpu_count  
11 import asyncio 10 import asyncio
12 11
13 # installed packages 12 # installed packages
@@ -17,9 +16,8 @@ import sqlalchemy as sa @@ -17,9 +16,8 @@ import sqlalchemy as sa
17 # this project 16 # this project
18 from models import Base, Student 17 from models import Base, Student
19 18
20 -pool = ThreadPoolExecutor() #cpu_count()  
21 19
22 -# replace password by hash for a single student dict 20 +# replace password by hash for a single student
23 def hashpw(student): 21 def hashpw(student):
24 pw = student.get('pw', student['uid']).encode('utf-8') 22 pw = student.get('pw', student['uid']).encode('utf-8')
25 print('.', end='', flush=True) 23 print('.', end='', flush=True)
@@ -53,11 +51,10 @@ def parse_commandline_arguments(): @@ -53,11 +51,10 @@ def parse_commandline_arguments():
53 action='store_true', 51 action='store_true',
54 help='initialize database with a few fake students') 52 help='initialize database with a few fake students')
55 53
56 - # FIXME  
57 - # argparser.add_argument('--pw',  
58 - # default='',  
59 - # type=str,  
60 - # help='default password') 54 + argparser.add_argument('--pw',
  55 + default='',
  56 + type=str,
  57 + help='default password')
61 58
62 argparser.add_argument('csvfile', 59 argparser.add_argument('csvfile',
63 nargs='?', 60 nargs='?',
@@ -97,8 +94,12 @@ elif args.demo: @@ -97,8 +94,12 @@ elif args.demo:
97 {'uid': '1903', 'name': 'John von Neumann'}] 94 {'uid': '1903', 'name': 'John von Neumann'}]
98 students.append({'uid': '0', 'name': 'Admin'}) 95 students.append({'uid': '0', 'name': 'Admin'})
99 96
  97 +if args.pw:
  98 + for s in students:
  99 + s['pw'] = args.pw
  100 +
100 print(f'Generating {len(students)} bcrypt password hashes.') 101 print(f'Generating {len(students)} bcrypt password hashes.')
101 -executor = ThreadPoolExecutor(cpu_count()) 102 +executor = ThreadPoolExecutor()
102 event_loop = asyncio.get_event_loop() 103 event_loop = asyncio.get_event_loop()
103 event_loop.run_until_complete(hash_all_passwords(executor, students)) 104 event_loop.run_until_complete(hash_all_passwords(executor, students))
104 event_loop.close() 105 event_loop.close()