1
0
forked from ScoDoc/ScoDoc

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

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

@ -18,37 +18,49 @@ 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
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)
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',
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',
@ -57,9 +69,6 @@ tables = ( 'absences',
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()

View File

@ -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()