Skip to content

Commit 4e75ef8

Browse files
committed
add user group to task
1 parent 5cd0182 commit 4e75ef8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

myst_libre/tools/myst_client.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def check_mystmd_installed(self):
8282
self.cprint(f"✗ Unexpected error occurred: {str(e)}", "red")
8383
raise
8484

85-
def run_command(self, *args, env_vars={}):
85+
def run_command(self, *args, env_vars={},user=None,group=None):
8686
"""
8787
Run a command using the MyST executable.
8888
@@ -99,7 +99,15 @@ def run_command(self, *args, env_vars={}):
9999
env = os.environ.copy()
100100
env.update(env_vars)
101101

102-
process = subprocess.Popen(command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
102+
if user and group:
103+
uid = os.getpwnam(user).pw_uid
104+
gid = os.getgrnam(group).gr_gid
105+
process = subprocess.Popen(command, env=env,
106+
preexec_fn=lambda: os.setgid(gid) or os.setuid(uid),
107+
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
108+
else:
109+
process = subprocess.Popen(command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
110+
103111
output = []
104112
error_output = []
105113

@@ -131,7 +139,7 @@ def run_command(self, *args, env_vars={}):
131139
print(f"Unexpected error: {e}")
132140
return None
133141

134-
def build(self, *args):
142+
def build(self, *args, user=None, group=None):
135143
"""
136144
Build the MyST markdown project with specified arguments.
137145
@@ -143,9 +151,9 @@ def build(self, *args):
143151
"""
144152
os.chdir(self.build_dir)
145153
self.cprint(f"--> Self env vars {self.env_vars}", "green")
146-
return self.run_command(*args, env_vars=self.env_vars)
154+
return self.run_command(*args, env_vars=self.env_vars, user=user, group=group)
147155

148-
def convert(self, input_file, output_file):
156+
def convert(self, input_file, output_file, user=None, group=None):
149157
"""
150158
Convert a MyST markdown file to another format.
151159
@@ -156,4 +164,4 @@ def convert(self, input_file, output_file):
156164
Returns:
157165
str: Command output or None if failed.
158166
"""
159-
return self.run_command('convert', input_file, '-o', output_file,env_vars=[])
167+
return self.run_command('convert', input_file, '-o', output_file,env_vars=self.env_vars, user=user, group=group)

0 commit comments

Comments
 (0)