From b86c815b02e9bb2da4ba72df39bab290b29940c7 Mon Sep 17 00:00:00 2001 From: IDK Date: Tue, 2 Feb 2021 14:49:49 +0100 Subject: [PATCH] pylinting --- csv2rules.py | 28 +++++++++++++++++++---- notes_log.py | 18 +++++++++++---- notesdb.py | 14 +++++++----- pe_tagtable.py | 2 +- sco_abs_notification.py | 12 ++++++---- sco_dump_db.py | 16 ++++++++----- sco_import_users.py | 14 ++++++------ test_jurype.py => scotests/test_jurype.py | 0 8 files changed, 71 insertions(+), 33 deletions(-) rename test_jurype.py => scotests/test_jurype.py (100%) diff --git a/csv2rules.py b/csv2rules.py index be06c95d8..1bf8ed57c 100755 --- a/csv2rules.py +++ b/csv2rules.py @@ -45,7 +45,27 @@ HEAD = """# -*- coding: utf-8 -*- # # Command: %s %s # -from sco_codes_parcours import * +from sco_codes_parcours import ( + DUTRule, + ADC, + ADJ, + ADM, + AJ, + ALL, + ATB, + ATJ, + ATT, + CMP, + NAR, + NEXT, + RA_OR_NEXT, + RA_OR_RS, + RAT, + REO, + REDOANNEE, + REDOSEM, + RS_OR_NEXT, +) rules_source_file='%s' @@ -55,15 +75,15 @@ rules_source_file='%s' sourcefile, ) -from sco_codes_parcours import * +import sco_utils as scu def _fmt(s): if not s: return None - if strlower(s) in ("ok", "oui", "o", "y", "yes"): + if scu.strlower(s) in ("ok", "oui", "o", "y", "yes"): return True - if strlower(s) in ("no", "non"): + if scu.strlower(s) in ("no", "non"): return False if s == "*": return ALL diff --git a/notes_log.py b/notes_log.py index de2d4619e..03852f9e3 100644 --- a/notes_log.py +++ b/notes_log.py @@ -1,12 +1,22 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -import pdb, os, sys, time, re, inspect -from email.MIMEMultipart import MIMEMultipart -from email.MIMEText import MIMEText -from email.Header import Header +import pdb +import sys +import os +import re +import inspect +import time import traceback +from email.MIMEMultipart import ( # pylint: disable=no-name-in-module,import-error + MIMEMultipart, +) +from email.MIMEText import MIMEText # pylint: disable=no-name-in-module,import-error +from email.MIMEBase import MIMEBase # pylint: disable=no-name-in-module,import-error +from email.Header import Header # pylint: disable=no-name-in-module,import-error +from email import Encoders # pylint: disable=no-name-in-module,import-error + # Simple & stupid file logguer, used only to debug # (logging to SQL is done in scolog) diff --git a/notesdb.py b/notesdb.py index 09e51a3be..fb073abf3 100644 --- a/notesdb.py +++ b/notesdb.py @@ -5,6 +5,7 @@ import pdb, os, sys, string import traceback import psycopg2 import psycopg2.pool +import psycopg2.extras import thread from notes_log import log from sco_exceptions import * @@ -67,16 +68,17 @@ def GetUsersDBConnexion(context, autocommit=True): return cnx +# Nota: on pourrait maintenant utiliser psycopg2.extras.DictCursor class ScoDocCursor(psycopg2.extensions.cursor): """A database cursor emulating some methods of psycopg v1 cursors""" - def dictfetchall(cursor): - col_names = [d[0] for d in cursor.description] - return [dict(zip(col_names, row)) for row in cursor.fetchall()] + def dictfetchall(self): + col_names = [d[0] for d in self.description] + return [dict(zip(col_names, row)) for row in self.fetchall()] - def dictfetchone(cursor): - col_names = [d[0] for d in cursor.description] - row = cursor.fetchone() + def dictfetchone(self): + col_names = [d[0] for d in self.description] + row = self.fetchone() if row: return dict(zip(col_names, row)) else: diff --git a/pe_tagtable.py b/pe_tagtable.py index fcdcd178b..56ea883ca 100644 --- a/pe_tagtable.py +++ b/pe_tagtable.py @@ -210,7 +210,7 @@ class TableTag: ] nb_notes_valides = len(notes_valides) if nb_notes_valides > 0: - (moy, coeff) = moyenne_ponderee_terme_a_terme(notes_valides, force=True) + (moy, _) = moyenne_ponderee_terme_a_terme(notes_valides, force=True) self.statistiques[tag] = (moy, max(notes_valides), min(notes_valides)) # ************************************************************************ diff --git a/sco_abs_notification.py b/sco_abs_notification.py index 7dfa682e2..e26e3d123 100644 --- a/sco_abs_notification.py +++ b/sco_abs_notification.py @@ -31,11 +31,13 @@ Il suffit d'appeler abs_notify() après chaque ajout d'absence. """ - -from email.MIMEMultipart import MIMEMultipart -from email.MIMEText import MIMEText -from email.Header import Header -from email import Encoders +from email.MIMEMultipart import ( # pylint: disable=no-name-in-module,import-error + MIMEMultipart, +) +from email.MIMEText import MIMEText # pylint: disable=no-name-in-module,import-error +from email.MIMEBase import MIMEBase # pylint: disable=no-name-in-module,import-error +from email.Header import Header # pylint: disable=no-name-in-module,import-error +from email import Encoders # pylint: disable=no-name-in-module,import-error from notesdb import * from sco_utils import * diff --git a/sco_dump_db.py b/sco_dump_db.py index 621fd96bb..9cea74073 100644 --- a/sco_dump_db.py +++ b/sco_dump_db.py @@ -50,11 +50,15 @@ pg_dump SCORT | psql ANORT import fcntl import subprocess import requests -from email.MIMEMultipart import MIMEMultipart -from email.MIMEText import MIMEText -from email.MIMEBase import MIMEBase -from email.Header import Header -from email import Encoders + +from email.MIMEMultipart import ( # pylint: disable=no-name-in-module,import-error + MIMEMultipart, +) +from email.MIMEText import MIMEText # pylint: disable=no-name-in-module,import-error +from email.MIMEBase import MIMEBase # pylint: disable=no-name-in-module,import-error +from email.Header import Header # pylint: disable=no-name-in-module,import-error +from email import Encoders # pylint: disable=no-name-in-module,import-error + from notesdb import * from sco_utils import * @@ -74,7 +78,7 @@ def sco_dump_and_send_db(context, REQUEST=None): try: x = open(SCO_DUMP_LOCK, "w+") fcntl.flock(x, fcntl.LOCK_EX | fcntl.LOCK_NB) - except fcntl.BlockingIOError: + except (IOError, OSError): # exception changed from Python 2 to 3 raise ScoValueError( "Un envoi de la base " + db_name diff --git a/sco_import_users.py b/sco_import_users.py index c6da8d293..e974dbcac 100644 --- a/sco_import_users.py +++ b/sco_import_users.py @@ -27,6 +27,13 @@ """Import d'utilisateurs via fichier Excel """ +from email.MIMEMultipart import ( # pylint: disable=no-name-in-module,import-error + MIMEMultipart, +) +from email.MIMEText import MIMEText # pylint: disable=no-name-in-module,import-error +from email.MIMEBase import MIMEBase # pylint: disable=no-name-in-module,import-error +from email.Header import Header # pylint: disable=no-name-in-module,import-error +from email import Encoders # pylint: disable=no-name-in-module,import-error from notesdb import * from sco_utils import * @@ -163,13 +170,6 @@ def generate_password(): return "".join(RNG.sample(l, PASSLEN)) -from email.MIMEMultipart import MIMEMultipart -from email.MIMEText import MIMEText -from email.MIMEBase import MIMEBase -from email.Header import Header -from email import Encoders - - def mail_password(u, context=None, reset=False): "Send password by email" if not u["email"]: diff --git a/test_jurype.py b/scotests/test_jurype.py similarity index 100% rename from test_jurype.py rename to scotests/test_jurype.py