Refactory of the code

This commit is contained in:
Domenico 2022-08-31 16:24:18 +02:00 committed by GitHub
parent 069a5f04db
commit 1ae7be08de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,13 +12,13 @@ if os.path.exists(APP_DIR):
print(f"{APP_DIR}/ already exists. Please remove it then run the script again.")
sys.exit(1)
print()
print("Convert any Arch linux package (official/AUR) to AppImage!!")
print("\nConvert any Arch linux package (official/AUR) to AppImage!!")
utils = Utils()
main_pkg = None
while True:
main_pkg = utils.user_text("Enter the name of the package (leave empty to quit)")
main_pkg = utils.user_text(
"Enter the name of the package (leave empty to quit)")
if not main_pkg:
print("Exiting...")
@ -29,9 +29,7 @@ while True:
if main_pkg_url:
break
print("Package not found. Please check the name and try again")
print()
print("Package not found. Please check the name and try again\n")
print()
os.mkdir(APP_DIR)
@ -40,17 +38,20 @@ utils.download(main_pkg_url, "download", main_pkg)
utils.extract_zst("download", APP_DIR)
utils.rm("download")
desktop_file = glob.glob(os.path.join(APP_DIR, "usr/share/applications/*.desktop"))
desktop_file = glob.glob(os.path.join(
APP_DIR, "usr/share/applications/*.desktop"))
if not desktop_file:
print("No .desktop file was found in the package.")
desktop_file = utils.user_path("Please enter the path to a .desktop file", required=True)
desktop_file = utils.user_path(
"Please enter the path to a .desktop file", required=True)
elif len(desktop_file) == 1:
desktop_file = desktop_file[0]
else:
desktop_file = utils.user_select("Select the .desktop file to be used", desktop_file)
desktop_file = utils.user_select(
"Select the .desktop file to be used", desktop_file)
while True:
@ -58,44 +59,42 @@ while True:
if vfd:
break
print()
print(".desktop file validation failed due to the error below:")
print(msg)
desktop_file = utils.user_path("Please enter the path to a valid .desktop file", required=True)
print(f"\n.desktop file validation failed due to the error below:\n{msg}")
desktop_file = utils.user_path(
"Please enter the path to a valid .desktop file", required=True)
utils.copy_file(desktop_file, APP_DIR)
with open(desktop_file, "r") as f:
icon_name = re.findall('Icon=(.*)', f.read())
if icon_name:
icon_name = icon_name[0]
else:
icon_name = None
icon_name = icon_name[0] if icon_name else None
icon_file = None
if not icon_name:
print("The .desktop file doesn't have an Icon attribute")
icon_file = utils.user_path("Please enter the path to the icon file to be used", required=True)
icon_file = utils.user_path(
"Please enter the path to the icon file to be used", required=True)
if icon_file is not None:
icon_name = ".".join(icon_file.split("/")[-1].split(".")[:-1])
utils.set_icon_desktop_file(desktop_file, icon_name)
else:
i_files = os.path.join(APP_DIR, f"usr/share/icons/**/*.*")
i_files = os.path.join(APP_DIR, "usr/share/icons/**/*.*")
icon_file = glob.glob(i_files, recursive=True)
if not icon_file:
print(f"No icon file was found in {APP_DIR}/usr/share/icons/")
icon_file = utils.user_path("Please enter the path to the icon file to be used", required=True)
icon_file = utils.user_path(
"Please enter the path to the icon file to be used", required=True)
elif len(icon_file) == 1:
icon_file = icon_file[0]
else:
icon_file = utils.user_select("Please select the icon file to be used", sorted(icon_file))
icon_file = utils.user_select(
"Please select the icon file to be used", sorted(icon_file))
utils.copy_file(icon_file, APP_DIR)
@ -124,24 +123,20 @@ while True:
if pkgs[pkg]:
continue
url = utils.get_pkg(pkg)
if url:
if url := utils.get_pkg(pkg):
pkgs[pkg] = url
else:
not_found.append(pkg)
print()
print("These packages (and their dependencies) will be downloaded:")
print("\nThese packages (and their dependencies) will be downloaded:")
for i, p in enumerate(pkgs):
if pkgs[p]:
print(f"{i+1}. {p}")
if not_found:
print()
print("These packages could not be found: " + " ".join(not_found))
print("\nThese packages could not be found: " + " ".join(not_found))
new_pkgs = utils.user_text("If you would like to add additional packages " +
"please enter them below (space seperated). Leave empty to start downloading")
@ -205,23 +200,20 @@ while True:
if pkgs[pkg]:
continue
url = utils.get_pkg(pkg)
if url:
if url := utils.get_pkg(pkg):
pkgs[pkg] = url
else:
not_found.append(pkg)
print()
print("These packages will be downloaded:")
print("\nThese packages will be downloaded:")
for i, p in enumerate(pkgs):
if pkgs[p]:
print(f"{i+1}. {p}")
if not_found:
print()
print("These packages could not be found: " + " ".join(not_found))
print("\nThese packages could not be found: " + " ".join(not_found))
if pkgs:
for name, url in pkgs.items():
@ -239,8 +231,7 @@ latest AppImageTool? If you select No the existing one will be used."):
utils.make_executable(appimagetool)
while True:
print("Running AppImageTool...")
print()
print("Running AppImageTool...\n")
if not os.path.exists(OUT_DIR):
os.mkdir(OUT_DIR)