@@ -82,7 +82,12 @@ def new(
8282
8383 env = jinja2 .Environment (
8484 loader = jinja2 .FileSystemLoader (
85- searchpath = get_ctf_script_templates_directory (), encoding = "utf-8"
85+ searchpath = (
86+ new_template_path := os .path .join (
87+ get_ctf_script_templates_directory (), "new"
88+ )
89+ ),
90+ encoding = "utf-8" ,
8691 )
8792 )
8893
@@ -106,7 +111,7 @@ def new(
106111 ipv6_address = f"216:3eff:fe{ rb [0 ]} { rb [1 ]} :{ rb [2 ]} { rb [3 ]} { rb [4 ]} { rb [5 ]} "
107112 full_ipv6_address = f"{ ipv6_subnet } :{ ipv6_address } "
108113
109- track_template = env .get_template (name = " track.yaml.j2" )
114+ track_template = env .get_template (name = os . path . join ( "common" , " track.yaml.j2") )
110115 render = track_template .render (
111116 data = {
112117 "name" : name ,
@@ -130,7 +135,7 @@ def new(
130135
131136 LOG .debug (msg = f"Directory { posts_directory } created." )
132137
133- track_template = env .get_template (name = " topic.yaml.j2" )
138+ track_template = env .get_template (name = os . path . join ( "common" , " topic.yaml.j2") )
134139 render = track_template .render (data = {"name" : name })
135140 with open (
136141 file = (p := os .path .join (posts_directory , f"{ name } .yaml" )),
@@ -141,7 +146,7 @@ def new(
141146
142147 LOG .debug (msg = f"Wrote { p } ." )
143148
144- track_template = env .get_template (name = " post.yaml.j2" )
149+ track_template = env .get_template (name = os . path . join ( "common" , " post.yaml.j2") )
145150 render = track_template .render (data = {"name" : name })
146151 with open (
147152 file = (p := os .path .join (posts_directory , f"{ name } _flag1.yaml" )),
@@ -170,7 +175,7 @@ def new(
170175
171176 LOG .debug (msg = f"Directory { terraform_directory } created." )
172177
173- track_template = env .get_template (name = " main.tf.j2" )
178+ track_template = env .get_template (name = os . path . join ( "common" , " main.tf.j2") )
174179
175180 render = track_template .render (
176181 data = {
@@ -215,7 +220,7 @@ def new(
215220
216221 LOG .debug (msg = f"Directory { ansible_directory } created." )
217222
218- track_template = env .get_template (name = f "deploy- { template } .yaml.j2" )
223+ track_template = env .get_template (name = os . path . join ( template , "deploy.yaml.j2" ) )
219224 render = track_template .render (data = {"name" : name })
220225 with open (
221226 file = (p := os .path .join (ansible_directory , "deploy.yaml" )),
@@ -226,7 +231,7 @@ def new(
226231
227232 LOG .debug (msg = f"Wrote { p } ." )
228233
229- track_template = env .get_template (name = " inventory.j2" )
234+ track_template = env .get_template (name = os . path . join ( "common" , " inventory.j2") )
230235 render = track_template .render (data = {"name" : name })
231236 with open (
232237 file = (p := os .path .join (ansible_directory , "inventory" )),
@@ -244,7 +249,9 @@ def new(
244249 LOG .debug (msg = f"Directory { ansible_challenge_directory } created." )
245250
246251 if template == Template .APACHE_PHP :
247- track_template = env .get_template (name = "index.php.j2" )
252+ track_template = env .get_template (
253+ name = os .path .join (Template .APACHE_PHP , "index.php.j2" )
254+ )
248255 render = track_template .render (data = {"name" : name })
249256 with open (
250257 file = (p := os .path .join (ansible_challenge_directory , "index.php" )),
@@ -256,7 +263,9 @@ def new(
256263 LOG .debug (msg = f"Wrote { p } ." )
257264
258265 if template == Template .PYTHON_SERVICE :
259- track_template = env .get_template (name = "app.py.j2" )
266+ track_template = env .get_template (
267+ name = os .path .join (Template .PYTHON_SERVICE , "app.py.j2" )
268+ )
260269 render = track_template .render (data = {"name" : name })
261270 with open (
262271 file = (p := os .path .join (ansible_challenge_directory , "app.py" )),
@@ -279,13 +288,19 @@ def new(
279288 if template == Template .RUST_WEBSERVICE :
280289 # Copy the entire challenge template
281290 shutil .copytree (
282- os .path .join (get_ctf_script_templates_directory (), "rust-webservice" ),
291+ os .path .join (
292+ new_template_path ,
293+ Template .RUST_WEBSERVICE ,
294+ "source" ,
295+ ),
283296 ansible_challenge_directory ,
284297 dirs_exist_ok = True ,
285298 )
286299 LOG .debug (msg = f"Wrote files to { ansible_challenge_directory } " )
287300
288- manifest_template = env .get_template (name = "Cargo.toml.j2" )
301+ manifest_template = env .get_template (
302+ name = os .path .join (Template .RUST_WEBSERVICE , "Cargo.toml.j2" )
303+ )
289304 render = manifest_template .render (data = {"name" : name })
290305 with open (
291306 file = (p := os .path .join (ansible_challenge_directory , "Cargo.toml" )),
0 commit comments