forked from davidwinter/wordpress-with-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
75 lines (61 loc) · 2.19 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
from uuid import uuid4
from os import getcwd
from getpass import getuser
from os.path import join, exists
from fabric.api import local, lcd, prompt, env, abort
def create():
prompt("Project Title:", "project_title", validate=nonempty)
prompt("Project Name:", "project_name",
clean(env.project_title), nonempty)
prompt("Project URL:", "project_url",
env.project_name+'.com', nonempty)
prompt("Project User:", "project_user",
getuser(), nonempty)
path = join('../', env.project_name)
if exists(path): abort("Project alread exists: "+path)
local("cp -r %s %s" % (getcwd(), path))
with lcd(path):
theme_tpl = join('../', 'wordpress-theme-template')
theme = join('wp-content/themes/',env.project_name)
local("cp -r %s %s" % (theme_tpl, theme))
local("mv project-fabfile.py fabfile.py")
do_string_replacement([
'.htaccess',
'hgrc',
'create.sh',
'local.wp-config.php',
'production.wp-config.php',
'wp-cli.yml',
'fabfile.py',
join(theme, 'style.css')
])
local("rm -rf .git")
local("rm -rf "+join(theme, '.git'))
local("rm wp-config-sample.php")
local("rm .gitignore")
local("rm "+join(theme, '.gitignore'))
local("rm "+join(theme, '.editorconfig'))
local("hg init")
local("mv hgrc .hg/")
local("hg add .")
local("hg commit -m'initial import'")
local("cp local.wp-config.php wp-config.php")
local("cp -r ../wordpress wordpress")
def clean(t):
return t.strip().lower().replace(' ','')
def nonempty(v):
if len(v.strip())==0:
raise "Cannot be empty."
return v.strip()
def do_string_replacement(files):
tplvars = {
'Title': env.project_title,
'Name': env.project_name,
'URL': env.project_url,
'User': env.project_user
}
tplvars.update([('Random Key %s'%i, uuid4()) for i in range(1,10)])
sed = ';'.join([r's/\[Project %s\]/%s/g'%(key,val)
for key,val in tplvars.items()])
for tpl in files:
local(r'sed -i -e "%s" %s' % (sed, tpl))