Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit045c1ee

Browse files
committed
feat(exec-options): add use_shell and encoding options to command execution
1 parent5d48c3f commit045c1ee

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

‎src/core/validation/widgets/yasb/custom.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
'run_once':False,
66
'run_interval':0,
77
'return_format':"json",
8-
'hide_empty':False
8+
'hide_empty':False,
9+
'use_shell':True,
10+
'encoding':None
911
},
1012
'animation': {
1113
'enabled':True,
@@ -66,6 +68,15 @@
6668
'type':'boolean',
6769
'required':False,
6870
'default':DEFAULTS['exec_options']['hide_empty']
71+
},
72+
'use_shell': {
73+
'type':'boolean',
74+
'default':DEFAULTS['exec_options']['use_shell']
75+
},
76+
'encoding': {
77+
'type':'string',
78+
'nullable':True,
79+
'default':DEFAULTS['exec_options']['encoding']
6980
}
7081
},
7182
'default':DEFAULTS['exec_options']

‎src/core/widgets/yasb/custom.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ class CustomWorker(QObject):
1313
finished=pyqtSignal()
1414
data_ready=pyqtSignal(object)
1515

16-
def__init__(self,cmd,return_type,hide_empty):
16+
def__init__(self,cmd,use_shell,encoding,return_type,hide_empty):
1717
super().__init__()
1818
self.cmd=cmd
19+
self.use_shell=use_shell
20+
self.encoding=encoding
1921
self.return_type=return_type
2022
self.hide_empty=hide_empty
2123

2224
defrun(self):
2325
exec_data=None
2426
ifself.cmd:
25-
proc=subprocess.Popen(self.cmd,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,creationflags=subprocess.CREATE_NO_WINDOW,shell=True)
27+
proc=subprocess.Popen(self.cmd,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,creationflags=subprocess.CREATE_NO_WINDOW,shell=self.use_shell,encoding=self.encoding)
2628
output=proc.stdout.read()
2729
ifself.return_type=="json":
2830
try:
@@ -53,6 +55,8 @@ def __init__(
5355
self._exec_data=None
5456
self._exec_cmd=exec_options['run_cmd'].split(" ")ifexec_options.get('run_cmd',False)elseNone
5557
self._exec_return_type=exec_options['return_format']
58+
self._exec_shell=exec_options['use_shell']
59+
self._exec_encoding=exec_options['encoding']
5660
self._hide_empty=exec_options['hide_empty']
5761
self._show_alt_label=False
5862
self._label_content=label
@@ -160,7 +164,7 @@ def _update_label(self):
160164

161165
def_exec_callback(self):
162166
ifself._exec_cmd:
163-
worker=CustomWorker(self._exec_cmd,self._exec_return_type,self._hide_empty)
167+
worker=CustomWorker(self._exec_cmd,self._exec_shell,self._exec_encoding,self._exec_return_type,self._hide_empty)
164168
worker_thread=threading.Thread(target=worker.run)
165169
worker.data_ready.connect(self._handle_exec_data)
166170
worker.finished.connect(worker.deleteLater)
@@ -186,4 +190,4 @@ def _cb_execute_subprocess(self, cmd: str, *cmd_args: list[str]):
186190
ifcmdinfunction_map:
187191
function_map[cmd]()
188192
else:
189-
subprocess.Popen([cmd,*cmd_args]ifcmd_argselse [cmd],shell=True)
193+
subprocess.Popen([cmd,*cmd_args]ifcmd_argselse [cmd],shell=self._exec_shell,encoding=self._exec_encoding)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp