-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
executable file
·77 lines (52 loc) · 2.06 KB
/
deploy.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
#!/usr/bin/env python
import yaml
import sys
import os
from subprocess import call
from utils import banner
from check import check_requirements
conf = yaml.load(open('./config.yml', 'r'))
cloning_method = 'ssh'
if len(sys.argv) > 1 and sys.argv[1] == 'https':
cloning_method = 'https'
def self_update():
print(banner.info('Self-updating...'))
call(['git', 'checkout', 'master'])
call(['git', 'pull'])
def update_confirmation():
print(banner.info('Are you sure you want to continue?'))
print('I will stash potential uncommitted changes, checkout master and pull the last commit from origin. '
'Continue? [y/N] ')
choice = input().lower()
if choice != 'y':
exit(1)
def update(name, path):
print(banner.info('Now updating ' + name))
update_confirmation()
call(['git', 'stash', 'save'], cwd=path)
call(['git', 'checkout', 'master'], cwd=path)
call(['git', 'pull'], cwd=path)
def install(name, description, url, path):
print(banner.info('Now installing ' + name))
print(description)
print(banner.info('Using ' + cloning_method + ' cloning method'))
print('You may change the cloning method by passing https or ssh as an argument.')
call(['git', 'clone', url, path])
def deploy():
for project_id in conf['projects']:
project = conf['projects'][project_id]
path = conf['parameters']['projects_dir'] + '/' + project_id
if os.path.exists(path):
update(project['name'], path)
else:
install(project['name'], project['description'], project['repository'][cloning_method], path)
check_requirements(project_id)
properties = yaml.load(open(path + '/.p-properties.yml', 'r'))
for command in properties['install']:
call(command, shell=True, cwd=path)
print(banner.success('Deployment is done!'))
print('Please check execution traces as installation scripts errors are ignored.')
print('You may also need to pop stashed changes in repositories.')
if __name__ == '__main__':
self_update()
deploy()