@@ -128,17 +128,26 @@ def apply_dark_theme(app: QApplication) -> None:
128
128
app .setPalette (QStyleFactory .create ('fusion' ).standardPalette ())
129
129
130
130
131
- def read_update_config_value (option : str , value , section : str = 'pupgui2' , config_file : str = CONFIG_FILE ) -> str :
132
-
131
+ def read_update_config_value (option : str , value = None , section : str = 'pupgui2' , config_file : str = CONFIG_FILE ) -> str | None :
133
132
"""
134
133
Uses ConfigParser to read a value with a given option from a given section from a given config file.
135
134
By default, will read a option and a value from the 'pupgui2' section in CONFIG_FILE path in constants.py.
135
+
136
+ Args:
137
+ option (str): The option to read from or update in the config file.
138
+ value (Any, optional): The value to write to the config file. If None, will read the value from the config file.
139
+ section (str, optional): The section to read from or update in the config file. Default is 'pupgui2'.
140
+ config_file (str, optional): The path to the config file. Default is CONFIG_FILE in constants.py.
141
+
142
+
143
+ Returns:
144
+ str | None: The value read from the config file or None if the option does not exist.
136
145
"""
137
146
138
147
config = ConfigParser ()
139
148
140
149
# Write value if given
141
- if value :
150
+ if value != None : # "!= None" is used to avoid false positives with empty strings
142
151
config .read (config_file )
143
152
if not config .has_section (section ):
144
153
config .add_section (section )
@@ -156,11 +165,11 @@ def read_update_config_value(option: str, value, section: str = 'pupgui2', confi
156
165
return value
157
166
158
167
159
- def config_theme (theme = None ) -> str :
168
+ def config_theme (theme = None ) -> str | None :
160
169
"""
161
170
Read/update config for the theme
162
171
Write theme to config or read if theme=None
163
- Return Type: str
172
+ Return Type: str | None
164
173
"""
165
174
166
175
return read_update_config_value ('theme' , theme , section = 'pupgui2' )
@@ -173,25 +182,23 @@ def config_advanced_mode(advmode=None) -> str:
173
182
Return Type: str
174
183
"""
175
184
176
- return read_update_config_value ('advancedmode' , advmode , section = 'pupgui2' )
185
+ return read_update_config_value ('advancedmode' , advmode , section = 'pupgui2' ) or ""
177
186
178
187
179
- def config_github_access_token (github_token = None ):
180
-
188
+ def config_github_access_token (github_token = None ) -> str :
181
189
"""
182
190
Read/update config for GitHub Access Token
183
191
"""
184
192
185
- return read_update_config_value ('github_api_token' , github_token , section = 'pupgui2' )
186
-
193
+ return read_update_config_value ('github_api_token' , github_token , section = 'pupgui2' ) or ""
187
194
188
- def config_gitlab_access_token (gitlab_token = None ):
189
195
196
+ def config_gitlab_access_token (gitlab_token = None ) -> str :
190
197
"""
191
198
Read/update config for GitLab Access Token
192
199
"""
193
200
194
- return read_update_config_value ('gitlab_api_token' , gitlab_token , section = 'pupgui2' )
201
+ return read_update_config_value ('gitlab_api_token' , gitlab_token , section = 'pupgui2' ) or ""
195
202
196
203
197
204
def create_compatibilitytools_folder () -> None :
0 commit comments