diff --git a/README.md b/README.md index 9b98f90..9d3efd5 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,10 @@ The following commands will show how to run a demonstration test: ```.bash cd WHERE/YOU/INSTALLED/perguntations -# create database. -# a database with fake students is created if no CSV file is provided -./initdb.py OPTIONAL_CSV_FILE +# create and initialize database either from a CSV file, fake students or empty +./initdb.py students.csv # from CSV file +./initdb.py --demo # initialize with fake students +./initdb.py # empty mv students.db demo/ # edit test configuration and check if everything looks right diff --git a/initdb.py b/initdb.py index 59ba0c8..aae469b 100755 --- a/initdb.py +++ b/initdb.py @@ -20,7 +20,7 @@ def fix(name): # Parse command line options argparser = argparse.ArgumentParser(description='Create new database from a CSV file (SIIUE format)') argparser.add_argument('--db', default='students.db', type=str, help='database filename') -# argparser.add_argument('--demo', default='students.db', type=str, help='add demo students') +argparser.add_argument('--demo', action='store_true', help='initialize database with a few fake students') argparser.add_argument('csvfile', nargs='?', type=str, default='', help='CSV filename') args = argparser.parse_args() @@ -50,8 +50,8 @@ try: sys.exit(1) else: session.add_all([Student(id=r['N.ยบ'], name=fix(r['Nome']), password='') for r in csvreader]) - else: - # otherwise add a few fake students + elif args.demo: + # add a few fake students fakes = [ ['1888', 'Fernando Pessoa'], ['1799', 'Almeida Garrett'], @@ -74,14 +74,15 @@ except Exception: else: n = session.query(Student).count() - print('New database created: {0}\n{1} users inserted:'.format(args.db, n)) + print('New database created: {0}\n{1} user(s) inserted:'.format(args.db, n)) users = session.query(Student).order_by(Student.id).all() print(' {0:8} - {1} (administrator)'.format(users[0].id, users[0].name)) if n > 1: print(' {0:8} - {1}'.format(users[1].id, users[1].name)) if n > 3: - print(' .\n .\n .') + print(' ... ...') + # print(' .\n .\n .') if n > 2: print(' {0:8} - {1}'.format(users[-1].id, users[-1].name)) -- libgit2 0.21.2