mirror of https://github.com/Riesi/frog_emojis.git
[tools] fix git option not supporting renamed git objects properly
This commit is contained in:
parent
6523eeeef2
commit
e16595b69d
48
gen_png.py
48
gen_png.py
|
@ -22,6 +22,7 @@ import argparse
|
||||||
import glob
|
import glob
|
||||||
import ntpath
|
import ntpath
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
# Dependencies: (optional) git, inkscape, python 3.9
|
# 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),
|
subprocess.run(["inkscape", file, "-C", "-h", str(size),
|
||||||
f"--export-filename={raster_path}/{name}.png"],timeout=30, check=True)
|
f"--export-filename={raster_path}/{name}.png"],timeout=30, check=True)
|
||||||
|
|
||||||
|
def print_pipe(out):
|
||||||
|
if out != '':
|
||||||
|
print(out)
|
||||||
|
|
||||||
# git add given files
|
# git add given files
|
||||||
def git_add_raster(files):
|
def git_add_raster(files):
|
||||||
"""Git add's each file in files"""
|
"""Git add's each file in files"""
|
||||||
for file in files:
|
for file in files:
|
||||||
file = file.removeprefix('svg/').removesuffix('.svg')
|
file = file.removeprefix('svg/').removesuffix('.svg')
|
||||||
stream = os.popen(f"git add ./png/**/{file}.png")
|
stream = os.popen(f"git add ./png/**/{file}.png")
|
||||||
print(stream.read())
|
print_pipe(stream.read())
|
||||||
|
|
||||||
# git commit given files
|
# git commit given files
|
||||||
def git_commit_raster():
|
def git_commit_raster():
|
||||||
"""Creates a new autogenerated git commit with the PNGs"""
|
"""Creates a new autogenerated git commit with the PNGs"""
|
||||||
stream = os.popen('git commit -m "[png] generate PNGs"')
|
stream = os.popen('git commit -m "[png] generate PNGs"')
|
||||||
print(stream.read())
|
print_pipe(stream.read())
|
||||||
|
|
||||||
# create a new tag
|
# create a new tag
|
||||||
def create_tag():
|
def create_tag():
|
||||||
|
@ -78,7 +83,7 @@ def create_tag():
|
||||||
tags.remove('')
|
tags.remove('')
|
||||||
# create new tag
|
# create new tag
|
||||||
stream = os.popen(f"git tag auto-v{len(tags)}")
|
stream = os.popen(f"git tag auto-v{len(tags)}")
|
||||||
print(stream.read())
|
print_pipe(stream.read())
|
||||||
|
|
||||||
# -------------------------------#
|
# -------------------------------#
|
||||||
# main section
|
# main section
|
||||||
|
@ -125,20 +130,31 @@ def main():
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
print('No SVGs to regenerate!')
|
print('No SVGs to regenerate!')
|
||||||
sys.exit(1)
|
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]
|
split_files = list()
|
||||||
deleted = [s.removeprefix('D\tsvg/').removesuffix('.svg') for s in files if 'D\t' in s]
|
additions = list()
|
||||||
renamed = [s.removeprefix('R100\t').split('\t') for s in files if 'R100\t' in s]
|
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
|
# print('A:' + str(additions))
|
||||||
for ren in renamed:
|
# print('M:' + str(modifications))
|
||||||
deleted.append(ren[0].removeprefix('svg/').removesuffix('.svg'))
|
# print('D:' + str(deleted))
|
||||||
modifications.append(ren[1])
|
# print('R[0-9]+:' + str(renamed))
|
||||||
|
|
||||||
#print('A:' + str(additions))
|
|
||||||
#print('M:' + str(modifications))
|
|
||||||
#print('D:' + str(deleted))
|
|
||||||
#print('R100:' + str(renamed))
|
|
||||||
|
|
||||||
delete_graphics(deleted)
|
delete_graphics(deleted)
|
||||||
git_add_raster(deleted)
|
git_add_raster(deleted)
|
||||||
|
|
Loading…
Reference in New Issue