issue89:command_conquer
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue89:command_conquer [2015/02/07 11:03] – [3] fredphil91 | issue89:command_conquer [2015/02/08 11:55] (Version actuelle) – [8] auntiee | ||
---|---|---|---|
Ligne 10: | Ligne 10: | ||
• pdfjam – in pdfjam package in Ubuntu, or textlive-extra-utils.** | • pdfjam – in pdfjam package in Ubuntu, or textlive-extra-utils.** | ||
- | Tout début septembre, j'ai reçu un courriel d'un lecteur de longue date, avec qui j' | + | Tout début septembre, j'ai reçu un courriel d'un lecteur de longue date, avec qui j' |
- | Les exigences | + | Les exigences |
- | • grep - dans le paquet grep (devrait être pré-installé dans Ubuntu) | + | • grep - dans le paquet grep (devrait être pré-installé dans Ubuntu) |
- | • pdfinfo - dans poppler-utils (devrait être pré-installé dans Ubuntu) | + | • pdfinfo - dans poppler-utils (devrait être pré-installé dans Ubuntu) |
- | • pdfunite - dans poppler-utils (devrait être pré-installé dans Ubuntu) | + | • pdfunite - dans poppler-utils (devrait être pré-installé dans Ubuntu) |
- | • pdftotext - dans poppler-utils (devrait être pré-installé dans Ubuntu) | + | • pdftotext - dans poppler-utils (devrait être pré-installé dans Ubuntu) |
• pdfjam - dans le paquet pdfjam dans Ubuntu ou textlive-extra-utils. | • pdfjam - dans le paquet pdfjam dans Ubuntu ou textlive-extra-utils. | ||
Ligne 37: | Ligne 37: | ||
Le script | Le script | ||
- | La version la plus récente du script est ici : http:// | + | La version la plus récente du script est ici : http:// |
Si vous ne voulez pas préciser un chemin d' | Si vous ne voulez pas préciser un chemin d' | ||
Ligne 70: | Ligne 70: | ||
Comment l' | Comment l' | ||
- | • Installer | + | • Installer |
• Rendre le script exécutable : | • Rendre le script exécutable : | ||
Ligne 76: | Ligne 76: | ||
Assurez-vous d' | Assurez-vous d' | ||
- | • Exécuter | + | • Exécutez |
- | - sans arguments pour voir les informations d' | + | - sans arguments pour voir les informations d' |
- | - exécutez la commande en adaptant à votre usage - par exemple : | + | - exécutez la commande en adaptant à votre usage, par exemple : |
/ | / | ||
Ligne 98: | Ligne 98: | ||
If you open the script up in your favourite text editor, you'll notice that it's formatted nicely with indentations, | If you open the script up in your favourite text editor, you'll notice that it's formatted nicely with indentations, | ||
+ | |||
+ | Cet exemple cherche « Command & Conquer » (sans tenir compte des majuscules et minuscules) dans tous les fichiers PDF dont le nom commence par « numero », et se termine par « .pdf » (ce qui doit couvrir tous les numéros du FCM, à moins que vous ne les renommiez). Ainsi, vous vous retrouverez avec un fichier PDF contenant tous les articles de C & C des numéros que vous avez téléchargés. | ||
+ | |||
+ | Naturellement, | ||
+ | |||
+ | Comment çela fonctionne-t-il ? | ||
+ | |||
+ | Si vous ouvrez le script dans votre éditeur de texte favori, vous remarquerez qu'il est joliment formaté avec indentations, | ||
====== 5 ====== | ====== 5 ====== | ||
Ligne 106: | Ligne 114: | ||
Lines 29-30 uses the trap command to empty the temporary folder when the script exits (including when the script is interrupted by the user or system – i.e. when you hit ctrl+c).** | Lines 29-30 uses the trap command to empty the temporary folder when the script exits (including when the script is interrupted by the user or system – i.e. when you hit ctrl+c).** | ||
+ | |||
+ | Les lignes 9 à 25 contiennent une instruction if qui vérifie s'il y a des arguments, sinon, elle affiche les informations d' | ||
+ | |||
+ | Les lignes 27-28 créent un emplacement temporaire pour stocker les fichiers PDF pendant qu'ils sont en cours de traitement par le script (car on convertit le fichier PDF avec pdftotext pour utiliser grep sur les textes). C'est une pratique acceptée pour garder propres les résultats du script (c' | ||
+ | |||
+ | Les lignes 29-30 utilisent la commande trap pour vider le dossier temporaire lorsque le script se termine (y compris lorsque le script est interrompu par l' | ||
====== 6 ====== | ====== 6 ====== | ||
Ligne 112: | Ligne 126: | ||
Lines 46 – 54 is a for loop that checks the passed arguments for any beginning with a hyphen – as it is assumed it indicates an argument. If I were the one authoring this script, I would have opted for an array of acceptable options, and searched for them instead. If your filename starts with a hyphen, I would imagine the script would fail. However, it is pretty uncommon for a file to be named in such a way.** | Lines 46 – 54 is a for loop that checks the passed arguments for any beginning with a hyphen – as it is assumed it indicates an argument. If I were the one authoring this script, I would have opted for an array of acceptable options, and searched for them instead. If your filename starts with a hyphen, I would imagine the script would fail. However, it is pretty uncommon for a file to be named in such a way.** | ||
+ | |||
+ | Les lignes 31 à 44 sont une boucle while qui demande à l' | ||
+ | |||
+ | Les lignes 46 à 54 sont une boucle for qui vérifie si les arguments passés commencent avec un tiret, car ils sont supposés indiquer un argument. Si j' | ||
====== 7 ====== | ====== 7 ====== | ||
Ligne 118: | Ligne 136: | ||
Lines 96-101 check if the number of matched PDF files exists. If not, there were no matches, and the program exits.** | Lines 96-101 check if the number of matched PDF files exists. If not, there were no matches, and the program exits.** | ||
+ | |||
+ | Les lignes 56 à 93 sont une boucle for qui sert à inverser la vérification des lignes 46 à 54 (des arguments qui ne commencent pas par un tiret), et suppose que c'est un nom de fichier. Il commence alors une nouvelle ligne, affiche « pages correspondantes dans <nom de fichier> : <liste des pages> ». Au final, vous devriez avoir une liste de tous les fichiers PDF recherchés, | ||
+ | |||
+ | Les lignes 96 à 101 vérifient si le nombre de fichiers PDF correspondant à la recherche existe. Sinon, il n'y avait aucun résultat, et le programme se termine. | ||
====== 8 ====== | ====== 8 ====== | ||
Ligne 126: | Ligne 148: | ||
I've skimmed over certain specifics of the script for two reasons – one being brevity, and the other being that figuring out exactly how a script works simply by reading it and running it is a good skill to have, especially if you plan on writing your own scripts or programs. If anyone has particular questions about a certain segment of the script, you're welcome to send me a quick email. If you have any other questions, suggestions, | I've skimmed over certain specifics of the script for two reasons – one being brevity, and the other being that figuring out exactly how a script works simply by reading it and running it is a good skill to have, especially if you plan on writing your own scripts or programs. If anyone has particular questions about a certain segment of the script, you're welcome to send me a quick email. If you have any other questions, suggestions, | ||
+ | |||
+ | Les lignes 102 à 112 couvrent le cas d'un fichier correspondant (et affichent « 1 fichier PDF correspondant », puis déplace le fichier temporaire dans le PDF final contenant les résultats, ce qui évite des problèmes avec pdfunite qui attendrait plus d'un fichier), ainsi que les correspondances multiples. Lorsque plusieurs fichiers PDF correspondants existent, il utilisera pdfunite pour fusionner les fichiers dans le pdf -matches. | ||
+ | |||
+ | La ligne 113 - Cette ligne affiche simplement le nom du fichier résultant, pour que l' | ||
+ | |||
+ | Je ne me suis pas étendu sur certaines spécificités du script pour deux raisons : l'une étant la concision et l' | ||
issue89/command_conquer.1423303397.txt.gz · Dernière modification : 2015/02/07 11:03 de fredphil91