mirror of
https://github.com/netinvent/npbackup.git
synced 2025-11-08 05:04:45 +08:00
Split npbackup into CLI and GUI
This commit is contained in:
parent
2efd3fc943
commit
f3eda15bef
4 changed files with 47 additions and 33 deletions
19
bin/npbackup_cli
Normal file
19
bin/npbackup_cli
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# This file is part of npbackup, and is really just a binary shortcut to launch npbackup.main
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))
|
||||||
|
|
||||||
|
from npbackup.globvars import Globvars
|
||||||
|
g = Globvars
|
||||||
|
g.GUI = False
|
||||||
|
from npbackup.__main__ import main
|
||||||
|
|
||||||
|
del sys.path[0]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
3
bin/npbackup → bin/npbackup_gui
Executable file → Normal file
3
bin/npbackup → bin/npbackup_gui
Executable file → Normal file
|
|
@ -8,6 +8,9 @@ import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))
|
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))
|
||||||
|
|
||||||
|
from npbackup.globvars import Globvars
|
||||||
|
g = Globvars
|
||||||
|
g.GUI = True
|
||||||
from npbackup.__main__ import main
|
from npbackup.__main__ import main
|
||||||
|
|
||||||
del sys.path[0]
|
del sys.path[0]
|
||||||
|
|
@ -24,21 +24,25 @@ import pidfile
|
||||||
import ofunctions.logger_utils
|
import ofunctions.logger_utils
|
||||||
from ofunctions.platform import python_arch
|
from ofunctions.platform import python_arch
|
||||||
from ofunctions.process import kill_childs
|
from ofunctions.process import kill_childs
|
||||||
|
from npbackup.globvars import Globvars
|
||||||
|
|
||||||
|
|
||||||
# This is needed so we get no GUI version messages
|
# This is needed so we get no GUI version messages
|
||||||
try:
|
if Globvars.GUI:
|
||||||
import PySimpleGUI as sg
|
try:
|
||||||
import _tkinter
|
import PySimpleGUI as sg
|
||||||
|
import _tkinter
|
||||||
_NO_GUI_ERROR = None
|
except ImportError as exc:
|
||||||
_NO_GUI = False
|
if not IS_COMPILED:
|
||||||
except ImportError as exc:
|
print(str(exc))
|
||||||
_NO_GUI_ERROR = str(exc)
|
else:
|
||||||
_NO_GUI = True
|
print("Missing packages in binary.")
|
||||||
|
sys.exit(1)
|
||||||
|
from npbackup.customization import (
|
||||||
|
PYSIMPLEGUI_THEME,
|
||||||
|
OEM_ICON,
|
||||||
|
)
|
||||||
from npbackup.customization import (
|
from npbackup.customization import (
|
||||||
PYSIMPLEGUI_THEME,
|
|
||||||
OEM_ICON,
|
|
||||||
LICENSE_TEXT,
|
LICENSE_TEXT,
|
||||||
LICENSE_FILE,
|
LICENSE_FILE,
|
||||||
)
|
)
|
||||||
|
|
@ -50,7 +54,7 @@ from npbackup.core.nuitka_helper import IS_COMPILED
|
||||||
from npbackup.upgrade_client.upgrader import need_upgrade
|
from npbackup.upgrade_client.upgrader import need_upgrade
|
||||||
from npbackup.core.upgrade_runner import run_upgrade
|
from npbackup.core.upgrade_runner import run_upgrade
|
||||||
|
|
||||||
if not _NO_GUI:
|
if Globvars.GUI:
|
||||||
from npbackup.gui.config import config_gui
|
from npbackup.gui.config import config_gui
|
||||||
from npbackup.gui.operations import operations_gui
|
from npbackup.gui.operations import operations_gui
|
||||||
from npbackup.gui.main import main_gui
|
from npbackup.gui.main import main_gui
|
||||||
|
|
@ -246,23 +250,16 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Add new configuration elements after upgrade",
|
help="Add new configuration elements after upgrade",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--gui-status",
|
|
||||||
action="store_true",
|
|
||||||
help="Show status of required modules for GUI to work",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
version_string = "{} v{}{}{}-{} {} - {} - {}".format(
|
version_string = "{} v{}{}{}-{} {} - {}".format(
|
||||||
__intname__,
|
__intname__,
|
||||||
__version__,
|
__version__,
|
||||||
"-PRIV" if configuration.IS_PRIV_BUILD else "",
|
"-PRIV" if configuration.IS_PRIV_BUILD else "",
|
||||||
"-P{}".format(sys.version_info[1]),
|
"-P{}".format(sys.version_info[1]),
|
||||||
python_arch(),
|
python_arch(),
|
||||||
__build__,
|
__build__,
|
||||||
"GUI disabled" if _NO_GUI else "GUI enabled",
|
|
||||||
__copyright__,
|
__copyright__,
|
||||||
)
|
)
|
||||||
if args.version:
|
if args.version:
|
||||||
|
|
@ -278,15 +275,6 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
print(LICENSE_TEXT)
|
print(LICENSE_TEXT)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.gui_status:
|
|
||||||
logger.info("Can run GUI: {}, errors={}".format(not _NO_GUI, _NO_GUI_ERROR))
|
|
||||||
# Don't bother to talk about package manager when compiled with Nuitka
|
|
||||||
if _NO_GUI and not IS_COMPILED:
|
|
||||||
logger.info(
|
|
||||||
'You need tcl/tk 8.6+ and python-tkinter installed for GUI to work. Please use your package manager (example "yum install python-tkinter" or "apt install python3-tk") to install missing dependencies.'
|
|
||||||
)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
if args.debug or os.environ.get("_DEBUG", "False").capitalize() == "True":
|
if args.debug or os.environ.get("_DEBUG", "False").capitalize() == "True":
|
||||||
_DEBUG = True
|
_DEBUG = True
|
||||||
logger.setLevel(ofunctions.logger_utils.logging.DEBUG)
|
logger.setLevel(ofunctions.logger_utils.logging.DEBUG)
|
||||||
|
|
@ -347,7 +335,7 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
message = _t("config_gui.no_config_available")
|
message = _t("config_gui.no_config_available")
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
|
|
||||||
if config_dict is None and not _NO_GUI:
|
if config_dict is None and Globvars.GUI:
|
||||||
config_dict = configuration.empty_config_dict
|
config_dict = configuration.empty_config_dict
|
||||||
# If no arguments are passed, assume we are launching the GUI
|
# If no arguments are passed, assume we are launching the GUI
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
|
|
@ -372,7 +360,7 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
sys.exit(7)
|
sys.exit(7)
|
||||||
elif not config_dict:
|
elif not config_dict:
|
||||||
if len(sys.argv) == 1 and not _NO_GUI:
|
if len(sys.argv) == 1 and Globvars.GUI:
|
||||||
sg.Popup(_t("config_gui.bogus_config_file", config_file=CONFIG_FILE))
|
sg.Popup(_t("config_gui.bogus_config_file", config_file=CONFIG_FILE))
|
||||||
sys.exit(7)
|
sys.exit(7)
|
||||||
|
|
||||||
|
|
@ -507,7 +495,7 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
# EXIT_CODE 21 = current backup process already running
|
# EXIT_CODE 21 = current backup process already running
|
||||||
sys.exit(21)
|
sys.exit(21)
|
||||||
|
|
||||||
if not _NO_GUI:
|
if Globvars.GUI:
|
||||||
# When no argument is given, let's run the GUI
|
# When no argument is given, let's run the GUI
|
||||||
# Also, let's minimize the commandline window so the GUI user isn't distracted
|
# Also, let's minimize the commandline window so the GUI user isn't distracted
|
||||||
minimize_current_window()
|
minimize_current_window()
|
||||||
|
|
|
||||||
4
npbackup/globvars.py
Normal file
4
npbackup/globvars.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
print("hello global")
|
||||||
|
|
||||||
|
class Globvars(object):
|
||||||
|
GUI = None
|
||||||
Loading…
Add table
Reference in a new issue