-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecompile.py
executable file
·55 lines (42 loc) · 1.35 KB
/
precompile.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
#!/usr/bin/python3
#-*-coding: utf-8 *-
import sys
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--production", action="store_true", help="precompile in production mode")
parser.add_argument("-s", "--staging", action="store_true", help="precompile in staging mode")
args = parser.parse_args()
branch = os.popen("git rev-parse --abbrev-ref HEAD").read()
if "fatal" in branch:
"Not a git repository : abort"
os.exit(1)
clobber = "bundle exec rake assets:clobber"
precompile = "bundle exec rake assets:precompile"
git = "git add . && git commit -m 'Assets' && git push origin {}".format(branch)
def get_secret_key(env):
secret_key = input("Type secret key base for environment {} : ".format(env))
return(secret_key)
if args.staging and args.production:
print("Only one environment can be chosen at a time")
os.exit(1)
if args.production:
secret_key = get_secret_key("production")
prefix = "RAILS_ENV=production SECRET_KEY_BASE={}".format(secret_key)
elif args.staging:
secret_key = get_secret_key("staging")
prefix = "RAILS_ENV=staging SECRET_KEY_BASE={}".format(secret_key)
else:
prefix = ""
precompile = prefix + precompile
cmds = [
clobber,
precompile,
git
]
for cmd in cmds:
if os.system(cmd) != 0:
print("Error while executing cmd : '{}'".format("cmd"))
sys.exit(1)
else:
print("{} ==> OK".format(cmd))