From 4e33c773086a45f8fdeae42f7947127117398cb0 Mon Sep 17 00:00:00 2001 From: Guyot Date: Mon, 20 Apr 2020 17:42:54 +0200 Subject: [PATCH] Add function undo remove a line. --- data2.csv | 5 +---- remove.txt | 1 + weight-cli.py | 31 ++++++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 remove.txt diff --git a/data2.csv b/data2.csv index 66fa8eb..595bbe4 100644 --- a/data2.csv +++ b/data2.csv @@ -1,6 +1,3 @@ 6|WEIGHT|2020-04-15 11:16:58|True| |6e test| 7|WEIGHT|2020-04-15 11:18:06|True| |7e test| -8|WEIGHT|2020-04-15 11:26:06|true||8e test| -9|WEIGHT|2020-04-15 11:27:45|true||9e test| -10|WEIGHT|2020-04-15 11:39:12|true||10e test| -10.1|WEIGHT|2020-04-15 15:22:22|true||11e test| +13.0|WEIGHT|2020-04-20 17:39:31|true||8e test| diff --git a/remove.txt b/remove.txt new file mode 100644 index 0000000..4846dea --- /dev/null +++ b/remove.txt @@ -0,0 +1 @@ +2 13.0|WEIGHT|2020-04-20 17:39:31|true||8e test| diff --git a/weight-cli.py b/weight-cli.py index 21fe3a2..8a91047 100644 --- a/weight-cli.py +++ b/weight-cli.py @@ -77,11 +77,15 @@ def read_measures(): data_file.close() def remove_measure(): - ''' Supprime une mesure ''' + ''' Remove a measure ''' f = open(args.data, "r") contents = f.readlines() f.close() # remove the line item from list, by line number, starts from 0 + store_temp = str(args.remove)+' '+contents[args.remove] + g = open('remove.txt', "w") + g.write(str(store_temp)) + g.close() contents.pop(args.remove) f = open(args.data, "w") @@ -89,6 +93,22 @@ def remove_measure(): f.write(contents) f.close() +def undo_remove(): + ''' Undo remove the last line removed ''' + f = open(args.data, "r") + contents = f.readlines() + f.close() + g = open('remove.txt', 'r') + store_temp = g.readline().split(' ',1) + g.close() + # insert the line item from list, by line number, starts from 0 + contents.insert(int(store_temp[0]), store_temp[1]) + + f = open(args.data, "w") + contents = "".join(contents) + f.write(contents) + f.close() + def trace_graph(): ''' Trace le graphe de l'évolution du poids avec Gnuplot ''' #process = Popen(['gnuplot', 'Fonctionnel.txt'], stdout=PIPE, stderr=PIPE) @@ -115,7 +135,7 @@ parser = argparse.ArgumentParser() # Création des arguments parser.add_argument('-da', '--data', default='data2.csv', - help='optional data' + help='optional file data' ) parser.add_argument('-w', '--weight', type=float, @@ -163,6 +183,10 @@ parser.add_argument('-tst', '--tests', help='optional tests operations', action='store_true' ) +parser.add_argument('-ur', '--undoremove', + help='optional undo remove the last line removed', + action='store_true' +) # Récupération des arguments args = parser.parse_args() # Lancement des actions @@ -176,5 +200,6 @@ if args.graph: trace_graph() if args.tests: tests_subproc() - +if args.undoremove: + undo_remove()