mirror of https://github.com/Riesi/frog_emojis.git
Add proper parameter support for gen_png + Windows support
This commit is contained in:
parent
1e4dbedee8
commit
412da59a6b
17
README.md
17
README.md
|
@ -15,3 +15,20 @@ When submitting PRs keep the following in mind please:
|
||||||
|
|
||||||
- only submit SVGs.
|
- only submit SVGs.
|
||||||
- don't have spaces in your file names. Use snake_case or camelCase instead.
|
- don't have spaces in your file names. Use snake_case or camelCase instead.
|
||||||
|
- only submit SVGs with the file ending `.svg`. Not `.SVG` or `.sVg`
|
||||||
|
|
||||||
|
## Generating PNGs
|
||||||
|
If you want to generate PNGs from the SVGs, you can use the `gen_png.py` script.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
- Python 3.9 - To run the script.
|
||||||
|
- Inkscape - Used to generate the PNGs. Needs to be located in PATH.
|
||||||
|
- (Optional) git - Can be used to automatically add a new commit with the generated PNGs.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
gen_png.py [OPTION]
|
||||||
|
|
||||||
|
-h, --help Shows this help message.
|
||||||
|
-a, --all Regenerates all PNGs.
|
||||||
|
-s, --specific [FILENAME]... Regenerate the PNGs for each FILENAME in the "svg" folder. The '.svg' suffix is optional.
|
||||||
|
-g, --git Regenerates all PNGs and creates a git commit for them. Requires 'git' to be installed and located in PATH.
|
||||||
|
|
48
gen_png.py
48
gen_png.py
|
@ -22,7 +22,8 @@ import ntpath
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
# Dependencies: grep, git, inkscape, python 3.9
|
import platform
|
||||||
|
# Dependencies: (optional) git, inkscape, python 3.9
|
||||||
|
|
||||||
|
|
||||||
# deletes raster graphics with given name
|
# deletes raster graphics with given name
|
||||||
|
@ -34,6 +35,7 @@ def delete_graphics(name):
|
||||||
|
|
||||||
# rasters SVGs via Inkscape
|
# rasters SVGs via Inkscape
|
||||||
def raster_graphics(files):
|
def raster_graphics(files):
|
||||||
|
# TODO: make this adjustable via option/parameter
|
||||||
sizes = [72, 512, 1024]
|
sizes = [72, 512, 1024]
|
||||||
frogs = len(files)-1
|
frogs = len(files)-1
|
||||||
for f in files:
|
for f in files:
|
||||||
|
@ -70,22 +72,40 @@ def create_tag():
|
||||||
# create new tag
|
# create new tag
|
||||||
stream = os.popen('git tag auto-v'+str(len(tags)))
|
stream = os.popen('git tag auto-v'+str(len(tags)))
|
||||||
print(stream.read())
|
print(stream.read())
|
||||||
|
|
||||||
|
# print help message
|
||||||
|
def print_help():
|
||||||
|
print("gen_png.py [OPTION]")
|
||||||
|
print("")
|
||||||
|
print("-h, --help Shows this help message.")
|
||||||
|
print("-a, --all Regenerates all PNGs.")
|
||||||
|
print("-s, --specific [FILENAME]... Regenerate the PNGs for each FILENAME in the \"svg\" folder. The '.svg' suffix is optional.")
|
||||||
|
print("-g, --git Regenerates all PNGs and creates a git commit for them. Requires 'git' to be installed and located in PATH.")
|
||||||
|
|
||||||
# -------------------------------------------------------------------------------------------------------------------------#
|
# -------------------------------------------------------------------------------------------------------------------------#
|
||||||
# main section
|
# main section
|
||||||
#
|
#
|
||||||
files = list()
|
files = list()
|
||||||
if len(sys.argv) == 1:
|
# if there are no arguments (or help parameter was specified), print help and exit
|
||||||
print("Help text missing!")
|
if len(sys.argv) == 1 or sys.argv[1] == '-h' or sys.argv[1] == '--help':
|
||||||
|
print_help()
|
||||||
exit(1)
|
exit(1)
|
||||||
elif sys.argv[1] == 'git':
|
# if "git" parameter was specified, regenerate since last tag + create git commit
|
||||||
|
elif sys.argv[1] == '-g' or sys.argv[1] == '--git':
|
||||||
# get modified, added, renamed, deleted SVGs since last tag
|
# get modified, added, renamed, deleted SVGs since last tag
|
||||||
stream = os.popen('git diff --name-status $(git describe --tags --abbrev=0 --match "auto-v*") HEAD | grep svg/')
|
# call this on windows a) with PS for the $() and b) replace grep with PS' equivalent
|
||||||
|
gitCommand = 'git diff --name-status $(git describe --tags --abbrev=0 --match "auto-v*") HEAD'
|
||||||
|
if sys.platform == "win32":
|
||||||
|
os.environ["COMSPEC"] = 'powershell'
|
||||||
|
stream = os.popen(gitCommand + ' | Select-String svg/')
|
||||||
|
else:
|
||||||
|
stream = os.popen(gitCommand + ' | grep svg/')
|
||||||
output = stream.read()
|
output = stream.read()
|
||||||
files = output.split('\n')
|
files = output.split('\n')
|
||||||
files.remove('')
|
files.remove('')
|
||||||
|
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
print('nothing to do!')
|
print('No SVGs to regenerate!')
|
||||||
exit()
|
exit()
|
||||||
additions = [s.removeprefix('A\t') for s in files if 'A\t' in s]
|
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]
|
modifications = [s.removeprefix('M\t') for s in files if 'M\t' in s]
|
||||||
|
@ -114,13 +134,23 @@ elif sys.argv[1] == 'git':
|
||||||
# commit and tag
|
# commit and tag
|
||||||
git_commit_raster()
|
git_commit_raster()
|
||||||
create_tag()
|
create_tag()
|
||||||
else:
|
# if "all" parameter was specified, raster all svgs including subfolders
|
||||||
if sys.argv[1] == 'all':
|
elif sys.argv[1] == '-a' or sys.argv[1] == '--all':
|
||||||
files = [f for f in glob.glob("svg/**/*.svg", recursive=True)]
|
files = [f for f in glob.glob("svg/**/*.svg", recursive=True)]
|
||||||
else:
|
raster_graphics(files)
|
||||||
|
# if "specific" parameter was specified, only render those
|
||||||
|
elif sys.argv[1] == '-s' or sys.argv[1] == '--specific':
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
print("Please specify at least one file!")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
for f in sys.argv:
|
for f in sys.argv:
|
||||||
f = f.removeprefix('svg/').removesuffix('.svg')
|
f = f.removeprefix('svg/').removesuffix('.svg')
|
||||||
if os.path.exists("svg/"+f+".svg"):
|
if os.path.exists("svg/"+f+".svg"):
|
||||||
files.append("svg/"+f+".svg")
|
files.append("svg/"+f+".svg")
|
||||||
raster_graphics(files)
|
raster_graphics(files)
|
||||||
|
# unknown option
|
||||||
|
else:
|
||||||
|
print("Unknown option!")
|
||||||
|
print("Try 'gen_png.py --help' for more information.")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue