Skip to content

Commit

Permalink
#3964 add config file tools
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 11, 2023
1 parent 70747b8 commit fa0b859
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions xpra/gtk/configure/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def populate(self):



def main() -> int:
def main(_args) -> int:
from xpra.gtk.configure.main import run_gui
return run_gui(ConfigureGUI)

if __name__ == "__main__":
import sys
sys.exit(main())
sys.exit(main(sys.argv[1:]))
4 changes: 2 additions & 2 deletions xpra/gtk/configure/gstreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def understood(self, *args):
self.populate()


def main() -> int:
def main(_args) -> int:
from xpra.gtk.configure.main import run_gui
return run_gui(ConfigureGUI)

if __name__ == "__main__":
import sys
sys.exit(main())
sys.exit(main(sys.argv[1:]))
41 changes: 38 additions & 3 deletions xpra/gtk/configure/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# Copyright (C) 2018-2023 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import os.path
from importlib import import_module
import gi

from xpra.scripts.config import InitExit
from xpra.exit_codes import ExitCode
from xpra.gtk.dialogs.base_gui_window import BaseGUIWindow
from xpra.gtk.widget import label
from xpra.log import Logger
Expand Down Expand Up @@ -63,10 +65,43 @@ def run_gui(gui_class=ConfigureGUI) -> int:
log("do_main() gui.exit_code=%i", gui.exit_code)
return 0

def main() -> int:

def get_user_config_file():
from xpra.platform.paths import get_user_conf_dirs
return os.path.join(get_user_conf_dirs()[0], "99_configure_tool.conf")


def main(args) -> ExitCode:
if args:
conf = get_user_config_file()
subcommand = args[0]
if subcommand=="reset":
import datetime
now = datetime.datetime.now()
with open(conf, "w", encoding="utf8") as f:
f.write("# this file was reset on "+now.strftime("%Y-%m-%d %H:%M:%S"))
return ExitCode.OK
elif subcommand == "backup":
if not os.path.exists(conf):
print(f"# {conf!r} does not exist yet")
return ExitCode.FILE_NOT_FOUND
bak = conf[-5:]+".bak"
with open(conf, "r", encoding="utf8") as read:
with open(bak, "w", encoding="utf8") as write:
write.write(read.read())
return ExitCode.OK
elif subcommand=="show":
if not os.path.exists(conf):
print(f"# {conf!r} does not exist yet")
else:
with open(conf, "r", encoding="utf8") as f:
print(f.read())
return ExitCode.OK
else:
raise InitExit(ExitCode.FILE_NOT_FOUND, f"unknown configure subcommand {subcommand!r}")
return run_gui(ConfigureGUI)


if __name__ == "__main__":
import sys
sys.exit(main())
sys.exit(int(main(sys.argv[1:])))
5 changes: 3 additions & 2 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3928,12 +3928,13 @@ def run_configure(args) -> ExitValue:
mod = "main"
if args:
mod = args[0]
valid = ("gstreamer", "encodings", "features")
valid = ("main", "gstreamer", "encodings", "features")
if mod not in valid:
raise ValueError(f"unsupported 'configure' argument {mod}, must be one of {csv(valid)}")
args = args[1:]
from importlib import import_module
mod = import_module(f"xpra.gtk.configure.{mod}")
return mod.main()
return mod.main(args)


def run_showconfig(options, args) -> ExitValue:
Expand Down

0 comments on commit fa0b859

Please sign in to comment.