forked from LaurentClaessens/mazhe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins_agreg.py
178 lines (156 loc) · 6.51 KB
/
plugins_agreg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf8 -*-
from __future__ import unicode_literals
frido_mark_list=[]
frido_mark_list.append("% SCRIPT MARK -- DECLARATIVE PART")
frido_mark_list.append("% SCRIPT MARK -- GARDE MES NOTES")
frido_mark_list.append("% SCRIPT MARK -- TOC")
frido_mark_list.append("% SCRIPT MARK -- FRIDO")
frido_mark_list.append("% SCRIPT MARK -- FINAL")
outilsmath_mark_list=[]
outilsmath_mark_list.append("% SCRIPT MARK -- DECLARATIVE PART")
outilsmath_mark_list.append("% SCRIPT MARK -- GARDE ENSEIGNEMENT")
outilsmath_mark_list.append("% SCRIPT MARK -- TOC")
outilsmath_mark_list.append("% SCRIPT MARK -- OUTILS MATHÉMATIQUES")
outilsmath_mark_list.append("% SCRIPT MARK -- FINAL")
enseignement_mark_list=[]
enseignement_mark_list.append("% SCRIPT MARK -- DECLARATIVE PART")
enseignement_mark_list.append("% SCRIPT MARK -- GARDE ENSEIGNEMENT")
enseignement_mark_list.append("% SCRIPT MARK -- TOC")
enseignement_mark_list.append("% SCRIPT MARK -- INTRO SAGE")
enseignement_mark_list.append("% SCRIPT MARK -- OUTILS MATHÉMATIQUES")
enseignement_mark_list.append("% SCRIPT MARK -- MATLAB")
enseignement_mark_list.append("% SCRIPT MARK -- EXERCICES")
enseignement_mark_list.append("% SCRIPT MARK -- CdI")
enseignement_mark_list.append("% SCRIPT MARK -- FINAL")
mazhe_mark_list=[]
mazhe_mark_list.append("% SCRIPT MARK -- DECLARATIVE PART")
mazhe_mark_list.append("% SCRIPT MARK -- GARDE MAZHE")
mazhe_mark_list.append("% SCRIPT MARK -- TOC")
mazhe_mark_list.append("% SCRIPT MARK -- ENGLISH INTRODUCTION")
mazhe_mark_list.append("% SCRIPT MARK -- MOODLE")
mazhe_mark_list.append("% SCRIPT MARK -- INTRO SAGE")
mazhe_mark_list.append("% SCRIPT MARK -- FRIDO")
mazhe_mark_list.append("% SCRIPT MARK -- DÉVELOPPEMENTS POSSIBLES")
mazhe_mark_list.append("% SCRIPT MARK -- OUTILS MATHÉMATIQUES")
mazhe_mark_list.append("% SCRIPT MARK -- RESEARCH PART")
mazhe_mark_list.append("% SCRIPT MARK -- MATLAB")
mazhe_mark_list.append("% SCRIPT MARK -- EXERCICES")
mazhe_mark_list.append("% SCRIPT MARK -- CdI")
mazhe_mark_list.append("% SCRIPT MARK -- FINAL")
research_mark_list=[]
research_mark_list.append("% SCRIPT MARK -- DECLARATIVE PART")
research_mark_list.append("% SCRIPT MARK -- GARDE MAZHE")
research_mark_list.append("% SCRIPT MARK -- TOC")
research_mark_list.append("% SCRIPT MARK -- ENGLISH INTRODUCTION")
research_mark_list.append("% SCRIPT MARK -- RESEARCH PART")
research_mark_list.append("% SCRIPT MARK -- FINAL")
class set_filename(object):
def __init__(self,new_output_filename):
self.new_output_filename=new_output_filename
def __call__(self,medicament):
raise DeprecationWarning("Use myRequest.new_output_filename='foo.pdf' instead")
medicament.new_output_filename=self.new_output_filename
# TODO : use a partial object from the module 'functools'
# https://pymotw.com/3/functools/
class set_counter(object):
def __init__(self,counter_name,init_value,final_value):
self.counter_name=counter_name
self.init_value=init_value
self.final_value=final_value
def __call__(self,A):
"""
Changes the line
\setcounter{<counter_name>}{<init_value>}
into
\setcounter{<counter_name>}{<final_value>}
"""
u="\setcounter{{{}}}{{{}}}".format(self.counter_name,self.init_value)
S = A.replace(u,u.replace(str(self.init_value),str(self.final_value)))
return S
class set_boolean(object):
def __init__(self,name,value):
self.name=name
self.value=value
def __call__(self,A):
r"""
Changes the line
\boolfalse{<name>}
into
\booltrue{<name>}
or the contrary
"""
true_line=r"\booltrue{{{}}}".format(self.name)
false_line=r"\boolfalse{{{}}}".format(self.name)
if self.value=="true":
S=A.replace(false_line,true_line)
elif self.value=="false":
S=A.replace(true_line,false_line)
else :
raise ValueError("You have to choose between 'true' of 'false'")
return S
set_isFrido = set_boolean("isFrido","true")
def up_to_text(liste,text):
for i,l in enumerate(liste):
if l.startswith(text):
return i
def is_dirty(repo):
import pygit2
status = repo.status()
print("list done")
for filepath, flags in status.items():
if flags != pygit2.GIT_STATUS_CURRENT:
if flags != 16384:
return True
return False;
def get_hexsha(repo):
commit=repo.revparse_single('HEAD')
return commit.id
def set_commit_hexsha(A):
import pygit2
import os
repo=pygit2.Repository(os.getcwd())
hexsha=str(get_hexsha(repo))
if is_dirty(repo):
hexsha=hexsha+" -- and slightly more"
u="\\newcommand{\GitCommitHexsha}{\info{missing information}}"
print(hexsha)
A = A.replace(u,u.replace("missing information",hexsha))
return A
def assert_MonCerveau_first():
"""
Read the bbl file and check that the reference "MonCerveau" is the first one.
"""
import os.path
filename="Inter_frido-mazhe_pytex.bbl"
if not os.path.exists(filename):
print("Le fichier bbl n'existe pas. C'est pas très normal. Si cela persiste à la prochaine compilation, posez-vous des questions.")
return None
bbl_content=open(filename).read()
bbl_first=bbl_content.find("bibitem")
bbl_second=bbl_content.find("bibitem",bbl_first+1)
text=bbl_content[bbl_first:bbl_second]
if not "MonCerveau" in text:
print("""Il semblerait que la référence bibliographique 'MonCerveau' ne soit pas la première. Il faut corriger ça. En effet, le lecteur doit savoir que lorsqu'il voit la référence [1], ça veut dire 'danger'.
Après modification, le plus simple est de supprimer le fichier {} et de relancer.
""".format(filename))
raise
def split_toc(name,n):
"""
Rewrites the TOC file with adding "(Vol i)" to the chapter name.
With i being the number of the volume in which the chapter should appears.
@param n : the number of volumes
@param name (string) the name of the document we are speaking about
@return : a function which makes the work
The parameter 'name' serves to distinguish 'frido' from 'book' when
creating the pathname of the toc file.
"""
def _split_doc():
import sys
import os
cwd=os.getcwd()
sys.path.append(os.path.join(cwd,"python"))
from splittoc import Book
toc_filename=os.path.join(cwd,"Inter_{}-mazhe_pytex.toc".format(name))
book=Book(toc_filename)
book.rewrite_toc(n)
return _split_doc