# Path: revolver/contextmanager.py
# def sudo(username=None, login=False):
# def unpatched_state():
# 
# Path: revolver/directory.py
# def temp_local():
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def create(path, recursive=False, mode=None, owner=None, group=None):
# 
# Path: revolver/file.py
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def touch(location, mode=None, owner=None, group=None):
# def copy(source, destination, force=True, mode=None, owner=None, group=None):
# 
# Path: revolver/git.py
# def repository_name():
# def create_archive(revision):
# def revparse(revision):
# 
# Path: revolver/core.py
# VERSION = '0.0.5'
# def put(*args, **kwargs):
# def run(*args, **kwargs):
# def sudo(*args, **kwargs):
# 
# Path: revolver/command.py

# 
# Path: revolver/service.py
# def add_upstart(name, content):
# def command(name, command):
# def start(name):
# def stop(name):
# def restart(name):
# def reload(name):
# def is_running(name):


from datetime import datetime
from revolver import contextmanager as ctx
from revolver import directory as dir
from revolver import file, git, core, command, service
import posixpath
author "Revolver UnicornUpstartHook"
version "1.0"

start on runlevel [2]
stop  on runlevel [016]

console owner

exec sudo -u {user} -i {shell} -c "cd {folders[current]} &&\\
  bundle exec unicorn -E {env} -c {config} -D"
"""

    def __init__(self, config):
        self._config = config

    def on_init(self):
        self._service = "unicorn-" + self.name

    def on_before_activate(self):
        # TODO: Use shell from the current user
        # TODO: Allow changes to the used environment
        values = {
            "folders": self.folders,
            "name": self.name,
            "user": core.run("echo $USER").stdout,
            "config": self._config,
            "env": "production",
            "shell": "/bin/bash -i"
        }
        content = self._template.format(**values)

# Path: revolver/contextmanager.py
# def sudo(username=None, login=False):
# def unpatched_state():
# 
# Path: revolver/directory.py
# def temp_local():
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def create(path, recursive=False, mode=None, owner=None, group=None):
# 
# Path: revolver/file.py
# def temp(mode=None, owner=None, group=None):
# def remove(location, recursive=False, force=True):
# def touch(location, mode=None, owner=None, group=None):
# def copy(source, destination, force=True, mode=None, owner=None, group=None):
# 
# Path: revolver/git.py
# def repository_name():
# def create_archive(revision):
# def revparse(revision):
# 
# Path: revolver/core.py
# VERSION = '0.0.5'
# def put(*args, **kwargs):
# def run(*args, **kwargs):
# def sudo(*args, **kwargs):
# 
# Path: revolver/command.py

# 
# Path: revolver/service.py
# def add_upstart(name, content):
# def command(name, command):
# def start(name):
# def stop(name):
# def restart(name):
# def reload(name):
# def is_running(name):


# Path: revolver/project.py
from datetime import datetime
from revolver import contextmanager as ctx
from revolver import directory as dir
from revolver import file, git, core, command, service
import posixpath

author "Revolver UnicornUpstartHook"
version "1.0"

start on runlevel [2]
stop  on runlevel [016]

console owner

exec sudo -u {user} -i {shell} -c "cd {folders[current]} &&\\
  bundle exec unicorn -E {env} -c {config} -D"
"""

    def __init__(self, config):
        self._config = config

    def on_init(self):
        self._service = "unicorn-" + self.name

    def on_before_activate(self):
        # TODO: Use shell from the current user
        # TODO: Allow changes to the used environment
        values = {
            "folders": self.folders,
            "name": self.name,
            "user": core.run("echo $USER").stdout,
            "config": self._config,
            "env": "production",
            "shell": "/bin/bash -i"
        }
        content = self._template.format(**values)

        service.add_upstart(self._service, content)