Skip to content

Commit

Permalink
Add optargs, TUI, and GUI for winetricks. Fix #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
thw26 authored Jan 5, 2024
2 parents 3ffe649 + bba0d30 commit 787b60a
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 79 deletions.
149 changes: 81 additions & 68 deletions LogosLinuxInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from control import remove_all_index_files
from control import remove_library_catalog
from installer import install
from installer import setWinetricks
from msg import cli_msg
from msg import initialize_logging
from msg import logos_error
Expand Down Expand Up @@ -56,6 +57,8 @@ def parse_command_line():
parser.add_argument('--shortcut', '-s', action='store_true', help='Create shortcut')
parser.add_argument('--passive', '-P', action='store_true', help='Install Faithlife product non-interactively')
parser.add_argument('--control-panel', '-C', action='store_true', help='Open Control Panel app')
parser.add_argument('--get-winetricks', action='store_true', help='Download or update Winetricks')
parser.add_argument('--run-winetricks', action='store_true', help='Download or update Winetricks')
return parser.parse_args()

def parse_args(args):
Expand All @@ -80,6 +83,14 @@ def parse_args(args):
if args.reinstall_dependencies:
config.REINSTALL_DEPENDENCIES = True

if args.get_winetricks:
setWinetricks()
sys.exit(0)

if args.run_winetricks:
run_winetricks()
sys.exit(0)

if args.debug:
setDebug()

Expand Down Expand Up @@ -151,22 +162,6 @@ def main():
with open(config.LOGOS_LOG, 'w') as f:
f.write('')

# If Logos app is installed, run the desired Logos action.
if config.LOGOS_EXE is not None and os.access(config.LOGOS_EXE, os.X_OK):
logging.info(f"App is installed: {config.LOGOS_EXE}")
if config.ACTION == 'control':
run_control_panel()
sys.exit(0)
elif config.ACTION == 'indexing':
run_indexing()
sys.exit(0)
elif config.ACTION == 'logging':
switch_logging()
sys.exit(0)
elif config.ACTION == 'app':
run_logos()
sys.exit(0)

# Check for environment variables.
if config.DIALOG is None:
getDialog()
Expand All @@ -181,58 +176,76 @@ def main():

if config.GUI is True:
setDebug()

options_default = ["Install Logos Bible Software"]
options_exit = ["Exit"]
if file_exists(config.CONFIG_FILE):
options_installed = [f"Run {config.FLPRODUCT}", "Run Indexing", "Remove Library Catalog", "Remove All Index Files", "Edit Config", "Reinstall Dependencies", "Back up Data", "Restore Data", "Set AppImage", "Control Panel", "Run Winetricks"]
if config.LOGS == "DISABLED":
options_installed.append("Enable Logging")
else:
options_installed.append("Disable Logging")
options = options_default + options_installed + options_exit
else:
options = options_default + options_exit

choice = None
if config.DIALOG is None or config.DIALOG == 'tk':
classname = "LogosLinuxInstaller"
installer_app = App(className=classname)
InstallerWindow(installer_app, class_=classname)
installer_app.mainloop()
elif config.DIALOG == 'curses':
choice = curses_menu(options, "Welcome to Logos on Linux", "What would you like to do?")

if choice is None or choice == "Exit":
sys.exit(0)
elif choice.startswith("Install"):
install()
elif choice == f"Run {config.FLPRODUCT}":
run_logos()
elif choice == "Run Indexing":
run_indexing()
elif choice == "Remove Library Catalog":
remove_library_catalog()
elif choice == "Remove All Index Files":
remove_all_index_files()
elif choice == "Edit Config":
edit_config()
elif choice == "Reinstall Dependencies":
checkDependencies()
elif choice == "Back up Data":
backup()
elif choice == "Restore Data":
restore()
elif choice == "Set AppImage":
set_appimage()
elif choice == "Control Panel":
run_control_panel()
elif choice == "Run Winetricks":
run_winetricks()
elif choice.endswith("Logging"):
switch_logging()
else:
logos_error("Unknown menu choice.")
# If Logos app is installed, run the desired Logos action.
if config.LOGOS_EXE is not None and os.access(config.LOGOS_EXE, os.X_OK):
if config.ACTION == 'control':
run_control_panel()
sys.exit(0)
elif config.ACTION == 'indexing':
run_indexing()
sys.exit(0)
elif config.ACTION == 'logging':
switch_logging()
sys.exit(0)
elif config.ACTION == 'app':
run_logos()
sys.exit(0)
if config.DIALOG is None or config.DIALOG == 'tk':
classname = "LogosLinuxInstaller"
installer_app = App(className=classname)
InstallerWindow(installer_app, class_=classname)
installer_app.mainloop()

if config.GUI is False:
while True:
options_default = ["Install Logos Bible Software"]
options_exit = ["Exit"]
if file_exists(config.LOGOS_EXE):
options_installed = [f"Run {config.FLPRODUCT}", "Run Indexing", "Remove Library Catalog", "Remove All Index Files", "Edit Config", "Reinstall Dependencies", "Back up Data", "Restore Data", "Set AppImage", "Control Panel", "Download or Update Winetricks", "Run Winetricks"]
if config.LOGS == "DISABLED":
options_installed.append("Enable Logging")
else:
options_installed.append("Disable Logging")
options = options_default + options_installed + options_exit
else:
options = options_default + options_exit

choice = None
if config.DIALOG == 'curses':
choice = curses_menu(options, "Welcome to Logos on Linux", "What would you like to do?")

if choice is None or choice == "Exit":
sys.exit(0)
elif choice.startswith("Install"):
install()
elif choice == f"Run {config.FLPRODUCT}":
run_logos()
elif choice == "Run Indexing":
run_indexing()
elif choice == "Remove Library Catalog":
remove_library_catalog()
elif choice == "Remove All Index Files":
remove_all_index_files()
elif choice == "Edit Config":
edit_config()
elif choice == "Reinstall Dependencies":
checkDependencies()
elif choice == "Back up Data":
backup()
elif choice == "Restore Data":
restore()
elif choice == "Set AppImage":
set_appimage()
elif choice == "Control Panel":
run_control_panel()
elif choice == "Download or Update Winetricks":
setWinetricks()
elif choice == "Run Winetricks":
run_winetricks()
elif choice.endswith("Logging"):
switch_logging()
else:
logos_error("Unknown menu choice.")

sys.exit(0)
# END FUNCTION DECLARATIONS
Expand Down
19 changes: 16 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from installer import checkExistingInstall
from installer import finish_install
from installer import logos_setup
from installer import setWinetricks
from msg import cli_msg
from utils import checkDependencies
from utils import get_winebin_code_and_desc
Expand All @@ -33,6 +34,7 @@
from wine import createWineBinaryList
from wine import get_app_logging_state
from wine import run_logos
from wine import run_winetricks
from wine import switch_logging


Expand Down Expand Up @@ -460,7 +462,7 @@ def __init__(self, root, **kwargs):
self.root = root
self.root.title("Faithlife Bible Software Control Panel")
self.root.w = 450
self.root.h = 300
self.root.h = 350
self.root.geometry(f"{self.root.w}x{self.root.h}")
self.root.minsize(self.root.w, self.root.h)
# self.root.resizable(False, False)
Expand All @@ -480,6 +482,8 @@ def __init__(self, root, **kwargs):
self.config_button.config(command=self.open_config)
self.deps_button.config(command=self.reinstall_deps)
self.deps_button.state(['disabled']) # FIXME: needs function
self.getwinetricks_button.config(command=self.get_winetricks)
self.runwinetricks_button.config(command=self.launch_winetricks)
self.message_event = '<<ClearMessage>>'

self.root.bind(self.logging_event, self.update_logging_button)
Expand All @@ -500,7 +504,7 @@ def check_resources(self, evt=None):
def get_installdir(self, evt=None):
dirname = askdirectory(
initialdir='~',
title="Choose installation directory..."
title="Choose installation directory"
)
if len(dirname) > 0:
self.installdir = dirname
Expand All @@ -509,8 +513,17 @@ def get_installdir(self, evt=None):
def reinstall_deps(self, evt=None):
checkDependencies()

def get_winetricks(self, evt=None):
winetricks_status = setWinetricks()
if winetricks_status == 0:
self.messagevar.set("Winetricks has been reinstalled.")

def launch_winetricks(self, evt=None):
self.messagevar.set("Launching Winetricks…")
run_winetricks()

def remove_indexes(self, evt=None):
self.messagevar.set("Removing indexes...")
self.messagevar.set("Removing indexes")
t = Thread(target=remove_all_index_files, kwargs={'app': self})
t.start()

Expand Down
4 changes: 4 additions & 0 deletions control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import config
from msg import cli_msg
from installer import setWinetricks


def open_config_file():
Expand Down Expand Up @@ -46,3 +47,6 @@ def remove_library_catalog():
logging.info(f"Removed: {file_to_remove}")
except OSError as e:
logging.error(f"Error removing {file_to_remove}: {e}")

def get_winetricks():
setWinetricks()
42 changes: 37 additions & 5 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __init__(self, **kwargs):

# INSTALLDIR file_chooser
self.installdir_label = Label(self, text="Installation folder: ")
self.installdir_filechooser = Button(self, text="Choose folder...")
self.installdir_filechooser = Button(self, text="Choose folder")
# Run app button
self.run_label = Label(self, text=f"Run app")
self.run_button = Button(self, text="Run")
Expand All @@ -289,10 +289,16 @@ def __init__(self, **kwargs):
self.logging_button = Button(self, textvariable=self.loggingstatevar)
# Edit config button
self.config_label = Label(self, text="Edit config file")
self.config_button = Button(self, text="Edit ...")
self.config_button = Button(self, text="Edit ")
# Reinstall deps button
self.deps_label = Label(self, text="Reinstall dependencies")
self.deps_button = Button(self, text="Reinstall")
# Reinstall or update winetricks
self.getwinetricks_label = Label(self, text="Download or Update Winetricks")
self.getwinetricks_button = Button(self, text="Download or Update Winetricks")
# Reinstall or update winetricks
self.runwinetricks_label = Label(self, text="Run Winetricks")
self.runwinetricks_button = Button(self, text="Run Winetricks")
# Separator
self.separator = Separator(self, orient='horizontal')
# Status message label
Expand Down Expand Up @@ -395,23 +401,49 @@ def __init__(self, **kwargs):
sticky='w',
pady=2,
)
self.separator.grid(
self.getwinetricks_label.grid(
column=0,
row=7,
sticky='w',
padx=2,
pady=2,
)
self.getwinetricks_button.grid(
column=1,
row=7,
sticky='w',
pady=2,
)
self.runwinetricks_label.grid(
column=0,
row=8,
sticky='w',
padx=2,
pady=2,
)
self.runwinetricks_button.grid(
column=1,
row=8,
sticky='w',
pady=2,
)
self.separator.grid(
column=0,
row=9,
columnspan=2,
sticky='we',
pady=2,
)
self.message_label.grid(
column=0,
row=8,
row=10,
columnspan=2,
sticky='we',
pady=2
)
self.progress.grid(
column=0,
row=9,
row=11,
columnspan=2,
sticky='we',
pady=2
Expand Down
10 changes: 7 additions & 3 deletions installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ def beginInstall(app=None):
logos_error(f"{wineserver_path} not found. Please either add it or create a symlink to it, and rerun.")

def downloadWinetricks():
cli_msg("Downloading winetricks...")
cli_msg("Downloading winetricks")
logos_reuse_download(config.WINETRICKS_URL, "winetricks", config.APPDIR_BINDIR)
os.chmod(f"{config.APPDIR_BINDIR}/winetricks", 0o755)

def setWinetricks():
cli_msg("Preparing winetricks...")
cli_msg("Preparing winetricks")
# Check if local winetricks version available; else, download it
if config.WINETRICKSBIN is None:
if config.WINETRICKSBIN is None or not os.access(config.WINETRICKSBIN, os.X_OK):
local_winetricks_path = shutil.which('winetricks')
if local_winetricks_path is not None:
# Check if local winetricks version is up-to-date; if so, offer to use it or to download; else, download it
Expand All @@ -288,20 +288,24 @@ def setWinetricks():
if winetricks_choice.startswith("1"):
logging.info("Setting winetricks to the local binary…")
config.WINETRICKSBIN = local_winetricks_path
return 0
elif winetricks_choice.startswith("2"):
downloadWinetricks()
config.WINETRICKSBIN = os.path.join(config.APPDIR_BINDIR, "winetricks")
return 0
else:
cli_msg("Installation canceled!")
sys.exit(0)
else:
cli_msg("The system's winetricks is too old. Downloading an up-to-date winetricks from the Internet...")
downloadWinetricks()
config.WINETRICKSBIN = os.path.join(config.APPDIR_BINDIR, "winetricks")
return 0
else:
cli_msg("Local winetricks not found. Downloading winetricks from the Internet…")
downloadWinetricks()
config.WINETRICKSBIN = os.path.join(config.APPDIR_BINDIR, "winetricks")
return 0

def getPremadeWineBottle():
cli_msg("Installing pre-made wineBottle 64bits…")
Expand Down

0 comments on commit 787b60a

Please sign in to comment.