forked from dmitryn/GitStats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_line_processor.py
More file actions
37 lines (32 loc) · 934 Bytes
/
Copy pathcommand_line_processor.py
File metadata and controls
37 lines (32 loc) · 934 Bytes
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
import time
import platform
import subprocess
VERSION = 0
ON_LINUX = (platform.system() == 'Linux')
exectime_external = 0.0
def getpipeoutput(cmds, quiet = False):
global exectime_external
start = time.time()
if not quiet and ON_LINUX and os.isatty(1):
print '>> ' + ' | '.join(cmds),
sys.stdout.flush()
p0 = subprocess.Popen(cmds[0], stdout = subprocess.PIPE, shell = True)
p = p0
for x in cmds[1:]:
p = subprocess.Popen(x, stdin = p0.stdout, stdout = subprocess.PIPE, shell = True)
p0 = p
output = p.communicate()[0]
end = time.time()
if not quiet:
if ON_LINUX and os.isatty(1):
print '\r',
print '[%.5f] >> %s' % (end - start, ' | '.join(cmds))
exectime_external += (end - start)
return output.rstrip('\n')
def getversion():
global VERSION
if VERSION == 0:
VERSION = getpipeoutput(["git rev-parse --short HEAD"]).split('\n')[0]
return VERSION
def getexectimeexternal():
return exectime_external