import subprocess
import io

from datetime import datetime


def execute_start_script(start_cmd):
    subprocess.call([start_cmd])


def save_apprc_file(environs):
    with io.open("/home/application/apprc", "w") as file:
        file.write(u"# generated by tsuru at {}\n".format(datetime.now()))
        for env in environs:
            file.write(u'export {}="{}"\n'.format(env["name"], env["value"]))
