-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull-head-tracking-subprojects.py
More file actions
executable file
·125 lines (111 loc) · 4.66 KB
/
pull-head-tracking-subprojects.py
File metadata and controls
executable file
·125 lines (111 loc) · 4.66 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import io
import os
import sys
import subprocess
tree = '''
▄████▄
▄███░░░██▄ ▄████▄
▄██░░░░░░░░███░░░░██▄
▄██░░░░░░░░░██░░░░░░░░█
██░░░░░░░░░██░░░░░░░░░█
█░░░░░░░░░██░░░░░░░░░░█
█░░░░░░░░░█░░░░░░░░░░░█
██░░░░░░░░█░░░░░░░░░░░█
█░░░░░░░██░░░░░░░░░░░█
█░░░░░░█░░░░░░░░░░░░█
██░░░░░█░░░░░░░░░░░░█
█ █ ██░░░░█░░░░░░░░░░░█
█ █ █░░░░█░░░░░░░░░██
█ █ █░░░░█░░░░░░░███
█ █ ▄███░░░█░░░░█████
▄████████▄ █▒▒██████████▒▒▒███
█░░░░░░░░███▒▒▒████▒▒▒███▒▒▒▒██
█░░░█░░█░░░█▒▒▒▒▒███▒▒▒▒███▒▒▒▒█▄
█░░░░░░░░░░█▒▒▒▒▒▒██▒▒▒▒▒██▒▒▒▒███
█░░█░░░░█░░█▒▒▒▒▒▒██▒▒▒▒▒██▒▒▒▒█▀
██░░████░░░█▒▒▒▒▒███▒▒▒▒███▒▒▒██
██░░░░░░███▒▒▒▒████▒▒▒███▒▒▒██
▀▀▀▀▀▀▀▀ ██▒▒████▒▒▒███▒▒▒██
▀███████████████▀
'''
try:
import colorama
has_colorama = True
colorama.init()
style = colorama.Style.NORMAL
if os.name == 'nt':
style = colorama.Style.BRIGHT
print(style + colorama.Fore.YELLOW + tree + colorama.Fore.RESET)
except:
has_colorama = False
if not os.path.exists('subprojects'):
print('No suprojects dir found')
sys.exit(1)
wraps = os.listdir('subprojects')
enc = sys.stdout.encoding
if enc is None:
import locale
enc = locale.getpreferredencoding()
def print_popen(popen):
out, err = popen
if err is not None:
sys.stdout.write(err.decode(enc))
if out is not None:
sys.stdout.write(out.decode(enc))
def print_msg(prefix, msg):
if has_colorama:
s = colorama.Style.BRIGHT + '> ' + colorama.Style.NORMAL
s += colorama.Fore.GREEN + prefix + ' ' + colorama.Style.RESET_ALL
s += colorama.Style.BRIGHT + msg + '...'
s += colorama.Style.RESET_ALL
else:
s = '> ' + prefix + ' ' + msg + '...'
print(s)
for name in wraps:
if not name.endswith('.wrap'):
continue
path = os.path.join('subprojects', name)
if not os.path.exists(path):
print('Path not found:', path)
sys.exit(1)
f = open(path, 'r')
header = f.readline().strip()
if header != '[wrap-git]':
continue
values = dict()
for line in f:
line = line.strip()
if line == '':
continue
(k, v) = line.split('=', 1)
k = k.strip()
v = v.strip()
values[k] = v
d = values['directory']
if d is None:
continue
rev = values['revision']
path = os.path.join('subprojects', d)
out = io.StringIO()
if not os.path.exists(path):
print_msg('Cloning', path)
popen = subprocess.Popen(['git', 'clone', values['url'], values['directory']], cwd='subprojects', stdout=subprocess.PIPE)
print_popen(popen.communicate())
else:
print_msg('Updating', path)
if rev == 'head':
popen = subprocess.Popen(['git', 'pull'], cwd=path, stdout=subprocess.PIPE)
print_popen(popen.communicate())
else:
popen = subprocess.Popen(['git', 'rev-parse', 'HEAD'], cwd=path, stdout=subprocess.PIPE)
out, err = popen.communicate()
if out.decode(enc).strip() != rev:
popen = subprocess.Popen(['git', 'fetch'], cwd=path, stdout=subprocess.PIPE)
print_popen(popen.communicate())
popen = subprocess.Popen(['git', 'checkout', rev], cwd=path, stdout=subprocess.PIPE)
print_popen(popen.communicate())
else:
print('Already up to date.')