#! /usr/bin/python3 import argparse import yaml import os import subprocess import sys def runcmd(command): print('RUN ' + command) process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) for line in iter(process.stdout.readline, b''): # b'' indicates EOF print(line.decode('utf-8'), end='') # Read environment variable parser = argparse.ArgumentParser() parser.add_argument('--password') args = parser.parse_args() new_password = args.password if not isinstance(new_password , str): print('ERROR: expect the password to be a string') sys.exit(1) # Read code-server configuration and adjust the password according to ENV code_server_config_path = '.config/code-server/config.yaml'; code_server_config = None with open(code_server_config_path, 'r') as file: code_server_config = yaml.safe_load(file) if code_server_config is not None: code_server_config['password'] = new_password with open(code_server_config_path, 'w') as file: yaml.dump(code_server_config, file) runcmd('code-server /workspace') sys.exit(0)