-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate
More file actions
executable file
·98 lines (78 loc) · 2.88 KB
/
update
File metadata and controls
executable file
·98 lines (78 loc) · 2.88 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
#!/usr/bin/env python
import subprocess
import os
import re
style = {
'cyan': '\033[36m',
'green': '\033[92m',
'red': '\033[91m',
'purpl': '\033[95m',
'yello': '\033[33m',
'blue': '\033[34m',
'bold': '\033[01m',
'ul' : '\033[04m',
'blink' : '\033[05m',
'inve' : '\033[07m',
'reset' : '\033[0m'
}
line_length = int(os.popen('stty size', 'r').read().split()[1])
line = ("-" * ((line_length /len("-")) + 1))[:line_length]
class Repo:
build = {
"sbt": "./sbt build",
"gradle": "./gradlew clean build",
"maven": "mvn clean build -DskipTests"
}
def __init__(self, path, rel_path):
self.path = path
self.rel_path = rel_path
self.build_command = self.__find_build_system()
self.has_git = os.path.isdir(self.path + "/.git")
def update(self):
print(line)
print("{yellow}Updating the repo: {path}{reset}".format(path=self.rel_path, **style))
if self.has_git:
os.chdir(self.path)
subprocess.Popen("git checkout master && git pull", stdout=subprocess.PIPE, shell=True).communicate()
else:
log.warn("{red}{path} is not a git project{reset}".format(red=self.rel_path, **style))
pass
if self.build_command is None:
print("{red}{path} does not contain a build system{reset}".format(path=self.rel_path, **style))
pass
else:
os.chdir(self.path)
print("Using {command} to update {cyan}{path}{reset}".format(command=self.build_command, path=self.rel_path, **style))
subprocess.Popen(self.build_command, stdout=subprocess.PIPE, shell=True).communicate()
print("\n{bold}{ul}Finished updating {path}{reset}".format(path=self.rel_path, **style))
print(line)
print("\n\n")
def __find_build_system(self):
if os.path.exists(self.path + "/gradlew"):
return self.build.get("gradle")
elif os.path.exists(self.path + "/pom.xml"):
return self.build.get("maven")
elif os.path.exists(self.path + "/sbt"):
return self.build.get("sbt")
else:
return None
def main():
global current_dir
current_dir = os.getcwd()
all_dirs = [name for name in os.listdir(current_dir) if os.path.isdir(os.path.join(current_dir, name))]
repos = list()
print("{bold}Updating all subdirectories under {cyan}{dir}{reset}".format(dir=current_dir, **style))
print("List of folders that are being updated:\n")
for name in all_dirs:
if name.startswith("."):
pass
else:
repo = Repo(current_dir + "/" + name, name)
if repo.has_git:
repos.append(repo)
print("\t{green}{bold}{name}{reset}".format(name=name, **style))
print("")
for repo in repos:
repo.update()
if __name__ == "__main__":
main()