-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabric.py
59 lines (47 loc) · 1.38 KB
/
fabric.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import shutil
from fabric.api import task, env, local, run
from ftpsync.targets import FsTarget
from ftpsync.ftp_target import FtpTarget
from ftpsync.synchronizers import BiDirSynchronizer
#
# Configuration
#
DEPLOY_FOLDER = "deploy"
SOURCE_FOLDER = "src"
FTP_HOST = "example.com"
FTP_TARGET = "/domains/xxx/public_html"
def build_html():
print "running gulp..."
run("gulp deploy")
def make_temp():
if os.path.exists(DEPLOY_FOLDER):
shutil.rmtree(DEPLOY_FOLDER)
shutil.copy2(SOURCE_FOLDER, DEPLOY_FOLDER)
return False
def make_config(env):
print "Making prod config file..."
shutil.copy2('{0}/protected/config/main.php-{1}'.format(SOURCE_FOLDER, env), '{0}/protected/config/main.php'.format(DEPLOY_FOLDER))
return False
def synchronize(user, password):
print "syncing..."
try:
local = FsTarget(DEPLOY_FOLDER)
remote = FtpTarget(FTP_TARGET, FTP_HOST, user, password, tls=True)
opts = {"resolve": "skip", "verbose": 1, "dry_run" : False}
s = BiDirSynchronizer(local, remote, opts)
s.run()
print "sync complete..."
except Exception as e:
print type(e)
print e.args
print e
@task
def deploy(env="test", user, password):
print "deploying..."
make_temp()
make_config(env)
synchronize(user, password)