From dc88238f6340722a649fcf19fc5587a6e0e5dc0c Mon Sep 17 00:00:00 2001 From: IDK Date: Thu, 28 Jan 2021 23:28:48 +0100 Subject: [PATCH] code cleaning --- ZScoDoc.py | 86 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/ZScoDoc.py b/ZScoDoc.py index 4dad4ba3..3a2d328b 100644 --- a/ZScoDoc.py +++ b/ZScoDoc.py @@ -31,19 +31,29 @@ Chaque departement est géré par un ZScolar sous ZScoDoc. """ -import time, string, glob, re, inspect -import urllib, urllib2, cgi, xml +import time +import datetime +import string +import glob +import re +import inspect +import urllib +import urllib2 +import cgi +import xml from cStringIO import StringIO from zipfile import ZipFile -import os.path, glob +import os.path import traceback -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 sco_zope import * # pylint: disable=unused-wildcard-import @@ -52,10 +62,28 @@ try: except: import ZPsycopgDA.DA as ZopeDA # interp.py -from sco_utils import * +import sco_utils as scu +import VERSION from notes_log import log import sco_find_etud import sco_users +from sco_permissions import ( + ScoView, + ScoEnsView, + ScoImplement, + ScoChangeFormation, + ScoObservateur, + ScoEtudInscrit, + ScoEtudChangeGroups, + ScoEtudChangeAdr, + ScoEtudSupprAnnotations, + ScoEditAllEvals, + ScoEditAllNotes, + ScoEditFormationTags, + ScoEditApo, + ScoSuperAdmin, +) +from sco_exceptions import ScoValueError, ScoLockedFormError, ScoGenError, AccessDenied class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Implicit): @@ -101,7 +129,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp def _check_users_folder(self, REQUEST=None): """Vérifie UserFolder et le crée s'il le faut""" try: - udb = self.UsersDB + _ = self.UsersDB return "" except: e = self._check_admin_perm(REQUEST) @@ -154,7 +182,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp pass # add missing getAuthFailedMessage (bug in exUserFolder ?) try: - x = self.getAuthFailedMessage + _ = self.getAuthFailedMessage except: log("adding getAuthFailedMessage to Zope install") parent = self.aq_parent @@ -177,7 +205,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp da = ZopeDA.Connection( oid, "Cnx bd utilisateurs", - SCO_DEFAULT_SQL_USERS_CNX, + scu.SCO_DEFAULT_SQL_USERS_CNX, False, check=1, tilevel=2, @@ -254,7 +282,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp r = [] for folder in folders: try: - s = folder.Scolarite + _ = folder.Scolarite r.append(folder) except: pass @@ -352,10 +380,10 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp def scodoc_top_html_header(self, REQUEST, page_title="ScoDoc"): H = [ self._html_begin - % {"page_title": "ScoDoc: bienvenue", "encoding": SCO_ENCODING}, + % {"page_title": "ScoDoc: bienvenue", "encoding": scu.SCO_ENCODING}, self._top_level_css, """""", - CUSTOM_HTML_HEADER_CNX, + scu.CUSTOM_HTML_HEADER_CNX, ] return "\n".join(H) @@ -468,7 +496,7 @@ class ZScoDoc(ObjectManager, PropertyManager, RoleManager, Item, Persistent, Imp E. Viennet (Université Paris 13).

""" - % (SCO_WEBSITE,) + % (scu.SCO_WEBSITE,) ) H.append("""""") @@ -581,8 +609,8 @@ E. Viennet (Université Paris 13).

%s""" % ( - SCO_ENCODING, - CUSTOM_HTML_HEADER_CNX, + scu.SCO_ENCODING, + scu.CUSTOM_HTML_HEADER_CNX, ) security.declareProtected("View", "standard_html_footer") @@ -594,8 +622,8 @@ Problème de connexion (identifiant, mot de passe): contacter votre responsa

Problèmes et suggestions sur le logiciel: %s

ScoDoc est un logiciel libre développé par Emmanuel Viennet.

""" % ( - SCO_USERS_LIST, - SCO_USERS_LIST, + scu.SCO_USERS_LIST, + scu.SCO_USERS_LIST, ) # sendEmail is not used through the web @@ -640,8 +668,8 @@ Problème de connexion (identifiant, mot de passe): contacter votre responsa **kv ): "Recuperation des exceptions Zope" - sco_exc_mail = SCO_EXC_MAIL - sco_dev_mail = SCO_DEV_MAIL + sco_exc_mail = scu.SCO_EXC_MAIL + sco_dev_mail = scu.SCO_DEV_MAIL # neat (or should I say dirty ?) hack to get REQUEST # in fact, our caller (probably SimpleItem.py) has the REQUEST variable # that we'd like to use for our logs, but does not pass it as an argument. @@ -728,7 +756,7 @@ Problème de connexion (identifiant, mot de passe): contacter votre responsa pass # --- Mail: - error_traceback_txt = scodoc_html2txt(error_tb) + error_traceback_txt = scu.scodoc_html2txt(error_tb) txt = ( """ ErrorType: %(error_type)s @@ -762,7 +790,7 @@ ErrorType: %(error_type)s HTTP_USER_AGENT = "na" form = REQUEST.get("form", "") HTTP_X_FORWARDED_FOR = REQUEST.get("HTTP_X_FORWARDED_FOR", "") - svn_version = get_svn_version(self.file_path) + svn_version = scu.get_svn_version(self.file_path) SCOVERSION = VERSION.SCOVERSION txt = ( @@ -792,7 +820,7 @@ subversion: %(svn_version)s def send_debug_alert(self, txt, REQUEST=None): """Send an alert email (bug report) to ScoDoc developpers""" - if not SCO_EXC_MAIL: + if not scu.SCO_EXC_MAIL: log("send_debug_alert: email disabled") return if REQUEST: @@ -801,13 +829,13 @@ subversion: %(svn_version)s else: URL = "send_debug_alert" msg = MIMEMultipart() - subj = Header("[scodoc] exc %s" % URL, SCO_ENCODING) + subj = Header("[scodoc] exc %s" % URL, scu.SCO_ENCODING) msg["Subject"] = subj - recipients = [SCO_EXC_MAIL] + recipients = [scu.SCO_EXC_MAIL] msg["To"] = " ,".join(recipients) msg["From"] = "scodoc-alert" msg.epilogue = "" - msg.attach(MIMEText(txt, "plain", SCO_ENCODING)) + msg.attach(MIMEText(txt, "plain", scu.SCO_ENCODING)) self.sendEmailFromException(msg) log("Sent mail alert:\n" + txt) @@ -881,7 +909,7 @@ subversion: %(svn_version)s """Liste de id de departements definis par create_dept.sh (fichiers depts/*.cfg) """ - filenames = glob.glob(SCODOC_VAR_DIR + "/config/depts/*.cfg") + filenames = glob.glob(scu.SCODOC_VAR_DIR + "/config/depts/*.cfg") ids = [os.path.split(os.path.splitext(f)[0])[1] for f in filenames] return ids