Skip to content

Commit 9e52d52

Browse files
committed
Enforce formatting in mig/lib and tests/ directories.
1 parent 8e6b89d commit 9e52d52

59 files changed

Lines changed: 6099 additions & 4249 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ ifndef PY
66
PY = 3
77
endif
88

9-
FORMAT_ENFORCE_DIRS = state/
10-
FORMAT_EXCLUDE_REGEX = '.*'
11-
FORMAT_EXCLUDE_GLOB = '*'
9+
FORMAT_ENFORCE_DIRS = ./mig/lib ./tests
10+
FORMAT_EXCLUDE_REGEX = '.git|tests/data/|tests/fixture/'
11+
FORMAT_EXCLUDE_GLOB = '.git/* tests/data/* tests/fixture/*'
1212
FORMAT_LINE_LENGTH = 80
13-
1413
LOCAL_PYTHON_BIN = './envhelp/lpython'
1514

1615
ifdef PYTHON_BIN

mig/lib/accounting.py

Lines changed: 253 additions & 221 deletions
Large diffs are not rendered by default.

mig/lib/events.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ def run_cron_command(
433433
_restore_env(saved_environ, os.environ)
434434
raise exc
435435
logger.info(
436-
"(%s) done running command for %s: %s" % (
437-
pid, target_path, command_str)
436+
"(%s) done running command for %s: %s" % (pid, target_path, command_str)
438437
)
439438

440439
# logger.debug('(%s) raw output is: %s' % (pid, output_objects))
@@ -532,8 +531,7 @@ def run_events_command(
532531
_restore_env(saved_environ, os.environ)
533532
raise exc
534533
logger.info(
535-
"(%s) done running command for %s: %s" % (
536-
pid, target_path, command_str)
534+
"(%s) done running command for %s: %s" % (pid, target_path, command_str)
537535
)
538536

539537
# logger.debug('(%s) raw output is: %s' % (pid, output_objects))

mig/lib/janitor.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
import os
3737
import time
3838

39-
from mig.shared.accountreq import accept_account_req, existing_user_collision, \
40-
reject_account_req
39+
from mig.shared.accountreq import (
40+
accept_account_req,
41+
existing_user_collision,
42+
reject_account_req,
43+
)
4144
from mig.shared.base import get_user_id
4245
from mig.shared.fileio import delete_file, listdir
4346
from mig.shared.pwcrypto import verify_reset_token
@@ -274,7 +277,7 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
274277
_logger.info("%r made an invalid account request" % client_id)
275278
# NOTE: 'invalid' is a list of validation error strings if set
276279
reason = "invalid request: %s." % ". ".join(req_invalid)
277-
(rej_status, rej_err) = reject_account_req(
280+
rej_status, rej_err = reject_account_req(
278281
req_id,
279282
configuration,
280283
reason,
@@ -284,21 +287,27 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
284287
)
285288
if not rej_status:
286289
_logger.warning(
287-
"failed to reject invalid %r account request: %s" % (client_id,
288-
rej_err)
290+
"failed to reject invalid %r account request: %s"
291+
% (client_id, rej_err)
289292
)
290293
else:
291294
_logger.info("rejected invalid %r account request" % client_id)
292295
elif authorized:
293-
_logger.info("%r requested renew and authorized password change" %
294-
client_id)
296+
_logger.info(
297+
"%r requested renew and authorized password change" % client_id
298+
)
295299
peer_id = user_dict.get("peers", [None])[0]
296300
# NOTE: let authorized reqs (with valid peer) renew even with pw change
297301
default_renew = True
298-
if accept_account_req(req_id, configuration, peer_id,
299-
user_copy=user_copy, admin_copy=admin_copy,
300-
auth_type=auth_type,
301-
default_renew=default_renew):
302+
if accept_account_req(
303+
req_id,
304+
configuration,
305+
peer_id,
306+
user_copy=user_copy,
307+
admin_copy=admin_copy,
308+
auth_type=auth_type,
309+
default_renew=default_renew,
310+
):
302311
_logger.info("accepted authorized %r access renew" % client_id)
303312
else:
304313
_logger.warning("failed authorized %r access renew" % client_id)
@@ -313,7 +322,7 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
313322
"%r requested and authorized password reset" % client_id
314323
)
315324
peer_id = user_dict.get("peers", [None])[0]
316-
(acc_status, acc_err) = accept_account_req(
325+
acc_status, acc_err = accept_account_req(
317326
req_id,
318327
configuration,
319328
peer_id,
@@ -324,18 +333,18 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
324333
)
325334
if not acc_status:
326335
_logger.warning(
327-
"failed to accept %r password reset: %s" % (client_id,
328-
acc_err)
336+
"failed to accept %r password reset: %s"
337+
% (client_id, acc_err)
329338
)
330339
else:
331340
_logger.info("accepted %r password reset" % client_id)
332341
else:
333342
_logger.warning(
334-
"%r requested password reset with bad token: %s" % (
335-
client_id, reset_token)
343+
"%r requested password reset with bad token: %s"
344+
% (client_id, reset_token)
336345
)
337346
reason = "invalid password reset token"
338-
(rej_status, rej_err) = reject_account_req(
347+
rej_status, rej_err = reject_account_req(
339348
req_id,
340349
configuration,
341350
reason,
@@ -345,16 +354,16 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
345354
)
346355
if not rej_status:
347356
_logger.warning(
348-
"failed to reject %r password reset: %s" % (client_id,
349-
rej_err)
357+
"failed to reject %r password reset: %s"
358+
% (client_id, rej_err)
350359
)
351360
else:
352361
_logger.info("rejected %r password reset" % client_id)
353362
elif req_expire < now:
354363
# NOTE: probably should no longer happen after initial auto clean
355364
_logger.warning("%r request is now past expire" % client_id)
356365
reason = "expired request - please re-request if still relevant"
357-
(rej_status, rej_err) = reject_account_req(
366+
rej_status, rej_err = reject_account_req(
358367
req_id,
359368
configuration,
360369
reason,
@@ -363,15 +372,15 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
363372
auth_type=auth_type,
364373
)
365374
if not rej_status:
366-
_logger.warning("failed to reject expired %r request: %s" %
367-
(client_id, rej_err)
368-
)
375+
_logger.warning(
376+
"failed to reject expired %r request: %s" % (client_id, rej_err)
377+
)
369378
else:
370379
_logger.info("rejected %r request now past expire" % client_id)
371380
elif existing_user_collision(configuration, req_dict, client_id):
372381
_logger.warning("ID collision in request from %r" % client_id)
373382
reason = "ID collision - please re-request with *existing* ID fields"
374-
(rej_status, rej_err) = reject_account_req(
383+
rej_status, rej_err = reject_account_req(
375384
req_id,
376385
configuration,
377386
reason,
@@ -381,8 +390,8 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
381390
)
382391
if not rej_status:
383392
_logger.warning(
384-
"failed to reject %r request with ID collision: %s" %
385-
(client_id, rej_err)
393+
"failed to reject %r request with ID collision: %s"
394+
% (client_id, rej_err)
386395
)
387396
else:
388397
_logger.info("rejected %r request with ID collision" % client_id)
@@ -417,8 +426,7 @@ def manage_trivial_user_requests(configuration, now=None):
417426
continue
418427
req_id = filename
419428
req_path = os.path.join(configuration.user_pending, req_id)
420-
_logger.debug("checking if account request in %r is trivial" %
421-
req_path)
429+
_logger.debug("checking if account request in %r is trivial" % req_path)
422430
req_age = now - os.path.getmtime(req_path)
423431
req_age_minutes = req_age / SECS_PER_MINUTE
424432
if req_age_minutes > MANAGE_TRIVIAL_REQ_MINUTES:
@@ -428,8 +436,7 @@ def manage_trivial_user_requests(configuration, now=None):
428436
)
429437
manage_single_req(configuration, req_id, req_path, db_path, now)
430438
handled += 1
431-
_logger.debug("handled %d trivial user account request action(s)" %
432-
handled)
439+
_logger.debug("handled %d trivial user account request action(s)" % handled)
433440
return handled
434441

435442

@@ -474,7 +481,7 @@ def remind_and_expire_user_pending(configuration, now=None):
474481
)
475482
user_copy = True
476483
admin_copy = True
477-
(rej_status, rej_err) = reject_account_req(
484+
rej_status, rej_err = reject_account_req(
478485
req_id,
479486
configuration,
480487
reason,
@@ -483,11 +490,12 @@ def remind_and_expire_user_pending(configuration, now=None):
483490
auth_type=auth_type,
484491
)
485492
if not rej_status:
486-
_logger.warning("failed to expire %s request from %r: %s" %
487-
(req_id, client_id, rej_err))
493+
_logger.warning(
494+
"failed to expire %s request from %r: %s"
495+
% (req_id, client_id, rej_err)
496+
)
488497
else:
489-
_logger.info("expired %s request from %r" % (req_id,
490-
client_id))
498+
_logger.info("expired %s request from %r" % (req_id, client_id))
491499
handled += 1
492500
_logger.debug("handled %d user account request action(s)" % handled)
493501
return handled

0 commit comments

Comments
 (0)