Commit 8dcdb358478d6c9fd57f19f0c7cc9a5be710d50d
1 parent
03c1b46f
Exists in
master
and in
1 other branch
- some fixes in exceptions.
Showing
3 changed files
with
12 additions
and
14 deletions
Show diff stats
initdb.py
| 1 | -#!/usr/bin/env python3 | |
| 1 | +#!/usr/bin/env python3.6 | |
| 2 | 2 | # -*- coding: utf-8 -*- |
| 3 | 3 | |
| 4 | 4 | import csv |
| ... | ... | @@ -44,8 +44,8 @@ try: |
| 44 | 44 | # from csv file if available |
| 45 | 45 | try: |
| 46 | 46 | csvreader = csv.DictReader(open(args.csvfile, encoding='iso-8859-1'), delimiter=';', quotechar='"', skipinitialspace=True) |
| 47 | - except EnvironmentError: | |
| 48 | - print('Error: CSV file "{0}" not found.'.format(args.csvfile)) | |
| 47 | + except OSError: | |
| 48 | + print(f'Error: Can\'t open CSV file "{args.csvfile}".') | |
| 49 | 49 | session.rollback() |
| 50 | 50 | sys.exit(1) |
| 51 | 51 | else: |
| ... | ... | @@ -72,15 +72,15 @@ except Exception: |
| 72 | 72 | |
| 73 | 73 | else: |
| 74 | 74 | n = session.query(Student).count() |
| 75 | - print('New database created: {0}\n{1} user(s) inserted:'.format(args.db, n)) | |
| 75 | + print(f'New database created: {args.db}\n{n} user(s) inserted:') | |
| 76 | 76 | |
| 77 | 77 | users = session.query(Student).order_by(Student.id).all() |
| 78 | - print(' {0:8} - {1} (administrator)'.format(users[0].id, users[0].name)) | |
| 78 | + print(f' {users[0].id:8} - {users[0].name} (administrator)') | |
| 79 | 79 | if n > 1: |
| 80 | - print(' {0:8} - {1}'.format(users[1].id, users[1].name)) | |
| 80 | + print(f' {users[1].id:8} - {users[1].name}') | |
| 81 | 81 | if n > 3: |
| 82 | 82 | print(' ... ...') |
| 83 | 83 | if n > 2: |
| 84 | - print(' {0:8} - {1}'.format(users[-1].id, users[-1].name)) | |
| 84 | + print(f' {users[-1].id:8} - {users[-1].name}') | |
| 85 | 85 | |
| 86 | 86 | # --- end session --- | ... | ... |
serve.py
| ... | ... | @@ -168,7 +168,7 @@ class TestHandler(BaseHandler): |
| 168 | 168 | for i, q in enumerate(t['questions']): |
| 169 | 169 | qid = str(i) # question id |
| 170 | 170 | if 'answered-' + qid in self.request.arguments: |
| 171 | - ans[i] = self.get_body_arguments(qid, None) | |
| 171 | + ans[i] = self.get_body_arguments(qid) | |
| 172 | 172 | |
| 173 | 173 | # remove list when it does not make sense... |
| 174 | 174 | if q['type'] == 'radio': |
| ... | ... | @@ -219,10 +219,8 @@ class ReviewHandler(BaseHandler): |
| 219 | 219 | |
| 220 | 220 | try: |
| 221 | 221 | f = open(path.expanduser(fname)) |
| 222 | - except FileNotFoundError: # FIXME EnvironmentError? | |
| 223 | - logging.error(f'Cannot find "{fname}" for review.') | |
| 224 | - except Exception as e: | |
| 225 | - raise e | |
| 222 | + except OSError: | |
| 223 | + logging.error(f'Cannot open "{fname}" for review.') | |
| 226 | 224 | else: |
| 227 | 225 | with f: |
| 228 | 226 | t = json.load(f) | ... | ... |
test.py
| ... | ... | @@ -71,7 +71,7 @@ class TestFactory(dict): |
| 71 | 71 | raise TestFactoryException() |
| 72 | 72 | try: # check if answers_dir is a writable directory |
| 73 | 73 | f = open(path.join(path.expanduser(self['answers_dir']),'REMOVE-ME'), 'w') |
| 74 | - except EnvironmentError: | |
| 74 | + except OSError: | |
| 75 | 75 | logger.critical(f'Cannot write answers to "{self["answers_dir"]}".') |
| 76 | 76 | raise TestFactoryException() |
| 77 | 77 | else: |
| ... | ... | @@ -96,7 +96,7 @@ class TestFactory(dict): |
| 96 | 96 | logger.warning('Missing "files" key. Loading all YAML files from "questions_dir"... DANGEROUS!!!') |
| 97 | 97 | try: |
| 98 | 98 | self['files'] = fnmatch.filter(listdir(self['questions_dir']), '*.yaml') |
| 99 | - except EnvironmentError: | |
| 99 | + except OSError: | |
| 100 | 100 | logger.critical('Couldn\'t get list of YAML question files.') |
| 101 | 101 | raise TestFactoryException() |
| 102 | 102 | if isinstance(self['files'], str): | ... | ... |