[tools] fix git option not supporting renamed git objects properly

This commit is contained in:
Stefan Riesenberger 2022-03-01 12:53:10 +01:00 committed by Riesi
parent 073c35c775
commit c6e69d7295
1 changed files with 32 additions and 16 deletions

View File

@ -22,6 +22,7 @@ import argparse
import glob
import ntpath
import os
import re
import subprocess
import sys
# Dependencies: (optional) git, inkscape, python 3.9
@ -54,19 +55,23 @@ def raster_graphics(files, sizes = None):
subprocess.run(["inkscape", file, "-C", "-h", str(size),
f"--export-filename={raster_path}/{name}.png"],timeout=30, check=True)
def print_pipe(out):
if out != '':
print(out)
# git add given files
def git_add_raster(files):
"""Git add's each file in files"""
for file in files:
file = file.removeprefix('svg/').removesuffix('.svg')
stream = os.popen(f"git add ./png/**/{file}.png")
print(stream.read())
print_pipe(stream.read())
# git commit given files
def git_commit_raster():
"""Creates a new autogenerated git commit with the PNGs"""
stream = os.popen('git commit -m "[png] generate PNGs"')
print(stream.read())
print_pipe(stream.read())
# create a new tag
def create_tag():
@ -78,7 +83,7 @@ def create_tag():
tags.remove('')
# create new tag
stream = os.popen(f"git tag auto-v{len(tags)}")
print(stream.read())
print_pipe(stream.read())
# -------------------------------#
# main section
@ -125,20 +130,31 @@ def main():
if len(files) == 0:
print('No SVGs to regenerate!')
sys.exit(1)
additions = [s.removeprefix('A\t') for s in files if 'A\t' in s]
modifications = [s.removeprefix('M\t') for s in files if 'M\t' in s]
deleted = [s.removeprefix('D\tsvg/').removesuffix('.svg') for s in files if 'D\t' in s]
renamed = [s.removeprefix('R100\t').split('\t') for s in files if 'R100\t' in s]
split_files = list()
additions = list()
modifications = list()
deleted = list()
renamed = list()
for s in reversed(files):
split_file = s.split('\t')
if 'A' == split_file[0]:
additions.append(split_file[1])
elif 'M' == split_file[0]:
modifications.append(split_file[1])
elif 'D' == split_file[0]:
deleted.append(split_file[1].removeprefix('svg/').removesuffix('.svg'))
elif re.match(r"R[0-9]+", split_file[0]):
deleted.append(split_file[1].removeprefix('svg/').removesuffix('.svg'))
modifications.append(split_file[2])
else:
print(f'Unrecognized git action: {split_file}')
sys.exit(1)
# also delete the renamed files and regenerate with the new name
for ren in renamed:
deleted.append(ren[0].removeprefix('svg/').removesuffix('.svg'))
modifications.append(ren[1])
#print('A:' + str(additions))
#print('M:' + str(modifications))
#print('D:' + str(deleted))
#print('R100:' + str(renamed))
# print('A:' + str(additions))
# print('M:' + str(modifications))
# print('D:' + str(deleted))
# print('R[0-9]+:' + str(renamed))
delete_graphics(deleted)
git_add_raster(deleted)