This repository was archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdeploy.py
62 lines (48 loc) · 1.69 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import datetime
import shutil
from catsup.logger import logger
from catsup.utils import call
RSYNC_COMMAND = (
"rsync -avze 'ssh -p {ssh_port}' {args}"
" {deploy_dir}/ {ssh_user}@{ssh_host}:{document_root}"
)
def git(config):
logger.info("Deploying your site via git")
cwd = os.path.abspath(config.config.output)
def _call(*args, **kwargs):
return call(*args, cwd=cwd, **kwargs)
dot_git_path = os.path.join(cwd, ".git")
if os.path.exists(dot_git_path):
if _call("git remote -v | grep %s" % config.deploy.git.repo) == 0:
shutil.rmtree(dot_git_path)
if not os.path.exists(dot_git_path):
_call("git init")
_call("git remote add origin %s" % config.deploy.git.repo)
if _call("git checkout %s" % config.deploy.git.branch) != 0:
_call("git branch -m %s" % config.deploy.git.branch)
if config.deploy.git.delete:
_call("rm -rf *")
from catsup.generator import Generator
generator = Generator(config.path)
generator.generate()
_call("git add .", silence=True)
_call(
'git commit -m "Update at %s"' % str(datetime.datetime.utcnow()), silence=True
)
_call("git push origin %s --force" % config.deploy.git.branch)
def rsync(config):
logger.info("Deploying your site via rsync")
if config.deploy.rsync.delete:
args = "--delete"
else:
args = ""
cmd = RSYNC_COMMAND.format(
ssh_port=config.deploy.rsync.ssh_port,
args=args,
deploy_dir=config.config.output,
ssh_user=config.deploy.rsync.ssh_user,
ssh_host=config.deploy.rsync.ssh_host,
document_root=config.deploy.rsync.document_root,
)
call(cmd)