-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.py
58 lines (42 loc) · 1.45 KB
/
manage.py
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
import subprocess
def read_config():
import json
# Opening JSON file
f = open('./config.json')
# returns JSON object as
# a dictionary
data = json.load(f)
f.close()
return data
def parse_args():
# putting import inside so that code can be moved to saperate files and we dont keep the import at top of this file
import argparse
# Create the argument parser
parser = argparse.ArgumentParser(description='Lazy Dev Argguments')
# Add the "--task" argument with the "-t" shortcut
parser.add_argument('--run', '-r', type=str, help='The script to run')
args = parser.parse_args()
return args
def execute_config_script(script_name:str,config:dict):
scripts:dict=config['scripts']
command:str=scripts[script_name]
# Execute the command
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# Check the return code
if result.returncode == 0:
# Command was successful
print("Command executed successfully.")
# Print the command output
print("Command output:")
print(result.stdout)
else:
# Command failed
print("Command failed with return code:", result.returncode)
# Print the error message
print("Error message:")
print(result.stderr)
if __name__ == "__main__":
args=parse_args()
command = args.run
config=read_config()
execute_config_script(command,config)