forked from crate-archive/crate-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
70 lines (51 loc) · 2.22 KB
/
fabfile.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
63
64
65
66
67
68
69
70
import datetime
import os
from fabric.api import abort, env, hide, local, task, settings
@task
def compile():
BASE_DIR = os.path.dirname(env["real_fabfile"])
with hide("stdout"):
local("git stash save")
local("%s collectstatic --noinput --clear" % os.path.join(BASE_DIR, "manage.py"))
# Delete Non Less Files
files_to_delete = set()
for root, dirs, files in os.walk(os.path.join(BASE_DIR, "crate_project", "site_media", "static")):
for file in files:
if not file.endswith(".less"):
files_to_delete.add(os.path.abspath(os.path.join(root, file)))
for f in files_to_delete:
os.remove(f)
# Compile the Less Files
files_to_compile = set([
os.path.join(BASE_DIR, "crate_project", "site_media", "static", "pinax", "less", "theme.less"),
os.path.join(BASE_DIR, "crate_project", "site_media", "static", "less", "crate.less"),
])
for f in files_to_compile:
filename = os.path.splitext(os.path.basename(f))[0] + ".css"
output_file = os.path.join(BASE_DIR, "crate_project", "static", "css", filename)
local(" ".join(["lessc -x", f, output_file]))
local("git add %s" % output_file)
pending = False
changes = local("git status --porcelain", capture=True)
for line in changes.splitlines():
if not line.startswith("??"):
print line
pending = True
break
if pending:
local("git commit -m 'automatically compiled CSS files on %sZ'" % datetime.datetime.utcnow().isoformat())
with settings(warn_only=True):
local("git stash pop")
@task
def deploy(instance=None):
if instance is None:
abort("Must provide an instance name.")
# Get the Current Branch
branch = local("git name-rev --name-only HEAD", capture=True)
if branch.failed:
abort("Unable to get the current branch name")
local("gondor deploy %(instance)s %(branch)s" % {"instance": instance, "branch": branch})
@task
def host():
BASE_DIR = os.path.dirname(env["real_fabfile"])
local("%s runserver" % os.path.join(BASE_DIR, "manage.py"))