2024-01-09 23:41:27 +00:00
|
|
|
#!/usr/bin/python
|
2024-01-11 14:08:11 +00:00
|
|
|
"""
|
2024-08-07 15:11:51 +00:00
|
|
|
Usage: update_icon_entries.py [--silent]
|
|
|
|
Update icon entries in limboai.gdextension file.
|
2024-01-11 14:08:11 +00:00
|
|
|
|
|
|
|
Options:
|
|
|
|
-s, --silent Don't print anything.
|
|
|
|
-h, --help Print this message.
|
|
|
|
|
|
|
|
Dependencies: python3.
|
|
|
|
|
|
|
|
Use of this source code is governed by an MIT-style
|
|
|
|
license that can be found in the LICENSE file or at
|
|
|
|
https://opensource.org/licenses/MIT.
|
|
|
|
"""
|
2024-01-09 23:41:27 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
2024-01-11 14:08:11 +00:00
|
|
|
import sys
|
|
|
|
import getopt
|
|
|
|
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
print(__doc__.strip())
|
|
|
|
|
2024-01-09 23:41:27 +00:00
|
|
|
|
|
|
|
def get_script_dir():
|
|
|
|
return os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
2024-08-07 15:19:51 +00:00
|
|
|
def update_icon_entries(silent=False):
|
2024-01-09 23:41:27 +00:00
|
|
|
config_dir = get_script_dir()
|
|
|
|
config_path = os.path.join(config_dir, "limboai.gdextension")
|
|
|
|
content = ""
|
|
|
|
|
|
|
|
f = open(config_path, "r")
|
|
|
|
for line in f:
|
|
|
|
if line.startswith("[icons]"):
|
|
|
|
break
|
|
|
|
content += line
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
content += "[icons]\n\n"
|
|
|
|
|
2024-01-17 10:14:51 +00:00
|
|
|
icon_files = []
|
2024-01-09 23:41:27 +00:00
|
|
|
icons_dir = os.path.join(config_dir, "../icons/")
|
|
|
|
for icon_file in glob.glob(icons_dir + "/*.svg"):
|
|
|
|
icon_file = os.path.basename(icon_file)
|
2024-01-17 10:14:51 +00:00
|
|
|
icon_files.append(icon_file)
|
|
|
|
|
|
|
|
icon_files.sort()
|
|
|
|
for icon_file in icon_files:
|
2024-05-02 22:21:51 +00:00
|
|
|
content += os.path.splitext(icon_file)[0] + ' = "res://addons/limboai/icons/' + icon_file + '"\n'
|
2024-01-09 23:41:27 +00:00
|
|
|
|
|
|
|
f = open(config_path, "w")
|
|
|
|
f.write(content)
|
|
|
|
f.close()
|
|
|
|
|
2024-01-11 14:08:11 +00:00
|
|
|
if not silent:
|
|
|
|
print(content)
|
2024-08-07 15:11:51 +00:00
|
|
|
print("======= Icon entries updated =======")
|
2024-01-09 23:41:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-08-07 15:19:51 +00:00
|
|
|
silent = False
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:], "s", ["silent"])
|
|
|
|
except getopt.GetoptError as e:
|
|
|
|
print(
|
|
|
|
"%s: %s!\n"
|
|
|
|
% (
|
|
|
|
os.path.basename(__file__),
|
|
|
|
e.msg,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
usage()
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
for opt, arg in opts:
|
|
|
|
if opt in ("-h", "--help"):
|
|
|
|
usage()
|
|
|
|
sys.exit(0)
|
|
|
|
elif opt in ("-s", "--silent"):
|
|
|
|
silent = True
|
|
|
|
|
|
|
|
update_icon_entries(silent)
|