#!/usr/bin/env python

from __future__ import print_function

import os
import sys


if 'PYTHON' in os.environ:
    python = os.getenv('PYTHON')
    os.unsetenv('PYTHON')
    os.execv(python, [python] + sys.argv)

from library import config
import py
import yaml

config.registrydir = lambda: py.path.local('snapshot/etc/registry')

print('Updating registry...')

updated = config.update()
if updated:
    print('  Updated config', updated)
else:
    print('  Config is up to date')

print('Updating share/config.yaml...')
yaml.dump(
    config.query('skynet.skycore.config', None, as_dict=True),
    open('share/config.yaml', 'wb'),
    default_flow_style=False
)

print('Done!')
