6
6
import os .path
7
7
from importlib import import_module
8
8
9
+ from xpra .gtk .configure .common import get_user_config_file
9
10
from xpra .scripts .config import InitExit
10
11
from xpra .exit_codes import ExitCode
11
12
from xpra .os_util import gi_import
12
- from xpra .util .parsing import parse_simple_dict
13
13
from xpra .gtk .dialogs .base_gui_window import BaseGUIWindow
14
14
from xpra .gtk .widget import label
15
15
from xpra .log import Logger
@@ -29,18 +29,19 @@ def __init__(self):
29
29
default_size = (480 , 300 ),
30
30
header_bar = (True , False ),
31
31
)
32
- self .dialogs : dict [str ,BaseGUIWindow ] = {}
32
+ self .dialogs : dict [str , BaseGUIWindow ] = {}
33
33
34
34
def populate (self ):
35
35
self .vbox .add (label ("Configure Xpra" , font = "sans 20" ))
36
36
self .vbox .add (label ("Tune your xpra configuration:" , font = "sans 14" ))
37
- self .sub ("Features" , "features.png" ,"Enable or disable feature groups" , "features" )
38
- self .sub ("Picture compression" , "encoding.png" ,"Encodings, speed and quality" , "encodings" )
39
- self .sub ("GStreamer" , "gstreamer.png" ,"Configure the GStreamer codecs" , "gstreamer" )
40
- self .sub ("OpenGL acceleration" , "opengl.png" ,"Test and validate OpenGL renderer" , "opengl" )
37
+ self .sub ("Features" , "features.png" , "Enable or disable feature groups" , "features" )
38
+ self .sub ("Picture compression" , "encoding.png" , "Encodings, speed and quality" , "encodings" )
39
+ self .sub ("GStreamer" , "gstreamer.png" , "Configure the GStreamer codecs" , "gstreamer" )
40
+ self .sub ("OpenGL acceleration" , "opengl.png" , "Test and validate OpenGL renderer" , "opengl" )
41
41
42
- def sub (self , title = "" , icon_name = "browse.png" , tooltip = "" , configure :str = "" ) -> None :
43
- def callback (btn ):
42
+ def sub (self , title = "" , icon_name = "browse.png" , tooltip = "" , configure : str = "" ) -> None :
43
+
44
+ def callback (_btn ):
44
45
dialog = self .dialogs .get (configure )
45
46
if dialog is None :
46
47
mod = import_module (f"xpra.gtk.configure.{ configure } " )
@@ -68,29 +69,11 @@ def run_gui(gui_class=ConfigureGUI) -> int:
68
69
return 0
69
70
70
71
71
- def get_user_config_file () -> str :
72
- from xpra .platform .paths import get_user_conf_dirs
73
- return os .path .join (get_user_conf_dirs ()[0 ], "99_configure_tool.conf" )
74
-
75
- def parse_user_config_file () -> dict :
76
- filename = get_user_config_file ()
77
- if not os .path .exists (filename ):
78
- return {}
79
- with open (filename , "r" , encoding = "utf8" ) as f :
80
- return parse_simple_dict (f .read ())
81
-
82
- def save_user_config_file (options :dict ) -> None :
83
- filename = get_user_config_file ()
84
- with open (filename , "w" , encoding = "utf8" ) as f :
85
- for k ,v in options .items ():
86
- f .write (f"{ k } = { v } " )
87
-
88
-
89
72
def main (args ) -> ExitCode :
90
73
if args :
91
74
conf = get_user_config_file ()
92
75
subcommand = args [0 ]
93
- if subcommand == "reset" :
76
+ if subcommand == "reset" :
94
77
import datetime
95
78
now = datetime .datetime .now ()
96
79
with open (conf , "w" , encoding = "utf8" ) as f :
@@ -105,15 +88,21 @@ def main(args) -> ExitCode:
105
88
with open (bak , "w" , encoding = "utf8" ) as write :
106
89
write .write (read .read ())
107
90
return ExitCode .OK
108
- elif subcommand == "show" :
91
+ elif subcommand == "show" :
109
92
if not os .path .exists (conf ):
110
93
print (f"# { conf !r} does not exist yet" )
111
94
else :
112
95
with open (conf , "r" , encoding = "utf8" ) as f :
113
96
print (f .read ())
114
97
return ExitCode .OK
115
98
else :
116
- raise InitExit (ExitCode .FILE_NOT_FOUND , f"unknown configure subcommand { subcommand !r} " )
99
+ if any (not str .isalnum (x ) for x in subcommand ):
100
+ raise ValueError ("invalid characters found in subcommand" )
101
+ from importlib import import_module
102
+ mod = import_module (f"xpra.gtk.configure.{ subcommand } " )
103
+ if not mod :
104
+ raise InitExit (ExitCode .FILE_NOT_FOUND , f"unknown configure subcommand { subcommand !r} " )
105
+ return mod .main (args [1 :])
117
106
return run_gui (ConfigureGUI )
118
107
119
108
0 commit comments