Skip to content

Commit 0c13e7a

Browse files
authored
Api chapter (#13)
* wip: plan for API * wip: Set up annexes for later * fix: workaround for big longs lines * wip: add too much ORM details in chapter 5 may be space killer * wip: set up this part * wip: add env variable def * wip: two implementation details explained fast * wip: middelwares * wip: add ref for states * wip: add ref * wip: hardest part (WIP) * wip: backup * wip: first proposal * wip: correction orthographique * wip: change listings things
1 parent 4634a09 commit 0c13e7a

File tree

17 files changed

+374
-31
lines changed

17 files changed

+374
-31
lines changed

codes/crawler.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env node
2+
const path = require('path');
3+
const {promises: fs, readFileSync} = require("fs");
4+
const PATH_FOR_STRATEGY = path.resolve(__dirname, "..", "./strategies");
5+
const DEBUG_FILE = path.resolve("./results.json");
6+
7+
exports = module.exports = {
8+
"command": "crawler",
9+
"describe": "export metadata from your exercises to Source Code",
10+
"builder": function (y) {
11+
return y
12+
.option("strategy", {
13+
alias: "s",
14+
type: "string",
15+
description: "Name of the already implemented strategy you want to use",
16+
choices: ["inginious-git"]
17+
})
18+
.option("custom_strategy", {
19+
alias: "cs",
20+
type: "string",
21+
conflicts: "strategy",
22+
description: "Absolute path to a JS file implementing your strategy (see docs for more info)"
23+
})
24+
.option("workingDirectory", {
25+
alias: "w",
26+
type: "string",
27+
description: "Absolute path to a folder where the crawler can do its stuff",
28+
demandOption: true
29+
})
30+
.option("resultFile", {
31+
alias: "out",
32+
type: "string",
33+
description: "Absolute path to a JSON file the crawler could write its results",
34+
default: DEBUG_FILE
35+
})
36+
.coerce("workingDirectory", (arg) => {
37+
return path.resolve(arg);
38+
})
39+
.config("settings", "Absolute path to a JSON config file for strategy + crawler", (configPath) => {
40+
return JSON.parse(readFileSync(path.resolve(configPath), 'utf-8'));
41+
})
42+
.help()
43+
.argv;
44+
},
45+
"handler": function (argv) {
46+
fs
47+
.mkdir(argv.workingDirectory, {recursive: true})
48+
.then(() => fetch_and_save_results(argv))
49+
.catch((err) => {
50+
console.error(err);
51+
});
52+
}
53+
};
54+
55+
async function fetch_and_save_results(argv) {
56+
// If custom script, invoke this to get results
57+
try {
58+
const results =
59+
(argv.hasOwnProperty("custom_strategy"))
60+
? await require(argv.custom_strategy)(argv)
61+
: await require(path.resolve(PATH_FOR_STRATEGY, argv.strategy))(argv);
62+
63+
await fs.writeFile(argv.resultFile, JSON.stringify(results, null, 4));
64+
console.log("SUCCESSFULLY SAVED THE RESULTS");
65+
return await Promise.resolve(results)
66+
} catch (e) {
67+
return await Promise.reject(e);
68+
}
69+
}

codes/mainCLI.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
3+
require('yargs')
4+
.command(require('./commands/crawler'))
5+
.command(require('./commands/uploader'))
6+
.command(require("./commands/archiver"))
7+
.command(require("./commands/validator"))
8+
.help()
9+
.argv;

codes/searchAPI.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Extracted from models/Exercises (it should be renamed to "Fiche" one day)
2+
// The interesting method is tagsConditionsBuilder
3+
const Sequelize = require("sequelize");
4+
const Op = Sequelize.Op;
5+
6+
const simpleCase = (array, mustBePresent) => {
7+
// positive tags : 2 OR 3 OR 4 , etc...
8+
// negative tags : NOT 2 OR NOT 3 , etc...
9+
return Sequelize.where(
10+
// for negative check, we should use contains instead
11+
// For example (using the examples above) :
12+
// For positive check : tags_ids && [2,3,4]
13+
// For negative check : tags_ids @> [2,3]
14+
Sequelize.where(
15+
Sequelize.col("tags_ids"),
16+
(mustBePresent) ? Op.overlap : Op.contains,
17+
array
18+
),
19+
Op.is,
20+
mustBePresent
21+
)
22+
};
23+
24+
const tagsWhereBuilder = {
25+
"simpleCase": simpleCase,
26+
"complexCase": (must_have, must_not) => ({
27+
[Op.or]: [
28+
simpleCase(must_have, true),
29+
simpleCase(must_not, false),
30+
]
31+
})
32+
};
33+
34+
// tag condition builder
35+
function tagsConditionsBuilder(tags) {
36+
37+
const conditions = tags.map(tagOrTags => {
38+
39+
// filter negative/positive integer(s) into array ( more efficient to check that way )
40+
const must_have = Array.isArray(tagOrTags)
41+
? tagOrTags.filter(tag => tag >= 0)
42+
: tagOrTags >= 0
43+
? [tagOrTags]
44+
: [];
45+
const must_not = Array.isArray(tagOrTags)
46+
? tagOrTags.filter(tag => !(tag >= 0)).map(tag => -tag)
47+
: tagOrTags >= 0
48+
? []
49+
: [-tagOrTags];
50+
51+
// multiple case can occur because of the mixin of must_have / must_not checks
52+
// One is these case is mandatory true
53+
const kind = (must_not.length > 0 && must_have.length > 0) ? "complexCase" : "simpleCase";
54+
55+
// in simple case, it's straightforward
56+
if (kind === "simpleCase") {
57+
return tagsWhereBuilder[kind](
58+
(must_have.length > 0) ? must_have : must_not,
59+
// simplification : if must_have is not empty, mustOverlap will be true , otherwise false (must_not)
60+
must_have.length > 0
61+
)
62+
} else {
63+
// the most horrible case
64+
return tagsWhereBuilder[kind](must_have, must_not)
65+
}
66+
67+
});
68+
69+
// as the expression is in Conjunctive Normal Form, we know we can combine AND and OR formulas
70+
return {
71+
[Op.and]: conditions
72+
};
73+
}

commonPreamble.sty

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
\usepackage[dvipsnames]{xcolor}
132132

133133
% Pour les maudits accents dans listings, vaut mieux prévenir que guérir
134+
% Aussi gérer les lignes trop longues
134135
\lstset{%
135136
inputencoding=utf8,
136137
extendedchars=true,
@@ -176,7 +177,11 @@ literate=%
176177
backgroundcolor=\color{white},
177178
basicstyle=\ttfamily,
178179
breakatwhitespace=false,
179-
breaklines=false,
180+
% To deal with too long lines
181+
% https://tex.stackexchange.com/questions/116534/lstlisting-line-wrapping
182+
breaklines=true,
183+
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
184+
% in the original JSES6Base, it was breaklines=false
180185
captionpos=b,
181186
columns=fullflexible,
182187
commentstyle=\color{mediumgray}\upshape,
@@ -263,6 +268,10 @@ literate=%
263268
%\setcounter{tocdepth}{#1}%
264269
}
265270

271+
% Pour renommer les listings
272+
\renewcommand\lstlistlistingname{Table des extraits de code}
273+
\renewcommand{\lstlistingname}{Code} % Listing->Code
274+
266275
% Pour être sur que ces footnotes soient bien en bottom de page
267276
\usepackage[bottom]{footmisc}
268277

glossary.tex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
{
148148
name={Middleware},
149149
text={middleware},
150-
plural={middleware},
150+
plural={middlewares},
151151
description={
152152
Terme générique pour désigner tout logiciel permettant de mettre en relation plusieurs applications.
153153
Ce terme existe également sous une version francisée : le "logiciel médiateur".
@@ -162,4 +162,14 @@
162162
description={
163163
Ce terme désigne, comme expliqué par Wikipédia\cite{libraryDef}, "une collection de fonctions utilitaires prêtes à être utilisées par des programmes".
164164
}
165+
}
166+
167+
\newglossaryentry{envvar}
168+
{
169+
name={Variable d'environnement},
170+
text={variable d'environnement},
171+
plural={variables d'environnement},
172+
description={
173+
Ce terme désigne, comme expliqué par Wikipédia\cite{envvarDef}, "une variables dynamique utilisée par les différents processus d’un système d’exploitation".
174+
}
165175
}

images/serveur/doc_example.PNG

113 KB
Loading
82.3 KB
Loading

images/serveur/tree_folders.png

29.6 KB
Loading

memory.bib

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ @online{
4343
url= {https://fr.wikipedia.org/wiki/Biblioth%C3%A8que_logicielle}
4444
}
4545

46+
@online{
47+
envvarDef,
48+
title = "Variable d'environnement",
49+
author = {Wikipedia},
50+
url= {https://fr.wikipedia.org/wiki/Variable_d%27environnement}
51+
}
52+
4653
@online{
4754
MoSCoW,
4855
title = "Méthode MoSCoW",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\chapter{Analyse Bibliographique}
2+
\label{annexe:AnalyseBiblio}
3+
4+
TODO includegraphics pdf

0 commit comments

Comments
 (0)