1
1
#!/usr/bin/env python
2
2
import argparse
3
3
import subprocess
4
- from typing import List
4
+ from typing import Dict
5
5
6
6
7
7
def _run_subprocess (
@@ -23,13 +23,6 @@ def _run_subprocess(
23
23
exit (err .returncode )
24
24
25
25
26
- def run_all (quiet = False ):
27
- print ("Run all deployment tasks..." )
28
- run_build (quiet = quiet )
29
- run_upload (quiet = quiet )
30
- print ("All tasks succeeded!" )
31
-
32
-
33
26
def run_build (quiet : bool ):
34
27
print ("Building thehive4py with the build module..." )
35
28
_run_subprocess (
@@ -52,14 +45,34 @@ def run_upload(quiet: bool):
52
45
print ("Successfully published thehive4py!" )
53
46
54
47
55
- def build_run_options () -> List [dict ]:
56
- return [
57
- {"name" : "build" , "help" : "run build step" , "func" : run_build },
58
- {"name" : "upload" , "help" : "run upload step" , "func" : run_upload },
59
- ]
48
+ def run_build_docs (quiet : bool ):
49
+ print ("Building thehive4py docs..." )
50
+ _run_subprocess (
51
+ command = "mkdocs build --clean --strict" ,
52
+ quiet = quiet ,
53
+ )
54
+ print ("Successfully built thehive4py docs!" )
60
55
61
56
62
- def parse_arguments (run_options : List [dict ]):
57
+ def run_deploy_docs (quiet : bool ):
58
+ print ("Deploying thehive4py docs to gh-pages..." )
59
+ _run_subprocess (
60
+ command = "mkdocs gh-deploy --force" ,
61
+ quiet = quiet ,
62
+ )
63
+ print ("Successfully deployed thehive4py docs to gh-pages!" )
64
+
65
+
66
+ def build_run_options () -> Dict [str , dict ]:
67
+ return {
68
+ "build" : {"help" : "build the package locally" , "func" : run_build },
69
+ "upload" : {"help" : "upload the package to pypi" , "func" : run_upload },
70
+ "build-docs" : {"help" : "build the docs locally" , "func" : run_build_docs },
71
+ "deploy-docs" : {"help" : "deploy the docs to gh-pages" , "func" : run_deploy_docs },
72
+ }
73
+
74
+
75
+ def parse_arguments (run_options : Dict [str , dict ]):
63
76
parser = argparse .ArgumentParser (
64
77
prog = "thehive4py-cd" ,
65
78
description = "run all cd steps or use options to run cd steps selectively" ,
@@ -72,14 +85,21 @@ def parse_arguments(run_options: List[dict]):
72
85
help = "silence verbose output" ,
73
86
)
74
87
75
- for run_option in run_options :
88
+ for run_option_name , run_option_attributes in run_options . items () :
76
89
parser .add_argument (
77
- f"--{ run_option [ 'name' ] } " ,
78
- help = run_option ["help" ],
90
+ f"--{ run_option_name . replace ( '_' , '-' ) } " ,
91
+ help = run_option_attributes ["help" ],
79
92
action = "store_true" ,
80
93
)
81
94
82
- return parser .parse_args ()
95
+ args = parser .parse_args ()
96
+
97
+ if not any (
98
+ getattr (args , run_option .replace ("-" , "_" )) for run_option in run_options
99
+ ):
100
+ parser .error (f"provide at least one option from: { list (run_options )} " )
101
+
102
+ return args
83
103
84
104
85
105
def main ():
@@ -88,17 +108,17 @@ def main():
88
108
89
109
quiet = args .quiet
90
110
91
- selective_runs = [
92
- run_option ["func" ]
93
- for run_option in run_options
94
- if getattr (args , run_option [ "name" ] )
111
+ selected_run_funcs = [
112
+ run_option_attributes ["func" ]
113
+ for run_option_name , run_option_attributes in run_options . items ()
114
+ if getattr (args , run_option_name . replace ( "-" , "_" ) )
95
115
]
96
116
97
- if selective_runs :
98
- for run in selective_runs :
99
- run ( quiet = quiet )
100
- else :
101
- run_all ( quiet = quiet )
117
+ for run_func in selected_run_funcs :
118
+ run_func ( quiet = quiet )
119
+ print ( )
120
+
121
+ print ( "Done!" )
102
122
103
123
104
124
if __name__ == "__main__" :
0 commit comments