[buildout]
parts =
  cli
  demo
  manual-flight

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true

[directory]
recipe = slapos.cookbook:mkdirectory
home = $${buildout:directory}
etc = $${:home}/etc
var = $${:home}/var
log = $${:var}/log

[slap-configuration]
recipe = slapos.cookbook:slapconfiguration
computer = $${slap_connection:computer_id}
partition = $${slap_connection:partition_id}
url = $${slap_connection:server_url}
key = $${slap_connection:key_file}
cert = $${slap_connection:cert_file}

[drone]
recipe = slapos.recipe.build
slapparameter-dict = $${slap-configuration:configuration}
init =
  options['autopilot-ip'] = options['slapparameter-dict'].get('autopilot_ip', '192.168.27.1')
  options['id'] = options['slapparameter-dict'].get('id', '1')
  options['is-a-simulation'] = options['slapparameter-dict'].get('is_a_simulation', 'false')
  options['leader-id'] = options['slapparameter-dict'].get('leader_id', '1')
  options['is-leader'] = 'true' if options['id'] == options['leader-id'] else 'false'
  options['multicast-ipv6'] = options['slapparameter-dict'].get('multicast_ip', 'ff15::1111')
  options['drone-id-list'] = options['slapparameter-dict'].get('drone_id_list', '')

[js-dynamic-template]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}
template = ${buildout:directory}/$${:_buildout_section_name_}.js
extra-context =
context =
  raw qjs_wrapper ${qjs-wrapper:location}/lib/libqjswrapper.so
  $${:extra-context}

[common]
<= js-dynamic-template
extra-context =
  key autopilot_ip drone:autopilot-ip
  key drone_id_list drone:drone-id-list
  key is_a_simulation drone:is-a-simulation
  key is_leader drone:is-leader
  key leader_id drone:leader-id
  key log_dir directory:log
  key pubsub_script pubsub:rendered

[cli]
<= js-dynamic-template
extra-context =
  key common common:rendered

[demo]
<= js-dynamic-template
extra-context =
  key common common:rendered

[manual-flight]
<= js-dynamic-template
extra-context =
  key common common:rendered

[pubsub]
<= js-dynamic-template
extra-context =
  key id drone:id
  key ipv6 drone:multicast-ipv6
