Selaa lähdekoodia

Cleaner output when not outputting to a tty.

Allow piping into a log file more cleanly without spewing \r (on Linux which
supports os.isatty()).
Heikki Hokkanen 16 vuotta sitten
vanhempi
commit
8908774429
1 muutettua tiedostoa jossa 6 lisäystä ja 2 poistoa
  1. 6
    2
      gitstats

+ 6
- 2
gitstats Näytä tiedosto

@@ -5,6 +5,7 @@ import datetime
5 5
 import glob
6 6
 import os
7 7
 import pickle
8
+import platform
8 9
 import re
9 10
 import shutil
10 11
 import subprocess
@@ -14,6 +15,7 @@ import zlib
14 15
 
15 16
 GNUPLOT_COMMON = 'set terminal png transparent\nset size 0.5,0.5\n'
16 17
 MAX_EXT_LENGTH = 10 # maximum file extension length
18
+ON_LINUX = (platform.system() == 'Linux')
17 19
 
18 20
 exectime_internal = 0.0
19 21
 exectime_external = 0.0
@@ -28,7 +30,7 @@ if 'GNUPLOT' in os.environ:
28 30
 def getpipeoutput(cmds, quiet = False):
29 31
 	global exectime_external
30 32
 	start = time.time()
31
-	if not quiet:
33
+	if not quiet and ON_LINUX and os.isatty(1):
32 34
 		print '>> ' + ' | '.join(cmds),
33 35
 		sys.stdout.flush()
34 36
 	p0 = subprocess.Popen(cmds[0], stdout = subprocess.PIPE, shell = True)
@@ -39,7 +41,9 @@ def getpipeoutput(cmds, quiet = False):
39 41
 	output = p.communicate()[0]
40 42
 	end = time.time()
41 43
 	if not quiet:
42
-		print '\r[%.5f] >> %s' % (end - start, ' | '.join(cmds))
44
+		if ON_LINUX and os.isatty(1):
45
+			print '\r',
46
+		print '[%.5f] >> %s' % (end - start, ' | '.join(cmds))
43 47
 	exectime_external += (end - start)
44 48
 	return output.rstrip('\n')
45 49