-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
87 lines (55 loc) · 2.31 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
from fabric.api import *
"""
Cuban Council fabfile. Some might say the fabbest of all.
"""
# ---- Variables
# Compression path root. Used as relative path for all paths set in 'env.compress_files' var
env.compress_root = os.path.dirname(os.path.dirname(__file__))
# File list by type, to be compressed. Dictionary entries in css/js -- key is outgoing file path relative to 'env.compress_root', and
# value is either a string file path relative to 'env.compress_root' or a tuple of string file paths to minify together into the outgoing
# file. See settings_example.py for example
env.compress_files = {
'css': {},
'js': {}
}
# Import local settings, if available
try:
from settings import *
except ImportError:
pass
# ---- Functions
def pushkey(keytype='dsa'):
"""
Put your local SSH key on an indicated remote host
Usage:
fab pushkey
If not using DSA, pass in key type to use:
fab pushkey:rsa
To push to a specific host:
fab -H someserver.com pushkey
"""
publickey = '~/.ssh/id_%s.pub' % keytype
tmpfile = '/tmp/%s.pub' % env.user
run('mkdir -p ~/.ssh && chmod 700 ~/.ssh')
put(publickey, tmpfile)
run('cat %s >> ~/.ssh/authorized_keys' % tmpfile)
run('rm %s' % tmpfile)
def compress():
"""
Compress/minify CSS and JS resources according to paths configured with 'env.compress_files' variable
"""
# Get resource root path
for file_type in env.compress_files:
for out_file in env.compress_files[file_type]:
# Set out directory and file
out_file_path = os.path.join(env.compress_root, out_file).replace('\\', '/')
# Get list of files to compress
if type(env.compress_files[file_type][out_file]) is str:
file_list = tuple([env.compress_files[file_type][out_file]])
else:
file_list = env.compress_files[file_type][out_file]
# Cycle through and compress files
file_list = ' '.join('\'' + os.path.join(env.compress_root, in_file).replace('\\', '/') + '\'' for in_file in file_list)
cmd = 'awk 1 %s | java -jar yuicompressor-2.4.6.jar --type %s -o %s' % (file_list, file_type, out_file_path)
local(cmd, capture=False)