diff --git a/README.md b/README.md index 9530478..e8c2682 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,30 @@ -# Weight-cli +usage: weight-cli.py [-h] [-da DATA] [-w WEIGHT] [-t TYPE] [-d DATE] [-i ID] + [-m METRIC] [-c COMMENT] [-o OTHER] [-r] [-rem REMOVE] + [-g] [-tst] [-ur] [-v] -A command line tool to manage your weight. \ No newline at end of file +Un script en ligne de commande pour gérer votre poids. + +optional arguments: + -h, --help show this help message and exit + -da DATA, --data DATA + fichier de données : optionnel + -w WEIGHT, --weight WEIGHT + poids : optionnel + -t TYPE, --type TYPE type : optionnel + -d DATE, --date DATE date : optionnelle + -i ID, --id ID identifiant : optionnel + -m METRIC, --metric METRIC + métrique : optionnelle + -c COMMENT, --comment COMMENT + commentaire : optionnel + -o OTHER, --other OTHER + autre : optionnel + -r, --read optional read measures + -rem REMOVE, --remove REMOVE + suppression d'une mesure par son numéro dans la liste + : optionnel + -g, --graph trace le graphe : optionnel + -tst, --tests optional tests operations + -ur, --undoremove annule la suppression de la dernière ligne effacée : + optionnel + -v, --version show program's version number and exit diff --git a/locale/base.pot b/locale/base.pot new file mode 100644 index 0000000..27c92eb --- /dev/null +++ b/locale/base.pot @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-21 14:19+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: weight-cli.py:139 +msgid "A script to manage your weight in command line." +msgstr "" + +#: weight-cli.py:144 +msgid "optional file data" +msgstr "" diff --git a/locale/en/LC_MESSAGES/base.mo b/locale/en/LC_MESSAGES/base.mo new file mode 100644 index 0000000..6ee1200 Binary files /dev/null and b/locale/en/LC_MESSAGES/base.mo differ diff --git a/locale/en/LC_MESSAGES/base.po b/locale/en/LC_MESSAGES/base.po new file mode 100644 index 0000000..346de7f --- /dev/null +++ b/locale/en/LC_MESSAGES/base.po @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-21 14:19+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: Guyot Vincent \n" +"Language-Team: English \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: weight-cli.py:139 +msgid "A script to manage your weight in command line." +msgstr "" + +#: weight-cli.py:144 +msgid "optional : file data" +msgstr "" diff --git a/locale/fr/LC_MESSAGES/base.mo b/locale/fr/LC_MESSAGES/base.mo new file mode 100644 index 0000000..34ea239 Binary files /dev/null and b/locale/fr/LC_MESSAGES/base.mo differ diff --git a/locale/fr/LC_MESSAGES/base.po b/locale/fr/LC_MESSAGES/base.po new file mode 100644 index 0000000..5713708 --- /dev/null +++ b/locale/fr/LC_MESSAGES/base.po @@ -0,0 +1,54 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-04-21 14:19+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: Guyot Vincent \n" +"Language-Team: French \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "A script to manage your weight in command line." +msgstr "Un script en ligne de commande pour gérer votre poids." + +msgid "optional : file data" +msgstr "fichier de données : optionnel" + +msgid "optional : weight" +msgstr "poids : optionnel" + +msgid "optional : type" +msgstr "type : optionnel" + +msgid "optional : date" +msgstr "date : optionnelle" + +msgid "optional : id" +msgstr "identifiant : optionnel" + +msgid "optional : metric" +msgstr "métrique : optionnelle" + +msgid "optional : comment" +msgstr "commentaire : optionnel" + +msgid "optional : other" +msgstr "autre : optionnel" + +msgid "optional : delete a measure by its number in the list" +msgstr "suppression d'une mesure par son numéro dans la liste : optionnel" + +msgid "optional : plot graph" +msgstr "trace le graphe : optionnel" + +msgid "optional : undo remove the last line removed" +msgstr "annule la suppression de la dernière ligne effacée : optionnel" diff --git a/weight-cli.py b/weight-cli.py index 8a91047..ca6fc24 100644 --- a/weight-cli.py +++ b/weight-cli.py @@ -16,6 +16,7 @@ from dateutil.rrule import rrulestr #import uuid #import json import os +#os.environ['LANGUAGE']='fr' #import logging import sys #import re @@ -26,6 +27,17 @@ import sys import subprocess from subprocess import Popen, PIPE import numpy as np +import gettext +#gettext.bindtextdomain('base', 'locale/en/LC_MESSAGES/base.mo') +#gettext.textdomain('base') +# Voir : https://docs.python.org/fr/3/library/gettext.html +#en = gettext.translation('base', localedir='locale/', languages=['en']) +#en.install() +#_ = en.gettext # english +fr = gettext.translation('base', localedir='locale/', languages=['fr']) +fr.install() +_ = fr.gettext # english +# Voir : https://medium.com/i18n-and-l10n-resources-for-developers/how-to-translate-python-applications-with-the-gnu-gettext-module-5c1c085041 """ Une mesure est caractérisée par : @@ -39,7 +51,7 @@ Une mesure est caractérisée par : """ def save_mesure(): - ''' Affichage et enregistrement d'une mesure ''' + """ Affichage et enregistrement d'une mesure """ print("Votre mesure a été enregistrée : ") with indent(4, quote=colored.blue('')): puts(colored.green("-votre poids : {weight} kg").format(weight=args.weight)) @@ -59,7 +71,7 @@ def save_mesure(): str(args.other)]) def read_measures(): - ''' Affichage de l'ensemble des mesures ''' + """ Affichage de l'ensemble des mesures """ data_file = open(str(args.data), 'r') data = csv.reader(data_file, delimiter='|') linenum = 0 @@ -77,7 +89,7 @@ def read_measures(): data_file.close() def remove_measure(): - ''' Remove a measure ''' + """ Remove a measure """ f = open(args.data, "r") contents = f.readlines() f.close() @@ -94,7 +106,7 @@ def remove_measure(): f.close() def undo_remove(): - ''' Undo remove the last line removed ''' + """ Undo remove the last line removed """ f = open(args.data, "r") contents = f.readlines() f.close() @@ -110,7 +122,7 @@ def undo_remove(): f.close() def trace_graph(): - ''' Trace le graphe de l'évolution du poids avec Gnuplot ''' + """ Trace le graphe de l'évolution du poids avec Gnuplot """ #process = Popen(['gnuplot', 'Fonctionnel.txt'], stdout=PIPE, stderr=PIPE) process = Popen(['gnuplot', 'Fonctionnel.txt'])#, stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() @@ -118,53 +130,55 @@ def trace_graph(): def tests_subproc(): - ''' Test du module subprocess ''' + """ Test du module subprocess """ process = Popen(['cat', 'data2.csv'], stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() print(stdout) ### Main ### -''' Programme de relevé de poids +""" Programme de relevé de poids Attention, le fichier data.csv à une ligne d'entête à laquelle il manque un séparateur | final pour que le nombre de champs soit correct. -''' +""" # Création du parseur pour les arguments parser = argparse.ArgumentParser() +texte = _('A script to manage your weight in command line.') +parser.description=texte # Création des arguments parser.add_argument('-da', '--data', default='data2.csv', - help='optional file data' + help=_('optional : file data') ) parser.add_argument('-w', '--weight', type=float, default=-1, - help='optional weight' + help=_('optional : weight') ) parser.add_argument('-t', '--type', default='WEIGHT', - help='optional type' + help=_('optional : type') ) parser.add_argument('-d', '--date', default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - help='optional date' + help=_('optional : date') ) parser.add_argument('-i', '--id', default='', - help='optional id' + help=_('optional : id') ) parser.add_argument('-m', '--metric', default='true', - help='optional metric' + help=_('optional : metric') ) parser.add_argument('-c', '--comment', default=' ', - help='optional comment' + help=_('optional : comment') ) parser.add_argument('-o', '--other', default='', - help='optional other' + help=_('optional : other') ) parser.add_argument('-r', '--read', help='optional read measures', @@ -173,10 +187,10 @@ parser.add_argument('-r', '--read', parser.add_argument('-rem', '--remove', type=int, default='-1', - help='optional delete a measure by its number in the list' + help=_('optional : delete a measure by its number in the list') ) parser.add_argument('-g', '--graph', - help='optional delete a measure by its number in the list', + help=_('optional : plot graph'), action='store_true' ) parser.add_argument('-tst', '--tests', @@ -184,9 +198,13 @@ parser.add_argument('-tst', '--tests', action='store_true' ) parser.add_argument('-ur', '--undoremove', - help='optional undo remove the last line removed', + help=_('optional : undo remove the last line removed'), action='store_true' ) +parser.add_argument('-v', '--version', + version='0.0.5', + action='version' +) # Récupération des arguments args = parser.parse_args() # Lancement des actions