issue184:tutoriel1
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue184:tutoriel1 [2022/08/28 15:12] – créée auntiee | issue184:tutoriel1 [2022/08/30 19:19] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | + | **Greg's regular Python series will be back next month. | |
- | Greg's regular Python series will be back next month. | + | |
Ligne 9: | Ligne 8: | ||
And, following that piece of wizardry, another clever person wrapped bash2py up into a Docker image for ease of use (https:// | And, following that piece of wizardry, another clever person wrapped bash2py up into a Docker image for ease of use (https:// | ||
- | Keen to see if it worked, I thought I would try bash2py with a simple script – as we'll see in a moment. At this stage, it's definitely worth pointing out that you will get mixed results with tools like this one. The author of bash2py states that it is intended to only "do the lion share of the translation effort" | + | Keen to see if it worked, I thought I would try bash2py with a simple script – as we'll see in a moment. At this stage, it's definitely worth pointing out that you will get mixed results with tools like this one. The author of bash2py states that it is intended to only "do the lion share of the translation effort" |
+ | |||
+ | La série régulière de Greg sur Python sera de retour le mois prochain. | ||
+ | |||
+ | Si vous êtes un peu comme moi, après quelques années d' | ||
+ | |||
+ | Récemment, j'ai été agréablement surpris de découvrir que quelqu' | ||
+ | |||
+ | Et, à la suite de ce tour de passe-passe, | ||
+ | |||
+ | Désireux de voir si cela fonctionnait, | ||
- | That said, for relatively simple jobs, like a Lambda function in AWS for example, this tool should be able to give you the building blocks in Python that could be further developed upon. | + | **That said, for relatively simple jobs, like a Lambda function in AWS for example, this tool should be able to give you the building blocks in Python that could be further developed upon. |
Simple Bash Script | Simple Bash Script | ||
Ligne 31: | Ligne 41: | ||
5 | 5 | ||
- | I can see the script, counting to five, so we’re all set. | + | I can see the script, counting to five, so we’re all set.** |
- | Resulting Python Script | + | Cela dit, pour des tâches relativement simples, comme une fonction Lambda dans AWS par exemple, cet outil devrait être en mesure de vous fournir des blocs de construction en Python qui pourraient être développés plus avant. |
+ | |||
+ | Simple script Bash | ||
+ | |||
+ | Voici un script simple que j'ai écrit afin de tester le convertisseur. Son but est d' | ||
+ | |||
+ | J'ai enregistré le script Bash dans un fichier appelé « bash.sh ». Nous allons le sauvegarder à nouveau dans un moment, alors restez à l' | ||
+ | |||
+ | chmod +x bash.sh | ||
+ | |||
+ | ./bash.sh | ||
+ | |||
+ | Je suis un script Bash et je peux compter... | ||
+ | |||
+ | 1 | ||
+ | 2 | ||
+ | 3 | ||
+ | 4 | ||
+ | 5 | ||
+ | |||
+ | Je peux voir le script comptant jusqu' | ||
+ | |||
+ | |||
+ | **Resulting Python Script | ||
Now that we have a simple Bash script, let's see what bash2py makes of it. We will use the Docker image approach. With Docker already installed, the command to use is this: | Now that we have a simple Bash script, let's see what bash2py makes of it. We will use the Docker image approach. With Docker already installed, the command to use is this: | ||
Ligne 49: | Ligne 82: | ||
Let’s see bash2py in action by entering the container after asking Docker to run it: | Let’s see bash2py in action by entering the container after asking Docker to run it: | ||
+ | |||
+ | docker run -ti imiell/ | ||
+ | |||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | Script Python résultant | ||
+ | |||
+ | Maintenant que nous avons un simple script Bash, voyons ce que bash2py en fait. Nous allons utiliser l' | ||
+ | |||
+ | docker pull imiell/ | ||
+ | |||
+ | Ensuite, nous pouvons vérifier la taille de cette image, avec cette commande : | ||
+ | |||
+ | docker images | ||
+ | |||
+ | REPOSITORY TAG IMAGE ID CREATED SIZE | ||
+ | imiell/ | ||
+ | |||
+ | Comme nous pouvons le voir, environ un demi Go d' | ||
+ | |||
+ | Voyons bash2py en action en entrant dans le conteneur après avoir demandé à Docker de l' | ||
docker run -ti imiell/ | docker run -ti imiell/ | ||
Ligne 54: | Ligne 108: | ||
root@8c3fa65fce45:/ | root@8c3fa65fce45:/ | ||
- | As we can see from the command prompt, we’re inside the container and can execute commands relating to bash2py. Next, we’re going to use the “vi” text editor inside the container and paste the “bash.sh” script into a file of the same name on the container’s filesystem, with this command: | + | |
+ | **As we can see from the command prompt, we’re inside the container and can execute commands relating to bash2py. Next, we’re going to use the “vi” text editor inside the container and paste the “bash.sh” script into a file of the same name on the container’s filesystem, with this command: | ||
root@8c3fa65fce45:/ | root@8c3fa65fce45:/ | ||
Ligne 69: | Ligne 124: | ||
Let’s finally test bash2py with this command: | Let’s finally test bash2py with this command: | ||
+ | |||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | Comme nous pouvons le voir dans l' | ||
+ | |||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | Sauvegardez ce fichier dans le conteneur en quittant « vi ». | ||
+ | |||
+ | Maintenant, exécutez-le, | ||
+ | |||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | Super, le résultat est le même qu' | ||
+ | |||
+ | Testons enfin bash2py avec cette commande : | ||
root@8c3fa65fce45:/ | root@8c3fa65fce45:/ | ||
- | The command completes without any output. If you do an “ls” command, you will see that a new file has been created inside the container’s directory called “bash.sh.py”, | + | |
+ | **The command completes without any output. If you do an “ls” command, you will see that a new file has been created inside the container’s directory called “bash.sh.py”, | ||
ls | ls | ||
Ligne 83: | Ligne 157: | ||
I am a Bash script and I can count... | I am a Bash script and I can count... | ||
+ | |||
+ | 1 | ||
+ | 2 | ||
+ | 3 | ||
+ | 4 | ||
+ | 5 | ||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | La commande se termine sans aucune sortie. Si vous faites une commande « ls », vous verrez qu'un nouveau fichier a été créé dans le répertoire du conteneur appelé « bash.sh.py », comme suit : | ||
+ | |||
+ | ls | ||
+ | |||
+ | MANIFEST README.txt analyseurs bash-4.3.30 bash.sh bash.sh.py bash2py bash2py.py bin install source_code.txt tests | ||
+ | |||
+ | Si nous utilisons d' | ||
+ | |||
+ | root@8c3fa65fce45:/ | ||
+ | |||
+ | Je suis un script Bash et je peux compter... | ||
1 | 1 | ||
Ligne 91: | Ligne 184: | ||
root@8c3fa65fce45:/ | root@8c3fa65fce45:/ | ||
- | Excellent! We have a working Python script! | + | |
+ | **Excellent! We have a working Python script! | ||
What has bash2py changed in our script? In the listing shown above, you can see the contents of our generated Python script. | What has bash2py changed in our script? In the listing shown above, you can see the contents of our generated Python script. | ||
Ligne 113: | Ligne 207: | ||
5 | 5 | ||
- | As hoped, our simple script runs on my laptop too! Great news. | + | As hoped, our simple script runs on my laptop too! Great news.** |
- | The End | + | Excellent ! Nous avons un script Python qui fonctionne ! |
+ | |||
+ | Qu' | ||
+ | |||
+ | Si vous regardez le programme, la plupart du travail a été fait pour configurer le script afin qu'il s' | ||
+ | |||
+ | La dernière chose à faire est de copier le script en dehors du conteneur et de l' | ||
+ | |||
+ | Je vous rappelle que lorsque vous tapez « CTRL-D » à l' | ||
+ | |||
+ | Avec le script Python copié dans mon presse-papiers, | ||
+ | |||
+ | Delta ~ # python3 counter.py | ||
+ | |||
+ | Je suis un script Bash et je peux compter... | ||
+ | |||
+ | 1 | ||
+ | 2 | ||
+ | 3 | ||
+ | 4 | ||
+ | 5 | ||
+ | |||
+ | Comme prévu, notre script simple fonctionne aussi sur mon ordinateur portable ! Bonne nouvelle. | ||
+ | |||
+ | |||
+ | **The End | ||
Obviously you still need some knowledge about Python if you use tools like this. | Obviously you still need some knowledge about Python if you use tools like this. | ||
Ligne 121: | Ligne 240: | ||
But bash2py could save you some eyestrain and lots of time under certain circumstances. Be warned you may find, especially for more complex operations, that a fair amount of tweaking is required. | But bash2py could save you some eyestrain and lots of time under certain circumstances. Be warned you may find, especially for more complex operations, that a fair amount of tweaking is required. | ||
- | Hopefully, a quick look at this very clever tool has inspired you to try it out for yourself. You never know, it might save the day at some point in the future. | + | Hopefully, a quick look at this very clever tool has inspired you to try it out for yourself. You never know, it might save the day at some point in the future.** |
+ | |||
+ | Fin | ||
+ | |||
+ | Il est évident que vous avez encore besoin de quelques connaissances de Python si vous utilisez des outils comme celui-ci. | ||
+ | |||
+ | Mais bash2py peut vous faire gagner de la fatigue visuelle et beaucoup de temps dans certaines circonstances. Attention, il se peut que vous trouviez, surtout pour les opérations les plus complexes, qu'une certaine quantité d' | ||
+ | |||
+ | Nous espérons qu'un rapide coup d'œil à cet outil très intelligent vous a donné envie de l' | ||
issue184/tutoriel1.1661692346.txt.gz · Dernière modification : 2022/08/28 15:12 de auntiee