From 945aa8c36d0a8409f3e5f6d495544bf554884b7f Mon Sep 17 00:00:00 2001 From: Thomas Maurice Date: Sat, 23 Jan 2016 17:40:57 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajoute=20le=20support=20du=20fichier=20Rece?= =?UTF-8?q?tte=C3=80Marcel=20en=20bon=20fran=C3=A7ais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "examples/Recette\303\200Marcel" | 10 +++++++++ marcel.py | 38 +++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 "examples/Recette\303\200Marcel" diff --git "a/examples/Recette\303\200Marcel" "b/examples/Recette\303\200Marcel" new file mode 100644 index 0000000..7469f42 --- /dev/null +++ "b/examples/Recette\303\200Marcel" @@ -0,0 +1,10 @@ +# This is an example RecetteÀMarcel file +DEPUIS debian:latest +CRÉATEUR Thomas Maurice + +LANCE apt-get update && apt-get upgrade -y +LANCE useradd manuel + +UTILISATEUR manuel + +ORDRE echo "La baguette hon hon hon" diff --git a/marcel.py b/marcel.py index d468895..b55cdd1 100755 --- a/marcel.py +++ b/marcel.py @@ -8,6 +8,7 @@ import subprocess import sys +import re from os.path import exists, join, dirname @@ -47,6 +48,39 @@ u'--etat-d-urgence': '--privileged' } +MARCELFILE_TRANSLATIONS = { + u'DEPUIS': u'FROM', + u'CRÉATEUR': u'MAINTAINER', + u'LANCE': u'RUN', + u'ORDRE': u'CMD', + u'ÉTIQUETTE': u'LABEL', + u'DÉSIGNER': u'EXPOSE', + u'EELV': u'ENV', + u'AJOUTER': u'ADD', + u'COPIER': u'COPY', + u'POINT D\'ENTRÉE': u'ENTRYPOINT', + u'UTILISATEUR': u'USER', +} + +def translate_marcefile(input_file, output_file): + u""" + Converts a RecetteÀMarcelle to a Dockerfile + + :param input_file: Input filename + :param output_file: Output filename + :return: The translated Dockerfile as a string + """ + with open(input_file, 'rb') as f: + marcel_file = f.read().decode('utf-8') + for key in MARCELFILE_TRANSLATIONS: + expression = re.compile(ur'(^|\n)%s' % key, re.UNICODE) + marcel_file = expression.sub(ur"\1%s" % MARCELFILE_TRANSLATIONS[key], marcel_file) + + with open(output_file, 'w') as output: + output.write(marcel_file.encode('utf-8')) + + return marcel_file + def check_for_marcefile(command): u""" @@ -57,7 +91,9 @@ def check_for_marcefile(command): if exists(join(dirname(__file__), u'RecetteÀMarcel')): # Check if a "-f" argument was not already given if '-f' not in command: - command = command[:2] + ['-f', u'./RecetteÀMarcel'] + command[2:] + # We want to generate a file with the propre Dockerfile format + translate_marcefile(u'RecetteÀMarcel', u'.RecetteÀMarcel.Dockerfile') + command = command[:2] + ['-f', u'./.RecetteÀMarcel.Dockerfile'] + command[2:] return command From 2f041ba64801c5ae5757421ce0f8563d8361e606 Mon Sep 17 00:00:00 2001 From: Thomas Maurice Date: Sat, 23 Jan 2016 19:08:35 +0100 Subject: [PATCH 2/2] Post review fixes --- marcel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/marcel.py b/marcel.py index b55cdd1..794a893 100755 --- a/marcel.py +++ b/marcel.py @@ -62,7 +62,7 @@ u'UTILISATEUR': u'USER', } -def translate_marcefile(input_file, output_file): +def translated_marcelfile(input_file, output_file): u""" Converts a RecetteÀMarcelle to a Dockerfile @@ -92,7 +92,7 @@ def check_for_marcefile(command): # Check if a "-f" argument was not already given if '-f' not in command: # We want to generate a file with the propre Dockerfile format - translate_marcefile(u'RecetteÀMarcel', u'.RecetteÀMarcel.Dockerfile') + translated_marcelfile(u'RecetteÀMarcel', u'.RecetteÀMarcel.Dockerfile') command = command[:2] + ['-f', u'./.RecetteÀMarcel.Dockerfile'] + command[2:] return command