Skip to content

Commit

Permalink
Revert removal of SABnzbd-console.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
Safihre committed Oct 20, 2023
1 parent 1be4cf9 commit b79a1e9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
13 changes: 10 additions & 3 deletions SABnzbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ def main():
ipv6_hosting = None
inet_exposure = None

service, sab_opts, _serv_opts, upload_nzbs = commandline_handler()
_service, sab_opts, _serv_opts, upload_nzbs = commandline_handler()

for opt, arg in sab_opts:
if opt == "--servicecall":
Expand Down Expand Up @@ -949,8 +949,9 @@ def main():
sabnzbd.DIR_LANGUAGE = real_path(sabnzbd.DIR_PROG, DEF_LANGUAGE)
org_dir = os.getcwd()

# Need console logging if requested or just running as script
console_logging = (console_logging or not hasattr(sys, "frozen")) and not sabnzbd.DAEMON
# Need console logging if requested, for SABnzbd.py and SABnzbd-console.exe
console_logging = console_logging or sys.executable.endswith("console.exe") or not hasattr(sys, "frozen")
console_logging = console_logging and not sabnzbd.DAEMON

LOGLEVELS = (logging.FATAL, logging.WARNING, logging.INFO, logging.DEBUG)

Expand Down Expand Up @@ -1639,6 +1640,12 @@ class SABnzbd(win32serviceutil.ServiceFramework):
"access to network shares."
)

# Only SABnzbd-console.exe can print to the console, so the service is installed
# from there. But we run SABnzbd.exe so nothing is logged. Logging can cause the
# Windows Service to stop because the output buffers are full.
if hasattr(sys, "frozen"):
_exe_name_ = "SABnzbd.exe"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
Expand Down
26 changes: 24 additions & 2 deletions builder/SABnzbd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ exe = EXE(
[],
exclude_binaries=True,
name="SABnzbd",
console=True,
hide_console="hide-early",
console=False,
append_pkg=False,
icon="icons/sabnzbd.ico",
contents_directory=".",
Expand All @@ -126,6 +125,29 @@ exe = EXE(

coll = COLLECT(exe, pyi_analysis.binaries, pyi_analysis.zipfiles, pyi_analysis.datas, name="SABnzbd")

# We need to run again for the console-app
if sys.platform == "win32":
# Enable console=True for this one
console_exe = EXE(
pyz,
pyi_analysis.scripts,
[],
exclude_binaries=True,
name="SABnzbd-console",
append_pkg=False,
icon="icons/sabnzbd.ico",
contents_directory=".",
version=version_info,
)

console_coll = COLLECT(
console_exe,
pyi_analysis.binaries,
pyi_analysis.zipfiles,
pyi_analysis.datas,
name="SABnzbd-console",
)

# Build the APP on macOS
if sys.platform == "darwin":
info_plist = {
Expand Down
3 changes: 3 additions & 0 deletions builder/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def test_sab_binary(binary_path: str):
# Run PyInstaller and check output
run_external_command([sys.executable, "-O", "-m", "PyInstaller", "SABnzbd.spec"])

shutil.copytree("dist/SABnzbd-console", "dist/SABnzbd", dirs_exist_ok=True)
safe_remove("dist/SABnzbd-console")

# Remove unwanted DLL's
shutil.rmtree("dist/SABnzbd/Pythonwin")
if BUILDING_64BIT:
Expand Down

0 comments on commit b79a1e9

Please sign in to comment.