88from pathlib import Path
99from typing import Any
1010
11+ from in2lambda .api .set import Set
1112from in2lambda .api .question import Question
1213
1314MINIMAL_QUESTION_TEMPLATE = "minimal_template_question.json"
1415MINIMAL_SET_TEMPLATE = "minimal_template_set.json"
1516
1617
17- def zip_sorted_folder (folder_path , zip_path ):
18+ def _zip_sorted_folder (folder_path , zip_path ):
1819 """Zips the contents of a folder, preserving the directory structure.
1920 Args:
2021 folder_path: The path to the folder to zip.
2122 zip_path: The path where the zip file will be created.
2223 """
2324 with zipfile .ZipFile (zip_path , 'w' ) as zf :
2425 for root , dirs , files in os .walk (folder_path ):
25- # Sort files for deterministic order
26+ # Sort files for deterministic, alphabetical order
2627 for file in sorted (files ):
2728 abs_path = os .path .join (root , file )
2829 rel_path = os .path .relpath (abs_path , folder_path )
2930 zf .write (abs_path , arcname = rel_path )
3031
3132def converter (
32- question_template : dict [str , Any ], set_template : dict [str , Any ], ListQuestions : list [ Question ] , output_dir : str
33+ question_template : dict [str , Any ], set_template : dict [str , Any ], SetQuestions : Set , output_dir : str
3334) -> None :
34- """Turns a list of question objects into Lambda Feedback JSON.
35+ """Turns a set of question objects into Lambda Feedback JSON.
3536
3637 Args:
3738 question_template: The loaded JSON from the minimal question template (it needs to be in sync).
3839 set_template: The loaded JSON from the minimal set template (it needs to be in sync).
39- ListQuestions : A list of question objects .
40+ SetQuestions : A Set object containing questions .
4041 output_dir: The absolute path for where to produced the final JSON/zip files.
4142 """
42- # Create output by copying template
43+ ListQuestions = SetQuestions .questions
44+ set_name = SetQuestions ._name
45+ set_description = SetQuestions ._description
4346
4447 # create directory to put the questions
4548 os .makedirs (output_dir , exist_ok = True )
46- output_question = os .path .join (output_dir , "set_a_simple_example" )
49+ output_question = os .path .join (output_dir , set_name )
4750 os .makedirs (output_question , exist_ok = True )
4851
52+
53+ set_template ["name" ] = set_name
54+ set_template ["description" ] = set_description
4955 # create the set file
50- with open (f"{ output_question } /set_a_simple_example .json" , "w" ) as file :
56+ with open (f"{ output_question } /set_ { set_name } .json" , "w" ) as file :
5157 json .dump (set_template , file )
52- shutil .make_archive (output_question , "zip" , output_question )
53-
5458
5559 for i in range (len (ListQuestions )):
5660 output = deepcopy (question_template )
@@ -97,16 +101,16 @@ def converter(
97101 shutil .copy (image_path , output_image ) # copies image into the directory
98102
99103 # output zip file in destination folder
100- zip_sorted_folder (output_question , output_question + ".zip" )
104+ _zip_sorted_folder (output_question , output_question + ".zip" )
101105
102106
103- def main (questions : list [ Question ] , output_dir : str ) -> None :
107+ def main (set_questions : Set , output_dir : str ) -> None :
104108 """Preliminary defensive programming before calling the main converter function.
105109
106110 This ultimately then produces the Lambda Feedback JSON/ZIP files.
107111
108112 Args:
109- questions : A list of question objects .
113+ set_questions : A Set object containing questions .
110114 output_dir: Where to output the final Lambda Feedback JSON/ZIP files.
111115 """
112116 # Use path so minimal template can be found regardless of where the user is running python from.
@@ -122,4 +126,4 @@ def main(questions: list[Question], output_dir: str) -> None:
122126 shutil .rmtree (output_dir )
123127 except OSError as e :
124128 print ("Error: %s : %s" % (output_dir , e .strerror ))
125- converter (question_template , set_template , questions , output_dir )
129+ converter (question_template , set_template , set_questions , output_dir )
0 commit comments