-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathversionInfo.py
More file actions
46 lines (36 loc) · 1.62 KB
/
Copy pathversionInfo.py
File metadata and controls
46 lines (36 loc) · 1.62 KB
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
38
39
40
41
42
43
44
45
46
"""Program version and optional Git build identification."""
import subprocess
from pathlib import Path
from extraLoggers import mustsee
from programversion import PROGRAM_VERSION
try:
# This module is generated by cewe2pdf.spec while building a PyInstaller
# executable. It is deliberately absent from a normal source checkout.
from frozenBuildInfo import FROZEN_GIT_BUILD_IDENTIFICATION
except ImportError:
FROZEN_GIT_BUILD_IDENTIFICATION = None
def getGitBuildIdentification():
"""Return the nearest cewe2pdf build tag and revision, if Git is available."""
if FROZEN_GIT_BUILD_IDENTIFICATION is not None:
return FROZEN_GIT_BUILD_IDENTIFICATION
try:
result = subprocess.run(
["git", "describe", "--tags", "--long", "--always", "--dirty",
"--match", "cewe2pdf-v*"],
cwd=Path(__file__).resolve().parent,
check=True,
capture_output=True,
text=True,
)
except (FileNotFoundError, OSError, subprocess.CalledProcessError):
return None
return result.stdout.strip() or None
def getVersionInformationText():
"""Return the user-facing version and available Git provenance."""
gitBuildIdentification = getGitBuildIdentification()
if gitBuildIdentification is None:
return f"cewe2pdf version {PROGRAM_VERSION}; Git identification is unavailable"
return f"cewe2pdf version {PROGRAM_VERSION}; Git identification: {gitBuildIdentification}"
def logVersionInformation():
"""Log the user-facing version and Git provenance when it is available."""
mustsee.info(getVersionInformationText())