# -*- coding: utf-8 -*-

"""Miscellaneous functions"""

import datetime
import getpass
import platform
import sys

import hankshaw
import networkx as nx
import numpy as np



def write_run_information(filename, config):
    """ Write information about the run and software environment """

    with open(filename, 'w') as infofile:
        infostr = 'Generated by {whom} at {when}\n'
        infofile.write(infostr.format(when=datetime.datetime.now().isoformat(),
                                        whom=getpass.getuser()))
        infofile.write('Host: {p}\n'.format(p=platform.node()))
        infofile.write('Platform: {p}\n'.format(p=platform.platform()))
        infofile.write('Hankshaw Model Version: {v}\n'.format(v=hankshaw.__version__))
        infofile.write('Python Version: {v}\n'.format(v=".".join([str(n) for n in sys.version_info[:3]])))
        infofile.write('NumPy Version: {v}\n'.format(v=np.version.version))
        infofile.write('NetworkX Version: {v}\n'.format(v=nx.__version__))
        infofile.write('Command: {cmd}\n'.format(cmd=' '.join(sys.argv)))
        infofile.write('Random Seed: {seed}\n'.format(seed=config['Simulation']['seed']))
        infofile.write('UUID: {uuid}\n'.format(uuid=config['Simulation']['UUID']))

def append_run_information(filename, string):
    """ Add additional information about the run and software environment """

    with open(filename, 'a') as infofile:
        infofile.write(string)

