From e772846992b0ae7e2944abb8b293bbdadc0c4875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Tue, 10 Nov 2020 17:40:14 +0100 Subject: [PATCH] Replace metarecover bash script by a more flexible python version in order to use python for each tools --- tools/metarecover.py | 25 +++++++++++++++++++++++++ tools/metarecover.sh | 10 ---------- 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 tools/metarecover.py delete mode 100755 tools/metarecover.sh diff --git a/tools/metarecover.py b/tools/metarecover.py new file mode 100644 index 00000000..5b9c285f --- /dev/null +++ b/tools/metarecover.py @@ -0,0 +1,25 @@ +from git import Repo,Git +import io +r=Repo(path=".") +l=[item for item in r.index.diff(None) if item.a_path.endswith(".dat") and item.change_type=="M"] +len(l) +for i in l: + print(i.a_path) + g=Git(Repo.git_dir) + with io.StringIO(g.execute(["git" ,"--no-pager", "show", f"HEAD~1:{i.a_path}"])) as old: + with open(i.a_path,mode="r+") as new: + with io.StringIO(new.read()) as copy: + new.seek(0) + line=old.readline() + while line and line.startswith("#"): + new.write(line) + line=old.readline() + line=copy.readline() + end=False + while line: + if not end and not line.startswith("#"): + end=True + if end: + new.write(line) + line=copy.readline() + new.truncate() \ No newline at end of file diff --git a/tools/metarecover.sh b/tools/metarecover.sh deleted file mode 100755 index 24538f2d..00000000 --- a/tools/metarecover.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -files=$(git status -s | grep " M " | cut -c4- | grep 'static/data/') -for file in $files; do - show="$(git --no-pager show HEAD~1:$file)" - IFS=$'\n' lines=($show) - for (( i=0; i<=5; i++ )) ;do - line=${lines[i]} - sed -i "$((i+1))s|^.*$|$line|" $file - done -done \ No newline at end of file