# 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
        join = posixpath.join
        self.folders = {
            "project": project,
            "current": join(project, "current"),
            "releases": join(project, "releases"),
            "releases.current": join(project, "releases", deploy),
            "shared": join(project, "shared"),
            "shared.logs": join(project, "shared", "logs"),
            "shared.temp": join(project, "shared", "temp"),
            "shared.run": join(project, "shared", "run")
        }

    def _layout(self):
        current_user = core.run("echo $USER").stdout

        for type, path in self.folders.iteritems():
            if not dir.exists(path):
                if type != "current":
                    dir.create(path, recursive=True)
            else:
                with ctx.sudo():
                    dir.attributes(path, owner=current_user, recursive=True)

    def _upload(self):
        # TODO Warn if there are local changes
        tmp_tar = git.create_archive(self.revision)

        try:
            core.put(tmp_tar, "deploy.tar.gz")
            core.run("tar -xzf deploy.tar.gz")

# 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

        join = posixpath.join
        self.folders = {
            "project": project,
            "current": join(project, "current"),
            "releases": join(project, "releases"),
            "releases.current": join(project, "releases", deploy),
            "shared": join(project, "shared"),
            "shared.logs": join(project, "shared", "logs"),
            "shared.temp": join(project, "shared", "temp"),
            "shared.run": join(project, "shared", "run")
        }

    def _layout(self):
        current_user = core.run("echo $USER").stdout

        for type, path in self.folders.iteritems():
            if not dir.exists(path):
                if type != "current":
                    dir.create(path, recursive=True)
            else:
                with ctx.sudo():
                    dir.attributes(path, owner=current_user, recursive=True)

    def _upload(self):
        # TODO Warn if there are local changes
        tmp_tar = git.create_archive(self.revision)

        try:
            core.put(tmp_tar, "deploy.tar.gz")
            core.run("tar -xzf deploy.tar.gz")

            file.remove("deploy.tar.gz")