Skip to content

Commit c9cd272

Browse files
Pylint suggestions
1 parent 10325e9 commit c9cd272

13 files changed

Lines changed: 82 additions & 80 deletions

File tree

cms/grading/TaskType.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def name(self):
152152
153153
"""
154154
# de-CamelCase the name, capitalize it and return it
155-
return re.sub("([A-Z])", " \g<1>",
155+
return re.sub("([A-Z])", r" \g<1>",
156156
self.__class__.__name__).strip().capitalize()
157157

158158
testable = True

cms/server/ContestWebServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def get(self, task_name, submission_num, filename):
739739
else:
740740
# We don't recognize this filename. Let's try to 'undo'
741741
# the '%l' -> 'c|cpp|pas' replacement before giving up.
742-
filename = re.sub('\.%s$' % submission.language, '.%l',
742+
filename = re.sub(r'\.%s$' % submission.language, '.%l',
743743
filename)
744744

745745
if filename not in submission.files:

cmscontrib/ContestExporter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def __init__(self, contest_id, export_target,
132132
self.contest_id = None
133133
else:
134134
self.export_target = "dump_%s.tar.gz" % contest.name
135-
logger.warning("export_target not given, using \"%s\""
136-
% self.export_target)
135+
logger.warning("export_target not given, using \"%s\"",
136+
self.export_target)
137137

138138
self.file_cacher = FileCacher()
139139

@@ -332,16 +332,16 @@ def safe_get_file(self, digest, path, descr_path=None):
332332
# First get the file
333333
try:
334334
self.file_cacher.get_file_to_path(digest, path)
335-
except Exception as error:
336-
logger.error("File %s could not retrieved from file server (%r)."
337-
% (digest, error))
335+
except Exception:
336+
logger.error("File %s could not retrieved from file server.",
337+
digest, exc_info=True)
338338
return False
339339

340340
# Then check the digest
341341
calc_digest = sha1sum(path)
342342
if digest != calc_digest:
343-
logger.critical("File %s has wrong hash %s."
344-
% (digest, calc_digest))
343+
logger.critical("File %s has wrong hash %s.",
344+
digest, calc_digest)
345345
return False
346346

347347
# If applicable, retrieve also the description

cmscontrib/ContestImporter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def do_import(self):
121121

122122
file_names = os.listdir(self.import_dir)
123123
if len(file_names) != 1:
124-
logger.critical("Cannot find a root directory in %s." %
124+
logger.critical("Cannot find a root directory in %s.",
125125
self.import_source)
126126
archive.cleanup()
127127
return False
@@ -136,8 +136,8 @@ def do_import(self):
136136
"and recreating the database.",
137137
exc_info=True)
138138
return False
139-
except Exception as error:
140-
logger.critical("Unable to access DB.\n%r" % error)
139+
except Exception:
140+
logger.critical("Unable to access DB.", exc_info=True)
141141
return False
142142

143143
with SessionGen() as session:
@@ -168,8 +168,8 @@ def do_import(self):
168168
"version %d). It may take a while to adapt it to "
169169
"the current data model (which is version %d). You "
170170
"can use cmsDumpUpdater to update the on-disk dump "
171-
"and speed up future imports."
172-
% (dump_version, model_version))
171+
"and speed up future imports.",
172+
dump_version, model_version)
173173

174174
if dump_version > model_version:
175175
logger.critical(
@@ -179,7 +179,7 @@ def do_import(self):
179179
"way to adapt it to the current data model (which "
180180
"is version %d). You probably need to update CMS to "
181181
"handle it. It is impossible to proceed with the "
182-
"importation." % (dump_version, model_version))
182+
"importation.", dump_version, model_version)
183183
return False
184184

185185
for version in range(dump_version, model_version):
@@ -279,7 +279,7 @@ def do_import(self):
279279
if not self.safe_put_file(file_, desc):
280280
logger.critical("Unable to put file `%s' in the DB. "
281281
"Aborting. Please remove the contest "
282-
"from the database." % file_)
282+
"from the database.", file_)
283283
# TODO: remove contest from the database.
284284
return False
285285

@@ -288,7 +288,7 @@ def do_import(self):
288288
archive.cleanup()
289289

290290
if contest_id is not None:
291-
logger.info("Import finished (contest id: %s)." %
291+
logger.info("Import finished (contest id: %s).",
292292
", ".join("%d" % id_ for id_ in contest_id))
293293
else:
294294
logger.info("Import finished.")
@@ -413,14 +413,14 @@ def safe_put_file(self, path, descr_path):
413413
digest = self.file_cacher.put_file_from_path(path, description)
414414
except Exception as error:
415415
logger.critical("File %s could not be put to file server (%r), "
416-
"aborting." % (path, error))
416+
"aborting.", path, error)
417417
return False
418418

419419
# Then check the digest.
420420
calc_digest = sha1sum(path)
421421
if digest != calc_digest:
422422
logger.critical("File %s has hash %s, but the server returned %s, "
423-
"aborting." % (path, calc_digest, digest))
423+
"aborting.", path, calc_digest, digest)
424424
return False
425425

426426
return True

cmscontrib/Importer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def _prepare_db(self):
8282
"recreating the database.",
8383
exc_info=True)
8484
return False
85-
except Exception as error:
86-
logger.critical("Unable to access DB.\n%r" % error)
85+
except Exception:
86+
logger.critical("Unable to access DB.", exc_info=True)
8787
return False
8888
return True
8989

@@ -104,7 +104,7 @@ def do_import(self):
104104
for user in users:
105105
contest.users.append(self.loader.get_user(user))
106106
else:
107-
logger.info("Generating %s random users." % self.user_number)
107+
logger.info("Generating %s random users.", self.user_number)
108108
contest.users = [User("User %d" % i,
109109
"Last name %d" % i,
110110
"user%03d" % i)
@@ -129,7 +129,7 @@ def do_import(self):
129129
session.commit()
130130
contest_id = contest.id
131131

132-
logger.info("Import finished (new contest id: %s)." % contest_id)
132+
logger.info("Import finished (new contest id: %s).", contest_id)
133133

134134

135135
def main():

cmscontrib/RWSHelper.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def main():
131131

132132
if args.verbose:
133133
verb = args.action[:4] + 'ting'
134-
logger.info("%s entity '%ss/%s'" % (verb.capitalize(),
135-
args.entity_type, args.entity_id))
134+
logger.info("%s entity '%ss/%s'", verb.capitalize(),
135+
args.entity_type, args.entity_id)
136136

137137
if args.rankings is not None:
138138
shards = args.rankings
@@ -149,9 +149,8 @@ def main():
149149
auth = urlsplit(url)
150150

151151
if args.verbose:
152-
logger.info(
153-
"Preparing %s request to %s" %
154-
(ACTION_METHODS[args.action], url))
152+
logger.info("Preparing %s request to %s",
153+
ACTION_METHODS[args.action], url)
155154

156155
if hasattr(args, 'file'):
157156
if args.verbose:
@@ -169,17 +168,16 @@ def main():
169168

170169
try:
171170
res = s.send(req, verify=config.https_certfile)
172-
except RequestException as error:
173-
logger.error("Failed")
174-
logger.info(repr(error))
171+
except RequestException:
172+
logger.error("Failed", exc_info=True)
175173
had_error = True
176174
continue
177175

178176
if args.verbose:
179177
logger.info("Response received")
180178

181179
if 400 <= res.status_code < 600:
182-
logger.error("Unexpected status code: %d" % res.status_code)
180+
logger.error("Unexpected status code: %d", res.status_code)
183181
had_error = True
184182
continue
185183

cmscontrib/Reimporter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,23 @@ def do_reimport(self):
238238

239239
if old_user is None:
240240
# Create a new user.
241-
logger.info("Creating user %s" % username)
241+
logger.info("Creating user %s", username)
242242
new_user = self.loader.get_user(username)
243243
old_contest.users.append(new_user)
244244
elif username in new_users:
245245
# Update an existing user.
246-
logger.info("Updating user %s" % username)
246+
logger.info("Updating user %s", username)
247247
new_user = self.loader.get_user(username)
248248
self._update_object(old_user, new_user)
249249
else:
250250
# Delete an existing user.
251251
if self.force:
252-
logger.info("Deleting user %s" % username)
252+
logger.info("Deleting user %s", username)
253253
old_contest.users.remove(old_user)
254254
else:
255255
logger.critical(
256256
"User %s exists in old contest, but "
257-
"not in the new one. Use -f to force." %
257+
"not in the new one. Use -f to force.",
258258
username)
259259
return False
260260

@@ -271,34 +271,34 @@ def do_reimport(self):
271271

272272
if old_task is None:
273273
# Create a new task.
274-
logger.info("Creating task %s" % task)
274+
logger.info("Creating task %s", task)
275275
new_task = self.loader.get_task(task)
276276
new_task.num = current_num
277277
current_num += 1
278278
old_contest.tasks.append(new_task)
279279
elif task in new_tasks:
280280
# Update an existing task.
281281
if self.full or self.loader.has_changed(task):
282-
logger.info("Updating task %s" % task)
282+
logger.info("Updating task %s", task)
283283
new_task = self.loader.get_task(task)
284284
new_task.num = current_num
285285
current_num += 1
286286
self._update_object(old_task, new_task)
287287
else:
288-
logger.info("Task %s has not changed" % task)
288+
logger.info("Task %s has not changed", task)
289289
# Even unchanged tasks should use a temporary number
290290
# to avoid duplicate numbers when we fix them.
291291
old_task.num = current_num
292292
current_num += 1
293293
else:
294294
# Delete an existing task.
295295
if self.force:
296-
logger.info("Deleting task %s" % task)
296+
logger.info("Deleting task %s", task)
297297
session.delete(old_task)
298298
else:
299299
logger.critical(
300300
"Task %s exists in old contest, but "
301-
"not in the new one. Use -f to force." %
301+
"not in the new one. Use -f to force.",
302302
task)
303303
return False
304304

@@ -315,7 +315,7 @@ def do_reimport(self):
315315

316316
session.commit()
317317

318-
logger.info("Reimport finished (contest id: %s)." %
318+
logger.info("Reimport finished (contest id: %s).",
319319
self.old_contest_id)
320320

321321
return True

cmscontrib/SpoolExporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def export_submissions(self):
117117
queue_file = io.open(os.path.join(self.spool_dir, "queue"), "w",
118118
encoding="utf-8")
119119
for submission in sorted(self.submissions, key=lambda x: x.timestamp):
120-
logger.info("Exporting submission %s." % submission.id)
120+
logger.info("Exporting submission %s.", submission.id)
121121
username = submission.user.username
122122
task = submission.task.name
123123
timestamp = time.mktime(submission.timestamp.timetuple())

cmscontrib/YamlLoader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def get_contest(self):
139139
io.open(os.path.join(self.path, "contest.yaml"),
140140
"rt", encoding="utf-8"))
141141

142-
logger.info("Loading parameters for contest %s." % name)
142+
logger.info("Loading parameters for contest %s.", name)
143143

144144
args = {}
145145

@@ -280,14 +280,14 @@ def has_changed(self, name):
280280

281281
if os.path.exists(os.path.join(path, ".import_error")):
282282
logger.warning("Last attempt to import task %s failed,"
283-
" I'm not trying again." % name)
283+
" I'm not trying again.", name)
284284
return False
285285

286286
def get_user(self, username):
287287
"""See docstring in class Loader.
288288
289289
"""
290-
logger.info("Loading parameters for user %s." % username)
290+
logger.info("Loading parameters for user %s.", username)
291291
conf = self.users_conf[username]
292292
assert username == conf['username']
293293

@@ -339,7 +339,7 @@ def get_task(self, name):
339339
io.open(os.path.join(self.path, name + ".yaml"),
340340
"rt", encoding="utf-8"))
341341

342-
logger.info("Loading parameters for task %s." % name)
342+
logger.info("Loading parameters for task %s.", name)
343343

344344
# Here we update the time of the last import
345345
touch(os.path.join(task_path, ".itime"))
@@ -473,7 +473,7 @@ def get_task(self, name):
473473
args["managers"] += [
474474
Manager("grader.%s" % lang, digest)]
475475
else:
476-
logger.warning("Grader for language %s not found " % lang)
476+
logger.warning("Grader for language %s not found ", lang)
477477
# Read managers with other known file extensions
478478
for other_filename in os.listdir(os.path.join(task_path, "sol")):
479479
if any(other_filename.endswith(header)
@@ -619,7 +619,7 @@ def get_task(self, name):
619619
Manager("stub.%s" % lang, digest)]
620620
else:
621621
logger.warning("Stub for language %s not "
622-
"found." % lang)
622+
"found.", lang)
623623
for other_filename in os.listdir(os.path.join(task_path,
624624
"sol")):
625625
if any(other_filename.endswith(header) for header in

cmsranking/Scoring.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ def create_subchange(self, key, subchange):
165165
break
166166
self.reset_history()
167167
logger.info("Reset history for user '%s' and task '%s' after "
168-
"creating subchange '%s' for submission '%s'" %
169-
(self._submissions[subchange.submission].user,
170-
self._submissions[subchange.submission].task,
171-
key, subchange.submission))
168+
"creating subchange '%s' for submission '%s'",
169+
self._submissions[subchange.submission].user,
170+
self._submissions[subchange.submission].task,
171+
key, subchange.submission)
172172

173173
def update_subchange(self, key, subchange):
174174
# Update the subchange inside the (sorted) list and,
@@ -178,17 +178,17 @@ def update_subchange(self, key, subchange):
178178
self._changes[i] = subchange
179179
self.reset_history()
180180
logger.info("Reset history for user '%s' and task '%s' after "
181-
"creating subchange '%s' for submission '%s'" %
182-
(self._submissions[subchange.submission].user,
183-
self._submissions[subchange.submission].task,
184-
key, subchange.submission))
181+
"creating subchange '%s' for submission '%s'",
182+
self._submissions[subchange.submission].user,
183+
self._submissions[subchange.submission].task,
184+
key, subchange.submission)
185185

186186
def delete_subchange(self, key):
187187
# Delete the subchange from the (sorted) list and reset the
188188
# history.
189189
self._changes = filter(lambda a: a.key != key, self._changes)
190190
self.reset_history()
191-
logger.info("Reset history after deleting subchange '%s'" % key)
191+
logger.info("Reset history after deleting subchange '%s'", key)
192192

193193
def create_submission(self, key, submission):
194194
# A new submission never triggers an update in the history,

0 commit comments

Comments
 (0)