Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (9)
Tags (19)
master
allow_to_disable_logging
dependabot/npm_and_yarn/web-src/elliptic-6.6.0
dependabot/npm_and_yarn/web-src/vue-3.0.0
test-amd-build
stable
521-notice-parcing-failure_review_fixes
e2e_test_search_history
UI_test_scripts_group_display
dev
1.18.0
1.17.1
1.17.0
1.16.0
1.15.2
1.15.1
1.15.0
1.14.0
1.13.2
1.13.1
1.13.0
1.12.0
1.11.0
1.11.0-beta
1.10.1
1.10-rc2
1.10
1.9
master
Branches (9)
Tags (19)
master
allow_to_disable_logging
dependabot/npm_and_yarn/web-src/elliptic-6.6.0
dependabot/npm_and_yarn/web-src/vue-3.0.0
test-amd-build
stable
521-notice-parcing-failure_review_fixes
e2e_test_search_history
UI_test_scripts_group_display
dev
1.18.0
1.17.1
1.17.0
1.16.0
1.15.2
1.15.1
1.15.0
1.14.0
1.13.2
1.13.1
1.13.0
1.12.0
1.11.0
1.11.0-beta
1.10.1
1.10-rc2
1.10
1.9
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (9)
Tags (19)
master
allow_to_disable_logging
dependabot/npm_and_yarn/web-src/elliptic-6.6.0
dependabot/npm_and_yarn/web-src/vue-3.0.0
test-amd-build
stable
521-notice-parcing-failure_review_fixes
e2e_test_search_history
UI_test_scripts_group_display
dev
1.18.0
1.17.1
1.17.0
1.16.0
1.15.2
1.15.1
1.15.0
1.14.0
1.13.2
1.13.1
1.13.0
1.12.0
1.11.0
1.11.0-beta
1.10.1
1.10-rc2
1.10
1.9
script-server
/
src
/
execution
/
executor.py
script-server
/
src
/
execution
/
executor.py
executor.py 11.47 KB
Copy Edit Raw Blame History
ClarkeAC authored 2024年08月19日 14:07 +08:00 . fixed invalid escape sequence error, 11 more
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
import logging
import re
import sys
from typing import List
from execution import process_popen, process_base
from model import model_helper
from model.model_helper import read_bool
from model.parameter_config import ParameterModel
from model.script_config import ConfigModel
from react.observable import ObservableBase
from utils import file_utils, process_utils, os_utils, string_utils
from utils.env_utils import EnvVariables
from utils.transliteration import transliterate
TIME_BUFFER_MS = 100
LOGGER = logging.getLogger('script_server.ScriptExecutor')
mock_process = False
def create_process_wrapper(executor, command, working_directory, all_env_variables):
run_pty = executor.config.requires_terminal
if run_pty and not os_utils.is_pty_supported():
LOGGER.warning(
"Requested PTY mode, but it's not supported for this OS (" + sys.platform + '). Falling back to POpen')
run_pty = False
if run_pty:
from execution import process_pty
process_wrapper = process_pty.PtyProcessWrapper(command, working_directory, all_env_variables)
else:
process_wrapper = process_popen.POpenProcessWrapper(command, working_directory, all_env_variables)
return process_wrapper
_process_creator = create_process_wrapper
def _normalize_working_dir(working_directory):
if working_directory is None:
return None
return file_utils.normalize_path(working_directory)
class ScriptExecutor:
def __init__(self, config: ConfigModel, env_vars: EnvVariables):
self.config = config
self._env_vars = env_vars
self._parameter_values = dict(config.parameter_values)
self._working_directory = _normalize_working_dir(config.working_directory)
self.script_base_command = process_utils.split_command(
self.config.script_command,
self._working_directory)
self.secure_replacements = self.__init_secure_replacements()
self.process_wrapper = None # type: process_base.ProcessWrapper
self.raw_output_stream = None
self.protected_output_stream = None
def start(self, execution_id):
if self.process_wrapper is not None:
raise Exception('Executor already started')
parameter_values = self.get_script_parameter_values()
script_args = build_command_args(parameter_values, self.config)
command = self.script_base_command + script_args
env_variables = _build_env_variables(parameter_values, self.config.parameters, execution_id)
all_env_variables = self._env_vars.build_env_vars(env_variables)
process_wrapper = _process_creator(self, command, self._working_directory, all_env_variables)
process_wrapper.start()
self.process_wrapper = process_wrapper
output_stream = process_wrapper.output_stream.time_buffered(TIME_BUFFER_MS, _concat_output)
self.raw_output_stream = output_stream.replay()
send_stdin_parameters(self.config.parameters, parameter_values, self.raw_output_stream, process_wrapper)
if self.secure_replacements:
self.protected_output_stream = output_stream \
.map(self.__replace_secure_variables) \
.replay()
else:
self.protected_output_stream = self.raw_output_stream
def __init_secure_replacements(self):
word_replacements = {}
for parameter in self.config.parameters:
if not parameter.secure:
continue
value = self._parameter_values.get(parameter.name)
if value is None:
continue
mapped_value = value.mapped_script_value
if model_helper.is_empty(mapped_value):
continue
if isinstance(mapped_value, list):
elements = mapped_value
else:
elements = [mapped_value]
for value_element in elements:
element_string = str(value_element)
if not element_string.strip():
continue
value_pattern = r'((?<!\w)|^)' + re.escape(element_string) + r'((?!\w)|$)'
word_replacements[value_pattern] = model_helper.SECURE_MASK
return word_replacements
def __replace_secure_variables(self, output):
result = output
replacements = self.secure_replacements
if replacements:
for word, replacement in replacements.items():
result = re.sub(word, replacement, result)
return result
def get_secure_command(self):
audit_script_args = build_command_args(
{name: v.get_secure_value() for name, v in self._parameter_values.items()},
self.config)
audit_script_args = [str(a) for a in audit_script_args]
command = self.script_base_command + audit_script_args
return ' '.join(command)
def get_anonymized_output_stream(self):
return self.protected_output_stream
def get_raw_output_stream(self):
return self.raw_output_stream
def get_process_id(self):
return self.process_wrapper.get_process_id()
def get_return_code(self):
return self.process_wrapper.get_return_code()
def is_finished(self):
return self.process_wrapper.is_finished()
def add_finish_listener(self, listener):
self.process_wrapper.add_finish_listener(listener)
def write_to_input(self, text):
if self.process_wrapper.is_finished():
LOGGER.warning('process already finished, ignoring input')
return
self.process_wrapper.write_to_input(text)
def get_user_parameter_values(self):
return {name: value.user_value
for name, value in self._parameter_values.items()
if value.user_value is not None}
def get_script_parameter_values(self):
return {name: value.script_arg for name, value in self._parameter_values.items()}
def kill(self):
if not self.process_wrapper.is_finished():
self.process_wrapper.kill()
def stop(self):
if not self.process_wrapper.is_finished():
self.process_wrapper.stop()
def cleanup(self):
self.raw_output_stream.dispose()
self.protected_output_stream.dispose()
self.process_wrapper.cleanup()
def build_command_args(param_values, config):
result = []
for parameter in config.parameters:
name = parameter.name
option_name = parameter.param
if not parameter.pass_as.pass_as_argument():
continue
if name in param_values:
value = param_values[name]
if parameter.no_value:
if value is True and option_name:
result.append(option_name)
elif value:
if option_name:
if isinstance(value, list):
if len(value) == 0:
continue
if parameter.multiselect_argument_type == 'argument_per_value':
if parameter.same_arg_param:
result.append(option_name + str(value[0]))
result.extend(value[1:])
else:
result.append(option_name)
result.extend(value)
elif parameter.multiselect_argument_type == 'repeat_param_value':
if parameter.same_arg_param:
for el in value:
result.append(option_name + str(el))
else:
for el in value:
result.append(option_name)
result.append(el)
else:
if parameter.same_arg_param:
result.append(option_name + str(value))
else:
result.append(option_name)
result.append(value)
else:
if isinstance(value, list):
result.extend(value)
else:
result.append(value)
return result
def _to_env_name(key):
transliterated = transliterate(key)
replaced = re.sub('[^0-9a-zA-Z_]+', '_', transliterated)
if replaced == '_':
return None
return 'PARAM_' + replaced.upper()
def _build_env_variables(parameter_values, parameters: List[ParameterModel], execution_id):
result = {}
excluded = []
for param_name, value in parameter_values.items():
if isinstance(value, list) or (value is None):
continue
found_parameters = [p for p in parameters if p.name == param_name]
if len(found_parameters) != 1:
continue
parameter = found_parameters[0]
if not parameter.pass_as.pass_as_env_variable():
continue
env_var = parameter.env_var
if env_var is None:
env_var = _to_env_name(param_name)
if (not env_var) or (env_var in excluded):
continue
if env_var in result:
excluded.append(env_var)
del result[env_var]
continue
if parameter.no_value:
if (value is not None) and (read_bool(value) == True):
result[env_var] = 'true'
continue
result[env_var] = str(value)
if 'EXECUTION_ID' not in result:
result['EXECUTION_ID'] = str(execution_id)
return result
def _concat_output(output_chunks):
if not output_chunks:
return output_chunks
return [''.join(output_chunks)]
def send_stdin_parameters(
parameters: List[ParameterModel],
parameter_values,
raw_output_stream: ObservableBase,
process_wrapper):
for parameter in parameters:
if not parameter.pass_as.pass_as_stdin():
continue
value = parameter_values.get(parameter.name)
if value is None:
continue
if parameter.no_value:
if read_bool(value):
value = 'true'
else:
value = 'false'
if isinstance(value, list):
value = ','.join(string_utils.values_to_string(value))
if not parameter.stdin_expected_text:
process_wrapper.write_to_input(value)
else:
raw_output_stream.subscribe(_ExpectedTextListener(
parameter.stdin_expected_text,
lambda closed_value=value: process_wrapper.write_to_input(closed_value)))
class _ExpectedTextListener:
def __init__(self, expected_text, callback):
self.expected_text = expected_text
self.callback = callback
self.buffer = ''
self.first_char = expected_text[0]
self.value_sent = False
def on_next(self, output):
if self.value_sent:
return
full_text = self.buffer + output
while True:
start_index = full_text.find(self.first_char)
if start_index < 0:
self.buffer = ''
return
full_text = full_text[start_index:]
if len(full_text) < len(self.expected_text):
self.buffer = full_text
return
if full_text.startswith(self.expected_text):
self.callback()
self.value_sent = True
return
full_text = full_text[1:]
def on_close(self):
pass
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Web UI for your scripts with execution management
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fxh/script-server.git
git@gitee.com:fxh/script-server.git
fxh
script-server
script-server
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /