Skip to content

Commit 0dbabe8

Browse files
committed
Merge branch 'master' of github.com:PyconUK/ConferenceScheduler-cli
2 parents 12e3e28 + 0f3df60 commit 0dbabe8

File tree

2 files changed

+56
-17
lines changed

2 files changed

+56
-17
lines changed

src/scheduler/cli.py

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,34 @@
1616
logger = daiquiri.getLogger(__name__)
1717

1818

19+
def events_and_slots(resources):
20+
slots = defn.slots(resources)
21+
events = defn.events(resources)
22+
unavailability = defn.unavailability(resources, slots)
23+
clashes = defn.clashes(resources)
24+
unsuitability = defn.unsuitability(resources, slots)
25+
26+
defn.add_unavailability_to_events(events, slots, unavailability)
27+
defn.add_clashes_to_events(events, clashes)
28+
defn.add_unsuitability_to_events(events, slots, unsuitability)
29+
return events, slots
30+
31+
1932
@click.version_option(message='%(prog)s %(version)s :: UK Python Association')
2033
@click.group()
2134
@click.option(
2235
'--verbosity', '-v', default='info',
2336
type=click.Choice(['critical', 'error', 'warning', 'info', 'debug']),
2437
help='Logging verbosity')
2538
def scheduler(verbosity):
26-
logging.setup(verbosity)
39+
pass
2740

2841

2942
@scheduler.command()
43+
@click.option(
44+
'--verbosity', '-v', default='info',
45+
type=click.Choice(['critical', 'error', 'warning', 'info', 'debug']),
46+
help='Logging verbosity')
3047
@click.option(
3148
'--algorithm', '-a', default='pulp_cbc_cmd',
3249
type=click.Choice(
@@ -44,7 +61,10 @@ def scheduler(verbosity):
4461
@click.option(
4562
'--build_dir', '-b', default=None, help='Directory for output yaml files')
4663
@timed
47-
def build(algorithm, objective, diff, input_dir, solution_dir, build_dir):
64+
def build(
65+
verbosity, algorithm, objective, diff, input_dir, solution_dir, build_dir
66+
):
67+
logging.setup(verbosity)
4868
if input_dir:
4969
session.folders['input'] = Path(input_dir)
5070

@@ -55,16 +75,7 @@ def build(algorithm, objective, diff, input_dir, solution_dir, build_dir):
5575
session.folders['build'] = Path(build_dir)
5676

5777
resources = defn.resources()
58-
slots = defn.slots(resources)
59-
events = defn.events(resources)
60-
unavailability = defn.unavailability(resources, slots)
61-
clashes = defn.clashes(resources)
62-
unsuitability = defn.unsuitability(resources, slots)
63-
allocations = defn.allocations(resources)
64-
65-
defn.add_unavailability_to_events(events, slots, unavailability)
66-
defn.add_clashes_to_events(events, clashes)
67-
defn.add_unsuitability_to_events(events, slots, unsuitability)
78+
events, slots = events_and_slots(resources)
6879

6980
kwargs = {}
7081
if objective == 'consistency' or diff:
@@ -89,24 +100,47 @@ def build(algorithm, objective, diff, input_dir, solution_dir, build_dir):
89100
logger.debug(f'{item.event.name} has moved from {item.old_slot.venue} at {item.old_slot.starts_at} to {item.new_slot.venue} at {item.new_slot.starts_at}')
90101

91102
if solution is not None:
103+
allocations = defn.allocations(resources)
92104
defn.add_allocations(events, slots, solution, allocations)
93105
logger.debug(convert.schedule_to_text(solution, events, slots))
94106
io.export_solution_and_definition(resources, events, slots, solution)
95107
io.build_output(resources, events, slots, solution)
96108

97109

98110
@scheduler.command()
111+
@click.option(
112+
'--verbosity', '-v', default='info',
113+
type=click.Choice(['critical', 'error', 'warning', 'info', 'debug']),
114+
help='Logging verbosity')
115+
@click.option(
116+
'--input_dir', '-i', default=None, help='Directory for input files')
99117
@click.option(
100118
'--solution_dir', '-s', default=None, help='Directory for solution files')
119+
@click.option(
120+
'--reload/--no-reload', default=False, help='Reload YAML definition')
101121
@timed
102-
def validate(solution_dir):
122+
def validate(verbosity, input_dir, solution_dir, reload):
123+
logging.setup(verbosity)
103124
if solution_dir:
104125
session.folders['solution'] = Path(solution_dir)
105126

106127
solution = io.import_solution()
107-
definition = io.import_schedule_definition()
128+
129+
if reload:
130+
resources = defn.resources()
131+
events, slots = events_and_slots(resources)
132+
original_solution = io.import_solution()
133+
solution = [
134+
item for item in original_solution
135+
if item[0] < len(events)]
136+
else:
137+
solution = io.import_solution()
138+
definition = io.import_schedule_definition()
139+
events = definition['events']
140+
slots = definition['slots']
141+
108142
logger.info('Validating schedule...')
109-
if is_valid_solution(solution, definition['events'], definition['slots']):
143+
if is_valid_solution(solution, events, slots):
110144
logger.info('Imported solution is valid')
111145
else:
112146
for v in solution_violations(
@@ -115,12 +149,17 @@ def validate(solution_dir):
115149

116150

117151
@scheduler.command()
152+
@click.option(
153+
'--verbosity', '-v', default='info',
154+
type=click.Choice(['critical', 'error', 'warning', 'info', 'debug']),
155+
help='Logging verbosity')
118156
@click.option(
119157
'--solution_dir', '-s', default=None, help='Directory for solution files')
120158
@click.option(
121159
'--build_dir', '-b', default=None, help='Directory for output yaml files')
122160
@timed
123-
def rebuild(solution_dir, build_dir):
161+
def rebuild(verbosity, solution_dir, build_dir):
162+
logging.setup(verbosity)
124163
if solution_dir:
125164
session.folders['solution'] = Path(solution_dir)
126165

src/scheduler/define.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import daiquiri
77

88
import scheduler.denormalise as dn
9-
from scheduler import io, session
9+
from scheduler import io
1010

1111
logger = daiquiri.getLogger(__name__)
1212

0 commit comments

Comments
 (0)