Skip to content

Commit

Permalink
fewer uses of sys.exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 27, 2024
1 parent c19ba56 commit 83aa7b8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyglossary/plugins/appledict/jing/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
log.addHandler(console_output_handler)
log.setLevel(logging.INFO)

main.main()
sys.exit(main.main())
7 changes: 4 additions & 3 deletions pyglossary/plugins/appledict/jing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ def run(filename: str) -> None:
log.info("Jing check successfully passed!")


def main() -> None:
def main() -> int:
"""
Run Jing test on given dictionary XML file with Apple Dictionary Schema.
It's a command-line utility.
"""
if len(sys.argv) < 2:
prog_name = path.basename(sys.argv[0])
log.info(f"usage:\n {prog_name} filename")
sys.exit(1)
return 1
try:
run(sys.argv[1])
return 0
except JingTestError as e:
log.fatal(str(e))
sys.exit(e.returncode)
return e.returncode
3 changes: 1 addition & 2 deletions pyglossary/ui/ui_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from __future__ import annotations

import logging
import sys
import traceback
from os.path import abspath, isfile
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -1424,7 +1423,7 @@ def onDeleteEvent(self, _widget, _event):
# if called while converting, main_quit does not exit program,
# it keeps printing warnings,
# and makes you close the terminal or force kill the process
sys.exit(0)
gtk.main_quit()

def consoleClearButtonClicked(self, _widget=None):
self.convertConsoleTextview.get_buffer().set_text("")
Expand Down
3 changes: 1 addition & 2 deletions pyglossary/ui/ui_gtk4.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from __future__ import annotations

import logging
import sys
import traceback
from os.path import abspath, isfile
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -1493,7 +1492,7 @@ def run( # noqa: PLR0913

def exitApp(self):
self.destroy()
sys.exit(0)
# unlike Gtk3, no need for sys.exit or gtk.main_quit (which does not exist)

def onCloseRequest(self, _widget):
self.exitApp()
Expand Down
3 changes: 1 addition & 2 deletions pyglossary/xdxf/css_js_transform.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import logging
import sys
from io import BytesIO
from typing import TYPE_CHECKING, cast

Expand Down Expand Up @@ -177,7 +176,7 @@ def _write_example(self, hf: T_htmlfile, elem: Element) -> None:

def _write_ex_orig(self, hf: T_htmlfile, child: Element) -> None:
# TODO NOT REACHABLE
sys.exit("NOT REACHABLE")
log.warning("---- _write_ex_orig")
with hf.element("i"):
self.writeChildrenOf(hf, child)

Expand Down

0 comments on commit 83aa7b8

Please sign in to comment.