Re-format, moved imports, fixed spelling error

master
oGre 10 years ago
parent bbe02ddce9
commit dd324dcdb2
  1. 23
      gitstatus.py

@ -8,9 +8,16 @@ http://docs.python.org/3.0/library/functions.html?highlight=print#print
Shamelessly ripped from http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python
"""
# change those symbols to whatever you prefer
symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash': ':'}
__all__ = ["Print"]
import sys
import re
import shlex
from subprocess import Popen, PIPE, check_output
__all__ = ["Print"]
try:
Print = eval("print") # python 3.0 case
except SyntaxError:
@ -21,6 +28,8 @@ except SyntaxError:
del D
except SyntaxError:
del D
def Print(*args, **kwd): # 2.4, 2.5, define our own Print function
fout = kwd.get("file", sys.stdout)
w = fout.write
@ -32,14 +41,6 @@ except SyntaxError:
w(str(a))
w(kwd.get("end", "\n"))
# change those symbols to whatever you prefer
symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash':':'}
import sys
import re
import shlex
from subprocess import Popen, PIPE, check_output
def get_tagname_or_hash():
"""return tagname if exists else hash"""
@ -61,6 +62,7 @@ def get_tagname_or_hash():
return hash_
return None
def get_stash():
cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE)
so, se = cmd.communicate()
@ -72,11 +74,12 @@ def get_stash():
except IOError:
return 0
# `git status --porcelain --branch` can collect all information
# branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind
po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'},
stdout=PIPE, stderr=PIPE)
stdout, sterr = po.communicate()
stdout, stderr = po.communicate()
if po.returncode != 0:
sys.exit(0) # Not a git repository

Loading…
Cancel
Save