2012-03-09 21:39:12 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
|
|
|
|
import xml.dom.minidom as md
|
|
|
|
import os
|
|
|
|
import optparse
|
|
|
|
|
|
|
|
import lecon
|
|
|
|
import config
|
|
|
|
|
|
|
|
# --------------------------------------------------
|
|
|
|
#
|
|
|
|
# Classe des développements
|
|
|
|
#
|
|
|
|
# --------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class Dev():
|
|
|
|
""" Pour les développements
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, ):
|
|
|
|
""" Initialisation du développement
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.nom = None
|
|
|
|
self.book=[]
|
|
|
|
self.lecon=[]
|
|
|
|
|
|
|
|
def from_file(self, file):
|
|
|
|
""" Importe les informations depuis un fichier
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
|
|
|
- `file`: fichier au format xml
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.document=md.parse(file)
|
|
|
|
except:
|
|
|
|
print("Le fichier ", file , " est inconnu")
|
|
|
|
else:
|
|
|
|
self.file = file
|
|
|
|
|
|
|
|
# Extraction du nom du developpement
|
|
|
|
self.nom = self.document.getElementsByTagName('dev')[0].getAttribute("nom")
|
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
# On vérifie s'il est sensé être connu
|
|
|
|
self.connu = self.document.getElementsByTagName('dev')[0].getAttribute("connu")
|
|
|
|
|
2012-03-09 21:39:12 +00:00
|
|
|
# des lecons
|
|
|
|
for lecon in self.document.getElementsByTagName('lecon'):
|
|
|
|
self.lecon += [lecon.getAttribute("num")]
|
|
|
|
|
|
|
|
# des bouquins
|
|
|
|
for book in self.document.getElementsByTagName('book'):
|
2012-04-29 13:03:57 +00:00
|
|
|
self.add_book({"nom" : book.getAttribute("nom") ,"auth" : book.getAttribute("auth") ,"isbn" : book.getAttribute("isbn") ,"pg": book.getAttribute("pg")})
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.commentaire = self.document.getElementsByTagName('commentaire')[0].childNodes[0].nodeValue
|
|
|
|
except:
|
|
|
|
self.commentaire = ""
|
2012-03-09 21:39:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
# -------------------- Création et ajout d'information sur d'un développement
|
|
|
|
|
|
|
|
def from_scratch(self, nom = "???"):
|
|
|
|
""" Créé le développement depuis rien
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
|
|
|
- `nom` : nom du developpement
|
|
|
|
"""
|
|
|
|
self.nom = nom
|
|
|
|
|
|
|
|
self.document=md.Document()
|
|
|
|
racine = self.document.createElement("dev")
|
|
|
|
racine.setAttribute("nom", nom)
|
|
|
|
self.document.appendChild(racine)
|
|
|
|
|
|
|
|
# print(self.document.toprettyxml())
|
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
def add_book(self, book = {"nom" : "", "auth" : "", "isbn" : "", "pg" : ""} ):
|
2012-03-09 21:39:12 +00:00
|
|
|
""" Ajoute un bouquin en relation avec ce developpement
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
2012-04-29 13:03:57 +00:00
|
|
|
- `book`: sous la forme suivante {"nom" : "", "auth" : "", "isbn" : "", "pg" : ""}
|
2012-03-09 21:39:12 +00:00
|
|
|
"""
|
|
|
|
self.book += [book]
|
|
|
|
|
|
|
|
element = self.document.createElement("book")
|
2012-04-29 13:03:57 +00:00
|
|
|
element.setAttribute("nom", book["nom"])
|
|
|
|
element.setAttribute("auth", book["auth"])
|
|
|
|
element.setAttribute("isbn", book["isbn"])
|
|
|
|
element.setAttribute("pg", book["pg"])
|
2012-03-09 21:39:12 +00:00
|
|
|
|
|
|
|
racine = self.document.getElementsByTagName('dev')[0]
|
|
|
|
racine.appendChild(element)
|
|
|
|
|
|
|
|
# print(self.document.toprettyxml())
|
|
|
|
|
|
|
|
def add_lecon(self, lecon = 0):
|
|
|
|
""" Ajoute une lecon où apparait ce developpement
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
|
|
|
- `lecon`: le numero de la lecon
|
|
|
|
"""
|
|
|
|
self.lecon += [lecon]
|
|
|
|
|
|
|
|
element = self.document.createElement("lecon")
|
|
|
|
element.setAttribute("num", str(lecon))
|
|
|
|
|
|
|
|
racine = self.document.getElementsByTagName('dev')[0]
|
|
|
|
racine.appendChild(element)
|
|
|
|
|
|
|
|
# print(self.document.toprettyxml())
|
|
|
|
|
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
|
|
|
|
def add_comment(self, comment):
|
|
|
|
""" Ajoute un commentaire
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
|
|
|
- `comment`: le commentaire
|
|
|
|
"""
|
|
|
|
self.commentaire = comment
|
|
|
|
|
|
|
|
element = self.document.createElement("commentaire")
|
|
|
|
com = self.document.createTextNode(comment)
|
|
|
|
element.appendChild(com)
|
|
|
|
|
|
|
|
racine = self.document.getElementsByTagName('dev')[0]
|
|
|
|
racine.appendChild(element)
|
|
|
|
|
|
|
|
# print(self.document.toprettyxml())
|
|
|
|
|
|
|
|
|
2012-03-09 21:39:12 +00:00
|
|
|
# -------------------- Concernant le Prompt
|
|
|
|
|
|
|
|
def from_prompt(self):
|
|
|
|
""" Créé le développement depuis le prompt
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
"""
|
|
|
|
print("\n ---------- Nouveau développement ---------- ")
|
|
|
|
|
|
|
|
|
|
|
|
# On crée l'objet
|
|
|
|
d = Dev()
|
|
|
|
|
|
|
|
# Nom du developpement
|
|
|
|
self.prompt_desc_dev()
|
|
|
|
|
|
|
|
bo = 1
|
|
|
|
while bo:
|
|
|
|
self.prompt_add_book()
|
|
|
|
|
|
|
|
print("Un autre bouquin? (vide pour non, n'importe quoi pour oui!)")
|
|
|
|
bo = input()
|
|
|
|
|
|
|
|
self.prompt_add_lecon()
|
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
self.prompt_add_comment()
|
|
|
|
|
2012-03-09 21:39:12 +00:00
|
|
|
print("\n ---------- Voila fini! ----------\n ")
|
|
|
|
|
|
|
|
|
|
|
|
def prompt_desc_dev(self):
|
|
|
|
""" Pour demander la description du developpement
|
|
|
|
"""
|
|
|
|
print("Nom du developpement?")
|
|
|
|
nom = input()
|
|
|
|
self.from_scratch(nom)
|
|
|
|
|
|
|
|
|
|
|
|
def prompt_add_lecon(self):
|
|
|
|
""" Prompt pour demander la liste des leçons correspondantes
|
|
|
|
"""
|
|
|
|
print("\n ---------- Ajout de la liste des developpement ---------- ")
|
|
|
|
print("Liste des leçons liées? (séparé par un espace)")
|
|
|
|
list_lecons = input().split(" ")
|
|
|
|
|
|
|
|
for l in list_lecons:
|
|
|
|
self.add_lecon(l)
|
|
|
|
|
|
|
|
|
|
|
|
def prompt_add_book(self):
|
|
|
|
""" Prompt pour demander les infos sur un bouquin
|
|
|
|
"""
|
|
|
|
print("\n ---------- Ajout d'un bouquin ---------- ")
|
|
|
|
|
|
|
|
print("Nom du bouquin")
|
|
|
|
nom = input()
|
|
|
|
print("Autheur (tous on va pas s'embeter)")
|
|
|
|
auth = input()
|
|
|
|
print("Réference")
|
|
|
|
ref = input()
|
|
|
|
print("page")
|
|
|
|
pg = input()
|
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
self.add_book({"nom" : nom , "auth" : auth ,"isbn" : ref , "pg" : pg})
|
2012-03-09 21:39:12 +00:00
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
def prompt_add_comment(self):
|
|
|
|
"""Prompt pour ajouter un commentaire"""
|
|
|
|
print("\n ---------- Ajout d'un commentaire ---------- \n Attention il vaut mieux ne pas faire entrer... ")
|
|
|
|
comment = input()
|
|
|
|
|
|
|
|
self.add_comment(comment)
|
2012-03-09 21:39:12 +00:00
|
|
|
|
|
|
|
# -------------------- Affichage
|
|
|
|
|
|
|
|
def print_info(self):
|
|
|
|
""" Affiche les infos sur le dev
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
|
|
|
"""
|
|
|
|
print(" \n ---------- Informations sur :{nom} ".format(nom = self.nom))
|
2012-04-29 13:03:57 +00:00
|
|
|
if self.connu:
|
|
|
|
print("Ce développement est sensé être connu!")
|
|
|
|
|
2012-03-09 21:39:12 +00:00
|
|
|
print(" --- Leçons --- ")
|
|
|
|
for l in self.lecon:
|
|
|
|
lec = lecon.Lecon()
|
|
|
|
lec.from_scratch(l)
|
|
|
|
lec.print_nom()
|
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
print(" --- Bouquins --- ")
|
|
|
|
for b in self.book:
|
|
|
|
print("{nom} -- {aut} -- {isbn} p{pg}".format(nom = b["nom"] , aut = b["auth"] , isbn = b["isbn"] , pg = b["pg"]))
|
2012-03-09 21:39:12 +00:00
|
|
|
|
2012-04-29 13:03:57 +00:00
|
|
|
print(" --- Commentaire --- ")
|
|
|
|
print(self.commentaire)
|
2012-03-09 21:39:12 +00:00
|
|
|
|
|
|
|
# -------------------- Sauvegarde
|
|
|
|
|
|
|
|
def sauve(self, folder = ""):
|
|
|
|
""" Sauve le developpement à l'endroit indiqué
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
- `self`:
|
|
|
|
- `folder`: là où on veut l'enregistrer (et oui pas le choix du nom!!)
|
|
|
|
"""
|
|
|
|
destination = folder + self.nom.replace(" ", "_") + ".agregDev"
|
|
|
|
|
|
|
|
fichier = open(destination, 'w')
|
|
|
|
fichier.write(self.document.toprettyxml())
|
|
|
|
fichier.close()
|
|
|
|
print("Le développement à été sauvé dans \"", destination, "\" voila son contenu")
|
|
|
|
print(self.document.toprettyxml())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# dev = Dev()
|
|
|
|
# dev.from_file("/media/documents/Cours/Agreg/developpement/mes_dev/Lp_Banach")
|
|
|
|
# # dev.from_scratch("j'aime les maths et les carottes rappées")
|
|
|
|
# dev.add_book(("pipo", "popi", "chipo", "pouet"))
|
|
|
|
# dev.add_book(("pipoi", "popii", "chipoi", "poueti"))
|
|
|
|
# dev.add_lecon("123")
|
|
|
|
# dev.add_lecon("128")
|
|
|
|
# dev.add_lecon("122")
|
|
|
|
# dev.sauve()
|
|
|
|
|
|
|
|
|
|
|
|
# Pour analyser les options qu'on lui demande
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
|
|
|
|
# options proposée
|
|
|
|
parser.add_option("-n","--new",action="store_true",dest="new", help='Pour créer un nouveau développement')
|
|
|
|
#parser.add_option("-o","--output",action="store",type="string",dest="outputFilename")
|
|
|
|
|
|
|
|
# Digestion
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if options.new:
|
|
|
|
dev = Dev()
|
|
|
|
dev.from_prompt()
|
|
|
|
dev.sauve(config.lieu_dev)
|