forked from fengluo/qingcheng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
52 lines (36 loc) · 1.27 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
import os
import glob
import hashlib
import datetime
from fabric.api import env, local
env.use_ssh_config = True
env.keepalive = 60
def hash_name(filename):
now = datetime.datetime.now()
with open(filename) as f:
hsh = hashlib.md5(f.read()).hexdigest()[:6]
basename = os.path.basename(filename)
key, ext = os.path.splitext(basename)
return '%s.%s.%s%s' % (now.strftime('%Y%m%d'), key, hsh, ext)
def upload_qiniu(filename):
name = hash_name(filename)
local('qboxrsctl put -c python qingcheng/%s %s' % (name, filename))
def upload_assets():
upload_qiniu('dist/vendor.css')
upload_qiniu('dist/app.css')
upload_qiniu('dist/vendor.js')
upload_app_js()
def upload_app_js():
filename = 'dist/app.js'
name = hash_name(filename)
with open(filename, 'r') as f:
content = f.read()
content = content.replace('app.js.map', name + '.map')
with open(filename, 'w') as f:
f.write(content)
local('qboxrsctl put -c python qingcheng/%s %s' % (name, filename))
local('qboxrsctl put -c python qingcheng/%s.map %s.map' % (name, filename))
def fonts():
for name in glob.glob('dist/fonts/*'):
key = name.replace('dist', 'qingcheng')
local('qboxrsctl put -c python %s %s' % (key, name))