Enhance change_etudid.py

This commit is contained in:
viennet 2020-11-26 10:23:52 +01:00
parent 7757173d1b
commit 0db128759f
2 changed files with 40 additions and 30 deletions

61
misc/change_etudid.py Normal file → Executable file
View File

@ -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 Attention: script a lancer en tant que "www-data", avec ScoDoc arrete
et postgresql lance 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: DBCNXSTRING = "dbname=%s" % dbname
OLD_ETUDID = 'EID1512' # etudid qui est en double (que l'on supprime)
NEW_ETUDID = '10500686' # etudid destination (celui d'origine)
cnx = psycopg2.connect( DBCNXSTRING ) cnx = psycopg2.connect(DBCNXSTRING)
cursor = cnx.cursor() cursor = cnx.cursor()
req = "update %s set etudid=%%(new_etudid)s where etudid=%%(old_etudid)s" 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', tables = (
'absences_notifications', "absences",
'billet_absence', "absences_notifications",
'scolog', "billet_absence",
'etud_annotations', "scolog",
'entreprise_contact', "etud_annotations",
'notes_formsemestre_inscription', "entreprise_contact",
'notes_moduleimpl_inscription', "notes_formsemestre_inscription",
'notes_notes', 'notes_notes_log', "notes_moduleimpl_inscription",
'scolar_events', "notes_notes",
'scolar_formsemestre_validation', "notes_notes_log",
'scolar_autorisation_inscription', "scolar_events",
'notes_appreciations', "scolar_formsemestre_validation",
"scolar_autorisation_inscription",
"notes_appreciations",
"itemsuivi",
"group_membership",
# nouvelles absences # nouvelles absences
#'abs_absences', #'abs_absences',
#'abs_presences', #'abs_presences',
#'abs_justifs', #'abs_justifs',
) )
for table in tables: for table in tables:
cursor.execute(req % table, args) cursor.execute(req % table, args)
print 'table %s: %s' % (table, cursor.statusmessage) print "table %s: %s" % (table, cursor.statusmessage)
cnx.commit() cnx.commit()

View File

@ -138,4 +138,5 @@ my_server = socketserver.TCPServer(("", PORT), handler_object)
if __name__ == "__main__": if __name__ == "__main__":
# Start the server # Start the server
print(f"Server listening on port {PORT}...")
my_server.serve_forever() my_server.serve_forever()