99from ruamel .yaml import YAML
1010from slugify import slugify
1111
12- from scheduler import session
13-
1412logger = daiquiri .getLogger (__name__ )
1513yaml = YAML (typ = 'safe' )
1614yaml .default_flow_style = False
1715
1816
19- def import_yaml ():
17+ def import_yaml (input_folder ):
2018 """Import all yaml files in the given folder into a single resources
2119 dict"""
2220 yaml_resources = {}
2321 yaml_files = [
24- path for path in session . folders [ 'input' ] .iterdir ()
22+ path for path in input_folder .iterdir ()
2523 if path .suffix == '.yml' ]
2624 for path in yaml_files :
2725 with path .open ('r' ) as file :
@@ -30,10 +28,10 @@ def import_yaml():
3028 return yaml_resources
3129
3230
33- def import_proposals (resources ):
31+ def import_proposals (resources , input_folder ):
3432 """Import the proposals data from a .csv file"""
3533 proposals = []
36- with Path (session . folders [ 'input' ] , 'proposals.csv' ).open ('r' ) as file :
34+ with Path (input_folder , 'proposals.csv' ).open ('r' ) as file :
3735 reader = csv .DictReader (file )
3836 for row in reader :
3937 if row ['session_type' ] in resources ['event_types' ]:
@@ -50,9 +48,9 @@ def import_proposals(resources):
5048 return proposals
5149
5250
53- def import_solution ():
51+ def import_solution (solution_folder ):
5452 """Import a previously computed schedule from a .csv file"""
55- csv_file = Path (session . folders [ 'solution' ] , 'schedule.csv' )
53+ csv_file = Path (solution_folder , 'schedule.csv' )
5654 logger .info (f'Importing schedule from { csv_file } ' )
5755 solution = []
5856 with Path (csv_file ).open ('r' ) as file :
@@ -65,20 +63,22 @@ def import_solution():
6563 return solution
6664
6765
68- def import_schedule_definition ():
66+ def import_schedule_definition (solution_folder ):
6967 """Import previously pickled schedule"""
70- pickle_file = Path (session . folders [ 'solution' ] , 'scheduler.pickle' )
68+ pickle_file = Path (solution_folder , 'scheduler.pickle' )
7169 logger .info (
7270 f'Importing resources, events, slots and schedule from { pickle_file } ' )
7371 with pickle_file .open ('rb' ) as f :
7472 bundle = pickle .load (f )
7573 return bundle
7674
7775
78- def pickle_solution_and_definition (resources , events , slots , solution ):
76+ def pickle_solution_and_definition (
77+ resources , events , slots , solution , solution_folder
78+ ):
7979 """Store the computed solution, the resources dict and the associated
8080 events and slots lists in pickle format"""
81- pickle_file = Path (session . folders [ 'solution' ] , 'scheduler.pickle' )
81+ pickle_file = Path (solution_folder , 'scheduler.pickle' )
8282 logger .info (
8383 f'Pickling resources, events, slots and schedule to { pickle_file } ' )
8484 bundle = {
@@ -91,9 +91,9 @@ def pickle_solution_and_definition(resources, events, slots, solution):
9191 pickle .dump (bundle , f , pickle .HIGHEST_PROTOCOL )
9292
9393
94- def export_schedule (solution , events , slots ):
94+ def export_schedule (solution , events , slots , solution_folder ):
9595 """Write a human readable .csv file of the computed solution"""
96- csv_file = Path (session . folders [ 'solution' ] , 'schedule.csv' )
96+ csv_file = Path (solution_folder , 'schedule.csv' )
9797 logger .info (f'Exporting schedule to { csv_file } ' )
9898
9999 schedule = converter .solution_to_schedule (solution , events , slots )
@@ -114,18 +114,21 @@ def export_schedule(solution, events, slots):
114114 writer .writerow (item )
115115
116116
117- def export_solution_and_definition (resources , events , slots , solution ):
118- session .folders ['solution' ].mkdir (exist_ok = True )
119- pickle_solution_and_definition (resources , events , slots , solution )
120- export_schedule (solution , events , slots )
117+ def export_solution_and_definition (
118+ resources , events , slots , solution , solution_folder
119+ ):
120+ solution_folder .mkdir (exist_ok = True )
121+ pickle_solution_and_definition (
122+ resources , events , slots , solution , solution_folder )
123+ export_schedule (solution , events , slots , solution_folder )
121124
122125
123- def build_output (resources , events , slots , solution ):
126+ def build_output (resources , events , slots , solution , build_folder ):
124127 """Create the yaml files required by the conference django-amber based
125128 website for display of the programme"""
126- logger .info (f'Creating output files in { session . folders [ "build" ] } ...' )
127- shutil .rmtree (session . folders [ 'build' ] , ignore_errors = True )
128- session . folders [ 'build' ] .mkdir ()
129+ logger .info (f'Creating output files in { build_folder } ...' )
130+ shutil .rmtree (build_folder , ignore_errors = True )
131+ build_folder .mkdir ()
129132
130133 day_format = '%A %-d'
131134 start_format = '%H:%M'
@@ -144,7 +147,7 @@ def build_output(resources, events, slots, solution):
144147 'title' : events [item [0 ]].name ,
145148 }
146149
147- folder = Path (session . folders [ 'build' ] , day , venue )
150+ folder = Path (build_folder , day , venue )
148151 folder .mkdir (parents = True , exist_ok = True )
149152 with Path (folder , start_time ).open ('a' ) as f :
150153 yaml .dump (content , f )
0 commit comments