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

103 lines
2.5 KiB
Python
Raw Normal View History

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