move git head functionality to function in util.py
This commit is contained in:
@@ -118,25 +118,15 @@ def main():
|
||||
config.set(("output",), "mode", "null")
|
||||
elif args.loglevel <= logging.DEBUG:
|
||||
import platform
|
||||
import subprocess
|
||||
import os.path
|
||||
import requests
|
||||
|
||||
extra = ""
|
||||
if getattr(sys, "frozen", False):
|
||||
extra = " - Executable"
|
||||
else:
|
||||
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:
|
||||
extra = " - Git HEAD: " + out.decode().rstrip()
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
pass
|
||||
git_head = util.git_head()
|
||||
if git_head:
|
||||
extra = " - Git HEAD: " + git_head
|
||||
|
||||
log.debug("Version %s%s", __version__, extra)
|
||||
log.debug("Python %s - %s",
|
||||
|
||||
@@ -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