Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajoute le support du fichier RecetteÀMarcel en bon français #23

Merged
merged 2 commits into from
Jan 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/RecetteÀMarcel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This is an example RecetteÀMarcel file
DEPUIS debian:latest
CRÉATEUR Thomas Maurice <[email protected]>

LANCE apt-get update && apt-get upgrade -y
LANCE useradd manuel

UTILISATEUR manuel

ORDRE echo "La baguette hon hon hon"
38 changes: 37 additions & 1 deletion marcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import subprocess
import sys
import re

from os.path import exists, join, dirname

Expand Down Expand Up @@ -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',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je t'aime.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keur keur keur <3

u'AJOUTER': u'ADD',
u'COPIER': u'COPY',
u'POINT D\'ENTRÉE': u'ENTRYPOINT',
u'UTILISATEUR': u'USER',
}

def translated_marcelfile(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"""
Expand All @@ -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
translated_marcelfile(u'RecetteÀMarcel', u'.RecetteÀMarcel.Dockerfile')
command = command[:2] + ['-f', u'./.RecetteÀMarcel.Dockerfile'] + command[2:]
return command


Expand Down