-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull.py
executable file
·63 lines (49 loc) · 1.4 KB
/
pull.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Laziness is virtue
# Copyright 2007-2015 İsmail Dönmez
import sys
import os
vcDict = {
".gclient": "gclient sync",
".git/refs/remotes/git-svn": "git svn rebase",
".git": "git pull",
".svn": "svn up",
".hg": "hg pull -u -v",
"CVS": "cvs -q -z3 update -dPA",
".bzr": "bzr pull",
".osc": "osc up",
}
def log(string, isTTY=sys.stdout.isatty()):
if isTTY:
print("Updating \033[0;33m%s\033[0m" % string)
else:
print(string)
def doPull(directory):
currentDirectory = os.getcwd()
os.chdir(directory)
for path in vcDict.keys():
if os.path.exists(path):
log(os.path.abspath("."))
sys.stdout.flush()
os.system(vcDict[path])
break
os.chdir(currentDirectory)
if __name__ == "__main__":
arglength = len(sys.argv)
if arglength > 1:
if sys.argv[1] in ["-r", "--recursive"]:
if arglength == 3:
os.chdir(sys.argv[2])
root = os.path.abspath(".")
paths = sorted(set([os.path.join(root, x[0]) for x in os.walk(root)]))
for path in paths:
doPull(path)
sys.exit(0)
for i in range(0, arglength - 1):
path = os.path.expanduser(sys.argv[i + 1])
if os.path.isdir(path):
doPull(path)
else:
doPull(".")