# 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




class Deployinator(object):
    def __init__(self, cwd=None, name=None):
        self.cwd = cwd or core.run("pwd").stdout
        self.name = name or git.repository_name()
        self.releases_to_keep = 15
        self.revision = "HEAD"
        self._hooks = []
        self._init_folders()

    def add_hook(self, hook):
        hook.set_deployinator(self)
        self._hooks.append(hook)

    def dispatch_hook(self, name):
        for hook in self._hooks:
            method = getattr(hook, "on_%s" % name)
            if method:
                method()

    def run(self):
        self.dispatch_hook("init")
        self.dispatch_hook("before_layout")
        try:
            self._layout()
            self.dispatch_hook("after_layout")


# 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





class Deployinator(object):
    def __init__(self, cwd=None, name=None):
        self.cwd = cwd or core.run("pwd").stdout
        self.name = name or git.repository_name()
        self.releases_to_keep = 15
        self.revision = "HEAD"
        self._hooks = []
        self._init_folders()

    def add_hook(self, hook):
        hook.set_deployinator(self)
        self._hooks.append(hook)

    def dispatch_hook(self, name):
        for hook in self._hooks:
            method = getattr(hook, "on_%s" % name)
            if method:
                method()

    def run(self):
        self.dispatch_hook("init")
        self.dispatch_hook("before_layout")
        try:
            self._layout()
            self.dispatch_hook("after_layout")


            with ctx.cd(self.folders["releases.current"]):