Switch to using constants and less manual pathing
This commit is contained in:
@@ -18,29 +18,32 @@ from PIL import Image
|
|||||||
# if False, then sips will be used instead of ImageMagick
|
# if False, then sips will be used instead of ImageMagick
|
||||||
useMagick = True
|
useMagick = True
|
||||||
|
|
||||||
logo_filename = "edgetx-logo.png"
|
LOGO_FILENAME = "edgetx-logo.png"
|
||||||
|
|
||||||
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
images_dir = os.path.join(PROJECT_ROOT, "companion", "src", "images")
|
TOOLS_DIR = os.path.dirname(__file__)
|
||||||
win_icons_dir = os.path.join(PROJECT_ROOT, "companion", "src", "images", "winicons")
|
IMAGES_DIR = os.path.join(PROJECT_ROOT, "companion", "src", "images")
|
||||||
linux_icons_dir = os.path.join(PROJECT_ROOT, "companion", "src", "images", "linuxicons")
|
WIN_ICONS_DIR = os.path.join(PROJECT_ROOT, "companion", "src", "images", "winicons")
|
||||||
mac_icons_dir = os.path.join(PROJECT_ROOT, "companion", "src", "images", "macicons")
|
LINUX_ICONS_DIR = os.path.join(PROJECT_ROOT, "companion", "src", "images", "linuxicons")
|
||||||
start_dir = os.getcwd()
|
MAC_ICONS_DIR = os.path.join(PROJECT_ROOT, "companion", "src", "images", "macicons")
|
||||||
|
START_DIR = os.getcwd()
|
||||||
|
ABS_LOGO_FILENAME = os.path.abspath(os.path.join(TOOLS_DIR,LOGO_FILENAME))
|
||||||
|
|
||||||
def cleanup():
|
def cleanup():
|
||||||
os.chdir(start_dir)
|
os.chdir(TOOLS_DIR)
|
||||||
os.remove(logo_filename)
|
os.remove(ABS_LOGO_FILENAME)
|
||||||
|
|
||||||
# Remove temporary mac icons folder
|
# Remove temporary mac icons folder
|
||||||
if os.path.exists(mac_icons_dir):
|
if os.path.exists(MAC_ICONS_DIR):
|
||||||
shutil.rmtree(mac_icons_dir)
|
shutil.rmtree(MAC_ICONS_DIR)
|
||||||
|
|
||||||
if os.path.exists("icns.tar.gz"):
|
if os.path.exists("icns.tar.gz"):
|
||||||
os.remove("icns.tar.gz")
|
os.remove("icns.tar.gz")
|
||||||
|
|
||||||
if os.path.exists("icnsify"):
|
if os.path.exists("icnsify"):
|
||||||
os.remove("icnsify")
|
os.remove("icnsify")
|
||||||
|
|
||||||
|
os.chdir(START_DIR)
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
|
||||||
@@ -54,46 +57,49 @@ def downloadFile(url: str, outFile: str):
|
|||||||
|
|
||||||
|
|
||||||
# Startup checks
|
# Startup checks
|
||||||
if not os.path.exists(images_dir) or not os.path.exists(win_icons_dir) or not os.path.exists(linux_icons_dir):
|
if not os.path.exists(IMAGES_DIR) or not os.path.exists(WIN_ICONS_DIR) or not os.path.exists(LINUX_ICONS_DIR):
|
||||||
print("Couldn't find a required directory!")
|
print("Couldn't find a required directory!")
|
||||||
print("Images => " + images_dir)
|
print("Images => " + IMAGES_DIR)
|
||||||
print("Windows => " + win_icons_dir)
|
print("Windows => " + WIN_ICONS_DIR)
|
||||||
print("Linux => " + linux_icons_dir)
|
print("Linux => " + LINUX_ICONS_DIR)
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
# Download and save logo if we don't have it already
|
# Download and save logo if we don't have it already
|
||||||
if not os.path.exists(logo_filename):
|
if not os.path.exists(LOGO_FILENAME):
|
||||||
print("Downloading logo...")
|
print("Downloading logo...")
|
||||||
downloadFile('https://raw.githubusercontent.com/EdgeTX/edgetx.github.io/master/images/edgetx-v2.png', logo_filename)
|
downloadFile('https://raw.githubusercontent.com/EdgeTX/edgetx.github.io/master/images/edgetx-v2.png', LOGO_FILENAME)
|
||||||
|
|
||||||
print("Generate 96x96 icon.png... ")
|
print("Generate 96x96 icon.png... ")
|
||||||
os.chdir(images_dir)
|
os.chdir(IMAGES_DIR)
|
||||||
if os.path.exists(images_dir + os.sep + 'icon.png'):
|
icon_png = os.path.join(IMAGES_DIR,'icon.png')
|
||||||
os.remove(images_dir + os.sep + 'icon.png')
|
if os.path.exists(icon_png):
|
||||||
img = Image.open(start_dir + os.sep + logo_filename).resize((96, 96))
|
os.remove(icon_png)
|
||||||
img.save(images_dir + os.sep + 'icon.png')
|
img = Image.open(ABS_LOGO_FILENAME).resize((96, 96))
|
||||||
|
img.save(icon_png)
|
||||||
|
|
||||||
print("Generate Linux Icons... ", end="")
|
print("Generate Linux Icons... ", end="")
|
||||||
os.chdir(linux_icons_dir)
|
os.chdir(LINUX_ICONS_DIR)
|
||||||
|
|
||||||
linux_resolutions = [16, 22, 24, 32, 48, 128, 256, 512]
|
linux_resolutions = [16, 22, 24, 32, 48, 128, 256, 512]
|
||||||
for size in linux_resolutions:
|
for size in linux_resolutions:
|
||||||
new_image_folder = os.path.join(linux_icons_dir, str(size) + 'x' + str(size))
|
new_image_folder = os.path.join(LINUX_ICONS_DIR, str(size) + 'x' + str(size))
|
||||||
if os.path.exists(new_image_folder + os.sep + 'companion.png'):
|
companion_png = os.path.join(new_image_folder, 'companion.png')
|
||||||
os.remove(new_image_folder + os.sep + 'companion.png')
|
if os.path.exists(companion_png):
|
||||||
|
os.remove(companion_png)
|
||||||
elif not os.path.exists(new_image_folder):
|
elif not os.path.exists(new_image_folder):
|
||||||
os.mkdir(new_image_folder)
|
os.mkdir(new_image_folder)
|
||||||
|
|
||||||
print(str(size) + " ", end="")
|
print(str(size) + " ", end="")
|
||||||
img = Image.open(start_dir + os.sep + logo_filename).resize((size, size))
|
img = Image.open(ABS_LOGO_FILENAME).resize((size, size))
|
||||||
img.save(new_image_folder + os.sep + 'companion.png')
|
img.save(companion_png)
|
||||||
|
|
||||||
print("\nGenerate Windows Icons... ", end="")
|
print("\nGenerate Windows Icons... ", end="")
|
||||||
os.chdir(win_icons_dir)
|
os.chdir(WIN_ICONS_DIR)
|
||||||
windows_resolutions = [16, 20, 24, 30, 32, 36, 40, 48, 60, 64, 72, 80, 96, 128, 256]
|
windows_resolutions = [16, 20, 24, 30, 32, 36, 40, 48, 60, 64, 72, 80, 96, 128, 256]
|
||||||
for size in windows_resolutions:
|
for size in windows_resolutions:
|
||||||
if os.path.exists(win_icons_dir + os.sep + 'edgetx_' + str(size) + '.ico'):
|
if os.path.exists('edgetx_' + str(size) + '.ico'):
|
||||||
os.remove(win_icons_dir + os.sep + 'edgetx_' + str(size) + '.ico')
|
os.remove('edgetx_' + str(size) + '.ico')
|
||||||
img = Image.open(start_dir + os.sep + logo_filename).resize((size, size))
|
img = Image.open(ABS_LOGO_FILENAME).resize((size, size))
|
||||||
print(str(size) + " ", end="")
|
print(str(size) + " ", end="")
|
||||||
img.save('edgetx_' + str(size) + '.ico')
|
img.save('edgetx_' + str(size) + '.ico')
|
||||||
|
|
||||||
@@ -104,7 +110,7 @@ print("\nWindows All in One...")
|
|||||||
icon_sizes = [(16, 16), (24, 24), (32, 32), (48, 48),
|
icon_sizes = [(16, 16), (24, 24), (32, 32), (48, 48),
|
||||||
(64, 64), (128, 128), (256, 256)]
|
(64, 64), (128, 128), (256, 256)]
|
||||||
|
|
||||||
img = Image.open(start_dir + os.sep + logo_filename)
|
img = Image.open(ABS_LOGO_FILENAME)
|
||||||
if os.path.exists('edgetx.ico'):
|
if os.path.exists('edgetx.ico'):
|
||||||
os.remove('edgetx.ico')
|
os.remove('edgetx.ico')
|
||||||
img.save('edgetx.ico', sizes=icon_sizes)
|
img.save('edgetx.ico', sizes=icon_sizes)
|
||||||
@@ -117,7 +123,7 @@ libicns @ https://icns.sourceforge.io\
|
|||||||
|
|
||||||
print("Generate Mac icon set...")
|
print("Generate Mac icon set...")
|
||||||
if platform.system() == "Linux":
|
if platform.system() == "Linux":
|
||||||
icns_linux_gz = os.path.join(start_dir, "icns.tar.gz")
|
icns_linux_gz = os.path.join(TOOLS_DIR, "icns.tar.gz")
|
||||||
print("Downloading icns (Go) for Linux amd64...")
|
print("Downloading icns (Go) for Linux amd64...")
|
||||||
downloadFile('https://github.com/JackMordaunt/icns/releases/download/v2.1.2/icns_2.1.2_Linux_x86_64.tar.gz',
|
downloadFile('https://github.com/JackMordaunt/icns/releases/download/v2.1.2/icns_2.1.2_Linux_x86_64.tar.gz',
|
||||||
icns_linux_gz)
|
icns_linux_gz)
|
||||||
@@ -126,21 +132,21 @@ if platform.system() == "Linux":
|
|||||||
tar = tarfile.open(icns_linux_gz, "r:gz")
|
tar = tarfile.open(icns_linux_gz, "r:gz")
|
||||||
for member in tar.getmembers():
|
for member in tar.getmembers():
|
||||||
if "icnsify" in member.name:
|
if "icnsify" in member.name:
|
||||||
tar.extract(member, start_dir)
|
tar.extract(member, TOOLS_DIR)
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(start_dir, "icnsify")):
|
if not os.path.exists(os.path.join(TOOLS_DIR, "icnsify")):
|
||||||
print("Something went wrong setting up icns! Some alternatives are")
|
print("Something went wrong setting up icns! Some alternatives are")
|
||||||
print(alternative_icns_tools)
|
print(alternative_icns_tools)
|
||||||
else:
|
else:
|
||||||
print("Creating MacOS icon set...")
|
print("Creating MacOS icon set...")
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
[
|
[
|
||||||
os.path.join(start_dir, "icnsify"),
|
os.path.join(TOOLS_DIR, "icnsify"),
|
||||||
"-i",
|
"-i",
|
||||||
os.path.join(start_dir, logo_filename),
|
ABS_LOGO_FILENAME,
|
||||||
"-o",
|
"-o",
|
||||||
os.path.join(images_dir, "iconmac.icns")
|
os.path.join(IMAGES_DIR, "iconmac.icns")
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -201,10 +207,10 @@ elif platform.system == "Darwin":
|
|||||||
[
|
[
|
||||||
"magick",
|
"magick",
|
||||||
"convert",
|
"convert",
|
||||||
logo_filename,
|
ABS_LOGO_FILENAME,
|
||||||
"-resize",
|
"-resize",
|
||||||
str(ip.width),
|
str(ip.width),
|
||||||
mac_icons_dir / ip.getIconName()
|
MAC_ICONS_DIR / ip.getIconName()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -214,9 +220,9 @@ elif platform.system == "Darwin":
|
|||||||
"-z",
|
"-z",
|
||||||
str(ip.width),
|
str(ip.width),
|
||||||
str(ip.width),
|
str(ip.width),
|
||||||
logo_filename,
|
ABS_LOGO_FILENAME,
|
||||||
"--out",
|
"--out",
|
||||||
mac_icons_dir / ip.getIconName()
|
MAC_ICONS_DIR / ip.getIconName()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -226,9 +232,9 @@ elif platform.system == "Darwin":
|
|||||||
"iconutil",
|
"iconutil",
|
||||||
"-c",
|
"-c",
|
||||||
"icns",
|
"icns",
|
||||||
mac_icons_dir,
|
MAC_ICONS_DIR,
|
||||||
"-o",
|
"-o",
|
||||||
images_dir / "iconmac.icns"
|
IMAGES_DIR / "iconmac.icns"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user