84 lines
2.1 KiB
Python
Executable file
84 lines
2.1 KiB
Python
Executable file
# Scipt permettant d'automatiser les TP
|
|
|
|
import os
|
|
import zipfile
|
|
|
|
base = './'
|
|
rendeurs = [('BEAUSSART Jean-loup', 'Beaussart'),
|
|
('PREUD\'HOMME Geoffrey', 'PreudHomme')]
|
|
|
|
|
|
def chemin(semestre, tp=None):
|
|
return os.path.normpath(base + '/S' + str(semestre) + ('/TP' + str(tp) if tp else ''))
|
|
|
|
|
|
def semestreProchain():
|
|
i = 1
|
|
while os.path.exists(chemin(i)):
|
|
i += 1
|
|
return i
|
|
|
|
|
|
def semestreEnCours():
|
|
return semestreProchain() - 1
|
|
|
|
|
|
def tpProchain():
|
|
i = 1
|
|
semestre = semestreEnCours()
|
|
while os.path.exists(chemin(semestre, i)):
|
|
i += 1
|
|
return i
|
|
|
|
|
|
def tpEnCours():
|
|
return tpProchain() - 1
|
|
|
|
|
|
def fichiersTp(semestre, tp):
|
|
# TODO .gitignore
|
|
# TODO .tpfiles
|
|
return fichiersPythons(semestre, tp)
|
|
|
|
|
|
def fichiersPythons(semestre, tp):
|
|
chem = chemin(semestre, tp)
|
|
return [i for i in os.listdir(chem) if i.endswith('.py') and os.path.isfile(os.path.join(chem, i))]
|
|
|
|
|
|
def rendeur(semestre, tp):
|
|
for i in fichiersPythons(semestre, tp):
|
|
texte = open(os.path.join(chemin(semestre, tp), i), 'r').read()
|
|
rend = ''
|
|
rendeurMax = 500
|
|
for j in range(len(rendeurs)):
|
|
pos = texte.find(rendeurs[j][0]) # TODO Gérer \'
|
|
if pos < rendeurMax and pos >= 0:
|
|
rendeurMax = pos
|
|
rend = j
|
|
if rend != '':
|
|
return rend
|
|
return None
|
|
|
|
|
|
def personnesSurTP(semestre, tp):
|
|
rend = rendeur(semestre, tp)
|
|
personnes = [i[1] for i in rendeurs]
|
|
personnes.remove(rendeurs[rend][1])
|
|
personnes = [rendeurs[rend][1]] + personnes
|
|
return personnes
|
|
|
|
def creerZip(semestre, tp):
|
|
personnes = personnesSurTP(semestre, tp)
|
|
nomDossier = '_'.join(personnes)
|
|
nomZip = 'tp%d_%s.zip' % (tp, ('_'.join(personnes).lower()))
|
|
chem = chemin(semestre, tp)
|
|
fichierZip = zipfile.ZipFile(os.path.join(chem, nomZip), 'w')
|
|
for f in fichiersTp(semestre, tp):
|
|
fichierZip.write(os.path.join(chem, f), os.path.join(nomDossier, f))
|
|
fichierZip.close()
|
|
|
|
os.link(chemin(semestreEnCours(), tpEnCours()), 't')
|
|
os.link(chemin(semestreEnCours()), 's')
|
|
creerZip(semestreEnCours(), tpEnCours())
|