Skip to content

Commit

Permalink
add user group to task
Browse files Browse the repository at this point in the history
  • Loading branch information
agahkarakuzu committed Nov 21, 2024
1 parent 5cd0182 commit 4e75ef8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions myst_libre/tools/myst_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def check_mystmd_installed(self):
self.cprint(f"✗ Unexpected error occurred: {str(e)}", "red")
raise

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

process = subprocess.Popen(command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if user and group:
uid = os.getpwnam(user).pw_uid
gid = os.getgrnam(group).gr_gid
process = subprocess.Popen(command, env=env,
preexec_fn=lambda: os.setgid(gid) or os.setuid(uid),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
else:
process = subprocess.Popen(command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)

output = []
error_output = []

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

def build(self, *args):
def build(self, *args, user=None, group=None):
"""
Build the MyST markdown project with specified arguments.
Expand All @@ -143,9 +151,9 @@ def build(self, *args):
"""
os.chdir(self.build_dir)
self.cprint(f"--> Self env vars {self.env_vars}", "green")
return self.run_command(*args, env_vars=self.env_vars)
return self.run_command(*args, env_vars=self.env_vars, user=user, group=group)

def convert(self, input_file, output_file):
def convert(self, input_file, output_file, user=None, group=None):
"""
Convert a MyST markdown file to another format.
Expand All @@ -156,4 +164,4 @@ def convert(self, input_file, output_file):
Returns:
str: Command output or None if failed.
"""
return self.run_command('convert', input_file, '-o', output_file,env_vars=[])
return self.run_command('convert', input_file, '-o', output_file,env_vars=self.env_vars, user=user, group=group)

0 comments on commit 4e75ef8

Please sign in to comment.