From 0db128759f94170842e8fcfe6ff05a804acbaa1e Mon Sep 17 00:00:00 2001 From: viennet Date: Thu, 26 Nov 2020 10:23:52 +0100 Subject: [PATCH] Enhance change_etudid.py --- misc/change_etudid.py | 69 +++++++++++++++++++--------------- tests/fakeportal/fakeportal.py | 1 + 2 files changed, 40 insertions(+), 30 deletions(-) mode change 100644 => 100755 misc/change_etudid.py diff --git a/misc/change_etudid.py b/misc/change_etudid.py old mode 100644 new mode 100755 index eef41019..eac00e1d --- a/misc/change_etudid.py +++ b/misc/change_etudid.py @@ -18,48 +18,57 @@ Ne traite que les inscriptions, les notes, absences, annotations, mais Attention: script a lancer en tant que "www-data", avec ScoDoc arrete et postgresql lance -Emmanuel Viennet, 2007 +Emmanuel Viennet, 2007-2020 """ -import pdb,os,sys,psycopg2 +import pdb, os, sys, psycopg2 +if len(sys.argv) != 4: + print "Usage: %s database orig_etudid dest_etudid" % sys.argv[0] + print " Fusionne l'étudiant orig dans l'étudiant dest." + print " L'identité, adresse et admission de dest restent inchangées." + print " Les inscriptions, notes, absences etc. d'orig sont associées à dest." + print " Après cette operation, orig_etudid peut être supprimé." + print "Exemple: change_etudid.py SCOGEII E1234 E87654" + sys.exit(1) -DBCNXSTRING = 'dbname=SCOXXX' +dbname = sys.argv[1] +OLD_ID = sys.argv[2] # etudid qui est en double (que l'on supprime) +NEW_ID = sys.argv[3] # etudid destination (celui d'origine) -# exemple: -OLD_ETUDID = 'EID1512' # etudid qui est en double (que l'on supprime) -NEW_ETUDID = '10500686' # etudid destination (celui d'origine) +DBCNXSTRING = "dbname=%s" % dbname -cnx = psycopg2.connect( DBCNXSTRING ) +cnx = psycopg2.connect(DBCNXSTRING) cursor = cnx.cursor() req = "update %s set etudid=%%(new_etudid)s where etudid=%%(old_etudid)s" -args = { 'old_etudid' : OLD_ETUDID, 'new_etudid' : NEW_ETUDID } +args = {"old_etudid": OLD_ID, "new_etudid": NEW_ID} -tables = ( 'absences', - 'absences_notifications', - 'billet_absence', - 'scolog', - 'etud_annotations', - 'entreprise_contact', - 'notes_formsemestre_inscription', - 'notes_moduleimpl_inscription', - 'notes_notes', 'notes_notes_log', - 'scolar_events', - 'scolar_formsemestre_validation', - 'scolar_autorisation_inscription', - 'notes_appreciations', - # nouvelles absences - #'abs_absences', - #'abs_presences', - #'abs_justifs', - ) +tables = ( + "absences", + "absences_notifications", + "billet_absence", + "scolog", + "etud_annotations", + "entreprise_contact", + "notes_formsemestre_inscription", + "notes_moduleimpl_inscription", + "notes_notes", + "notes_notes_log", + "scolar_events", + "scolar_formsemestre_validation", + "scolar_autorisation_inscription", + "notes_appreciations", + "itemsuivi", + "group_membership", + # nouvelles absences + #'abs_absences', + #'abs_presences', + #'abs_justifs', +) for table in tables: cursor.execute(req % table, args) - print 'table %s: %s' % (table, cursor.statusmessage) + print "table %s: %s" % (table, cursor.statusmessage) cnx.commit() - - - diff --git a/tests/fakeportal/fakeportal.py b/tests/fakeportal/fakeportal.py index 14bcf72c..94b2a78a 100755 --- a/tests/fakeportal/fakeportal.py +++ b/tests/fakeportal/fakeportal.py @@ -138,4 +138,5 @@ my_server = socketserver.TCPServer(("", PORT), handler_object) if __name__ == "__main__": # Start the server + print(f"Server listening on port {PORT}...") my_server.serve_forever()