Skip to content

Commit

Permalink
修复 execute/execfile sudo 选项
Browse files Browse the repository at this point in the history
  • Loading branch information
souloss committed Oct 27, 2021
1 parent 492fe82 commit a17ee36
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pypssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ def execute(command, needpty, sudo, outmode, template):
"""
execute command
"""
if sudo:
for i in TARGET:
i.sudo = sudo
result = []
if needpty:
result = concurrent(
Expand Down Expand Up @@ -468,10 +471,10 @@ def execfile(ctx, script_file, script_arg, env, attachment, workdir, needpty, su
script_env = ''.join(["export %s && " % item for item in env])
script_arg_str = ' '.join(script_arg)
command = f"{script_env} cd {workdir} && chmod +x {remote_file} && {remote_file} {script_arg_str}"
ctx.invoke(execute, command=command, outmode=outmode, template=template)
ctx.invoke(execute, command=command, outmode=outmode, template=template, sudo=sudo)
finally:
command = f"rm -rf {' '.join(put_files)}"
ctx.invoke(execute, command=command, outmode=outmode, template=template)
ctx.invoke(execute, command=command, outmode=outmode, template=template, sudo=sudo)

put_default_template = "{{src}} =====> {{hostname}}:{{dst}} {% if completed %} successfully! {% else %} faild! {% endif %}"

Expand Down

0 comments on commit a17ee36

Please sign in to comment.