move git head functionality to function in util.py
This commit is contained in:
@@ -19,6 +19,7 @@ import binascii
|
||||
import datetime
|
||||
import functools
|
||||
import itertools
|
||||
import subprocess
|
||||
import urllib.parse
|
||||
from http.cookiejar import Cookie
|
||||
from email.utils import mktime_tz, parsedate_tz
|
||||
@@ -273,6 +274,22 @@ Response Headers
|
||||
fp.write(response.content)
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def git_head():
|
||||
try:
|
||||
out, err = subprocess.Popen(
|
||||
("git", "rev-parse", "--short", "HEAD"),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
cwd=os.path.dirname(os.path.abspath(__file__)),
|
||||
).communicate()
|
||||
if out and not err:
|
||||
return out.decode().rstrip()
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def expand_path(path):
|
||||
"""Expand environment variables and tildes (~)"""
|
||||
if not path:
|
||||
|
||||
Reference in New Issue
Block a user