diff --git a/deploy/git.py b/deploy/git.py index 3d5956c1..ec9fe28e 100644 --- a/deploy/git.py +++ b/deploy/git.py @@ -2,36 +2,51 @@ from .path import repo_path, file_exists + def check(c: Connection): return remote_reachable(c) + def update(c: Connection): if repo_exists(c): fetch(c) else: clone(c) + def repo_exists(c: Connection) -> bool: return file_exists(c, "{}/HEAD".format(c.repo_path)) + def remote_reachable(c: Connection) -> bool: with c.cd(c.repo_path): - return c.run("git ls-remote {} HEAD".format(c.deploy.repo_url), warn=True, echo=True).ok + return c.run( + "git ls-remote {} HEAD".format(c.deploy.repo_url), warn=True, echo=True + ).ok + def clone(c: Connection): with c.cd(c.deploy_path): c.run("git clone --bare {} {}".format(c.deploy.repo_url, c.repo_path)) + def fetch(c: Connection): with c.cd(c.repo_path): c.run("git remote set-url origin {}".format(c.deploy.repo_url), echo=True) c.run("git remote update", echo=True) c.run("git fetch origin {0}:{0}".format(c.commit), echo=True) + def revision_number(c: Connection, revision: str) -> str: with c.cd(c.repo_path): - return c.run("git rev-list --max-count=1 {} --".format(revision), echo=True).stdout.strip() + return c.run( + "git rev-list --max-count=1 {} --".format(revision), echo=True + ).stdout.strip() + def create_archive(c: Connection): with c.cd(c.repo_path): - c.run("git archive {} | tar -x -f - -C '{}'".format(c.commit, c.release_path), echo=True) + c.run( + "git archive {} | tar -x -f - -C '{}'".format(c.commit, c.release_path), + echo=True, + ) diff --git a/deploy/path.py b/deploy/path.py index 81a19b27..fae26f44 100644 --- a/deploy/path.py +++ b/deploy/path.py @@ -2,29 +2,38 @@ from fabric import Connection + def exists(c: Connection, path: str) -> bool: return c.run("[[ -e {} ]]".format(path), warn=True).ok + def file_exists(c: Connection, path: str) -> bool: return c.run("[[ -f {} ]]".format(path), warn=True).ok + def dir_exists(c: Connection, path: str) -> bool: return c.run("[[ -d {} ]]".format(path), warn=True).ok + def deploy_path(c: Connection) -> str: return posixpath.join(c.deploy.path.root, c.deploy.name) + def repo_path(c: Connection) -> str: return posixpath.join(deploy_path(c), c.deploy.path.repo) + def releases_path(c: Connection) -> str: return posixpath.join(deploy_path(c), c.deploy.path.releases) + def current_path(c: Connection) -> str: return posixpath.join(deploy_path(c), c.deploy.path.current) + def shared_path(c: Connection) -> str: return posixpath.join(deploy_path(c), c.deploy.path.shared) + def release_path(c: Connection) -> str: - return posixpath.join(releases_path(c), c.release) \ No newline at end of file + return posixpath.join(releases_path(c), c.release)