-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.py
86 lines (75 loc) · 2.11 KB
/
scripts.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sys
import subprocess
import shutil
import os
def download_python_template():
try:
subprocess.run([
"openapi-generator-cli",
"author",
"template",
"-g",
"python",
"--library",
"urllib3",
])
except Exception as e:
print("Exception when generating package: %s\n" % e)
def generate_package():
try:
subprocess.run([
"openapi-generator-cli",
"generate",
"-g",
"python",
"--library",
"urllib3",
"-t",
"lib_template",
"-o",
"src",
"-i",
"openapi.yaml",
"-c",
"config.json"
])
except Exception as e:
print("Exception when generating package: %s\n" % e)
def build_distro_package():
try:
os.chdir("src/")
# Check if the 'dist/' folder exists
if os.path.exists("dist"):
# If it exists, delete it and its contents
shutil.rmtree("dist")
# Upgrade the 'build' module
subprocess.run([
"python3",
"-m",
"pip",
"install",
"--upgrade",
"build"
])
# Generate a new 'dist/' folder
subprocess.run([
"python3",
"-m",
"build"
])
except Exception as e:
print("Exception when building distro package: %s\n" % e)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python3 scripts.py [download_python_template | generate_package | build_distro_package]")
sys.exit(1)
script_to_run = sys.argv[1]
if script_to_run == "download_python_template":
download_python_template()
elif script_to_run == "generate_package":
generate_package()
elif script_to_run == "build_distro_package":
build_distro_package()
else:
print("Invalid script name. Use one of: download_python_template, generate_package, build_distro_package")
sys.exit(1)