This repository has been archived on 2019-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
s1-tp/auto.py

98 lines
2.4 KiB
Python
Raw Normal View History

2015-02-16 18:59:44 +01:00
#!/usr/bin/python3
"""
TP AP1
Licence SESI 1ère année
Univ. Lille 1
Scipt permettant d'automatiser les TP
"""
__author__ = "PREUD'HOMME Geoffrey"
2015-01-26 23:07:12 +01:00
import os
2015-02-10 11:11:03 +01:00
import zipfile
2015-01-26 23:07:12 +01:00
base = './'
2015-02-10 11:11:03 +01:00
rendeurs = [('BEAUSSART Jean-loup', 'Beaussart'),
('PREUD\'HOMME Geoffrey', 'PreudHomme')]
2015-01-26 23:07:12 +01:00
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
2015-02-10 11:11:03 +01:00
2015-01-26 23:07:12 +01:00
def fichiersTp(semestre, tp):
2015-02-10 11:11:03 +01:00
# TODO .gitignore
# TODO .tpfiles
2015-02-16 18:59:44 +01:00
fichiers = fichiersPythons(semestre, tp)
if semestre == 2 and tp == 3:
fichiers.remove('bataille_navale_graphique.py')
fichiers.append('jeu3.txt')
return fichiers
2015-02-10 11:11:03 +01:00
2015-01-26 23:07:12 +01:00
def fichiersPythons(semestre, tp):
chem = chemin(semestre, tp)
2015-02-10 11:11:03 +01:00
return [i for i in os.listdir(chem) if i.endswith('.py') and os.path.isfile(os.path.join(chem, i))]
2015-01-26 23:07:12 +01:00
def rendeur(semestre, tp):
for i in fichiersPythons(semestre, tp):
2015-02-10 11:11:03 +01:00
texte = open(os.path.join(chemin(semestre, tp), i), 'r').read()
2015-01-26 23:07:12 +01:00
rend = ''
rendeurMax = 500
for j in range(len(rendeurs)):
2015-02-10 11:11:03 +01:00
pos = texte.find(rendeurs[j][0]) # TODO Gérer \'
if pos < rendeurMax and pos >= 0:
2015-01-26 23:07:12 +01:00
rendeurMax = pos
rend = j
if rend != '':
return rend
return None
2015-02-10 11:11:03 +01:00
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)
2015-02-16 18:59:44 +01:00
fichierZip = zipfile.ZipFile(os.path.join(chem, nomZip), 'w', zipfile.ZIP_DEFLATED)
2015-02-10 11:11:03 +01:00
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')
2015-02-10 11:11:03 +01:00
creerZip(semestreEnCours(), tpEnCours())