forked from Shrinks99/blender-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize.py
More file actions
executable file
·49 lines (42 loc) · 1.57 KB
/
optimize.py
File metadata and controls
executable file
·49 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
# Requires Python >= 3
"""
Filename:
optimize.py
Function:
This script calls SVGO and makes sure that SVGO is executed correctly on all platforms
Important notes:
Code should be formatted by black and checked for bugs by pylint
"""
from sys import platform
import os
# We'll use NPX to run SVGO which optimizes the files
MAIN_COMMAND = "npx svgo -f blender-icons -o blender-icons"
# These two commands are used on Unix-based OSes and Windows
# respectively to check if the `npx` command exists
UNIX_COMMAND = "command -v npx &> /dev/null"
WINDOWS_COMMAND = "WHERE scp >nul 2>nul"
# These variables store the error warning if NPX is not found
ERROR_WARNING = "ERROR: You don't have NPX installed or it's not installed correctly!"
HELP_LINK = "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm"
ERROR_INSTRUCTION = "To troubleshoot this issue, visit " + HELP_LINK
# This variable prints the success message
SUCCESS_MESSAGE = "Great! SVGO will begin optimizing the SVGs shortly...\n"
# Linux & macOS (basically any Unix-based OS)
if platform in ("linux", "linux2", "darwin"):
# If exit code is 0 that means NPX is found
if os.system(UNIX_COMMAND) == 0:
print(SUCCESS_MESSAGE)
os.system(MAIN_COMMAND)
else:
print(ERROR_WARNING)
print(ERROR_INSTRUCTION)
# Windows
elif platform == "win32":
# If exit code is 0 that means NPX is found
if os.system(WINDOWS_COMMAND) == 0:
print(SUCCESS_MESSAGE)
os.system(MAIN_COMMAND)
else:
print(ERROR_WARNING)
print(ERROR_INSTRUCTION)