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 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
3 | 3 | ||
4 | import csv | 4 | import csv |
@@ -44,8 +44,8 @@ try: | @@ -44,8 +44,8 @@ try: | ||
44 | # from csv file if available | 44 | # from csv file if available |
45 | try: | 45 | try: |
46 | csvreader = csv.DictReader(open(args.csvfile, encoding='iso-8859-1'), delimiter=';', quotechar='"', skipinitialspace=True) | 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 | session.rollback() | 49 | session.rollback() |
50 | sys.exit(1) | 50 | sys.exit(1) |
51 | else: | 51 | else: |
@@ -72,15 +72,15 @@ except Exception: | @@ -72,15 +72,15 @@ except Exception: | ||
72 | 72 | ||
73 | else: | 73 | else: |
74 | n = session.query(Student).count() | 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 | users = session.query(Student).order_by(Student.id).all() | 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 | if n > 1: | 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 | if n > 3: | 81 | if n > 3: |
82 | print(' ... ...') | 82 | print(' ... ...') |
83 | if n > 2: | 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 | # --- end session --- | 86 | # --- end session --- |
serve.py
@@ -168,7 +168,7 @@ class TestHandler(BaseHandler): | @@ -168,7 +168,7 @@ class TestHandler(BaseHandler): | ||
168 | for i, q in enumerate(t['questions']): | 168 | for i, q in enumerate(t['questions']): |
169 | qid = str(i) # question id | 169 | qid = str(i) # question id |
170 | if 'answered-' + qid in self.request.arguments: | 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 | # remove list when it does not make sense... | 173 | # remove list when it does not make sense... |
174 | if q['type'] == 'radio': | 174 | if q['type'] == 'radio': |
@@ -219,10 +219,8 @@ class ReviewHandler(BaseHandler): | @@ -219,10 +219,8 @@ class ReviewHandler(BaseHandler): | ||
219 | 219 | ||
220 | try: | 220 | try: |
221 | f = open(path.expanduser(fname)) | 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 | else: | 224 | else: |
227 | with f: | 225 | with f: |
228 | t = json.load(f) | 226 | t = json.load(f) |
test.py
@@ -71,7 +71,7 @@ class TestFactory(dict): | @@ -71,7 +71,7 @@ class TestFactory(dict): | ||
71 | raise TestFactoryException() | 71 | raise TestFactoryException() |
72 | try: # check if answers_dir is a writable directory | 72 | try: # check if answers_dir is a writable directory |
73 | f = open(path.join(path.expanduser(self['answers_dir']),'REMOVE-ME'), 'w') | 73 | f = open(path.join(path.expanduser(self['answers_dir']),'REMOVE-ME'), 'w') |
74 | - except EnvironmentError: | 74 | + except OSError: |
75 | logger.critical(f'Cannot write answers to "{self["answers_dir"]}".') | 75 | logger.critical(f'Cannot write answers to "{self["answers_dir"]}".') |
76 | raise TestFactoryException() | 76 | raise TestFactoryException() |
77 | else: | 77 | else: |
@@ -96,7 +96,7 @@ class TestFactory(dict): | @@ -96,7 +96,7 @@ class TestFactory(dict): | ||
96 | logger.warning('Missing "files" key. Loading all YAML files from "questions_dir"... DANGEROUS!!!') | 96 | logger.warning('Missing "files" key. Loading all YAML files from "questions_dir"... DANGEROUS!!!') |
97 | try: | 97 | try: |
98 | self['files'] = fnmatch.filter(listdir(self['questions_dir']), '*.yaml') | 98 | self['files'] = fnmatch.filter(listdir(self['questions_dir']), '*.yaml') |
99 | - except EnvironmentError: | 99 | + except OSError: |
100 | logger.critical('Couldn\'t get list of YAML question files.') | 100 | logger.critical('Couldn\'t get list of YAML question files.') |
101 | raise TestFactoryException() | 101 | raise TestFactoryException() |
102 | if isinstance(self['files'], str): | 102 | if isinstance(self['files'], str): |