-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSubmoduleInstall.py
More file actions
executable file
·87 lines (74 loc) · 2.65 KB
/
SubmoduleInstall.py
File metadata and controls
executable file
·87 lines (74 loc) · 2.65 KB
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
#!/usr/bin/env python
# Script that installs the necessary submodules to build with cmake
# Imports
import os
# Colors
PROGRESS = '\033[1m\033[35m'
WARNING = '\033[33m'
PASS = '\033[32m'
DEFAULT = '\033[0m'
# Submodule Class
class Submodule:
def _init_(self, path=None, url=None, commit=None):
self.path = path
self.url = url
self.commit = commit
def put_path(self, path):
self.path = path
def put_url(self, url):
self.url = url
def put_commit(self, commit):
self.commit = commit
# Used for debugging
def __str__(self):
return 'path = {}\nurl = {}\ncommit = {}'.format(self.path, self.url, self.commit)
def color_print(message, color=DEFAULT):
output = '{}{}{}'.format(color, message, DEFAULT)
print(output)
if __name__ == '__main__':
# Get the submodules
color_print('Getting submodule info...', PROGRESS)
submodules = []
with open('.gitmodules') as module_file:
line = module_file.readline().strip()
index = -1
while line:
if line.startswith('[submodule'):
submodules.append(Submodule())
index += 1
else:
data = line[1 + line.index('='):].strip()
if line.startswith('path'):
submodules[index].put_path(data)
elif line.startswith('url'):
submodules[index].put_url(data)
elif line.startswith('branch'):
submodules[index].put_commit(data)
line = module_file.readline().strip()
color_print('DONE', PROGRESS)
# Prepare for install
color_print('Preparing for install...', PROGRESS)
for submodule in submodules:
if os.path.isdir(submodule.path):
color_print('{} exists. Removing...'.format(submodule.path), WARNING)
os.system('rm -rf {}'.format(submodule.path))
else:
color_print('{} does not exist. Good'.format(submodule.path), PASS)
color_print('DONE', PROGRESS)
# Install submodules
color_print('Installing submodules...', PROGRESS)
for submodule in submodules:
os.system('git clone {} {}'.format(submodule.url, submodule.path))
color_print('DONE', PROGRESS)
# Checkout correct commits
color_print('Checking out correct commits...', PROGRESS)
workingdir = os.getcwd()
for submodule in submodules:
os.chdir(submodule.path)
try:
os.system('git checkout {}'.format(submodule.commit))
except:
color_print('No commit to check out', WARNING)
os.chdir(workingdir)
pass
color_print('DONE', PROGRESS)