Skip to content

Commit fd21fb2

Browse files
committed
print out fact version + git hash on start
1 parent 3ae3656 commit fd21fb2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/fact_base.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import logging
22
import os
33
import signal
4+
import sys
5+
from pathlib import Path
46
from time import sleep
57

68
import config
79

810
try:
11+
import git
912
import psutil
1013
import psycopg2 # noqa: F401
1114

1215
from helperFunctions.program_setup import setup_argparser, setup_logging
1316
from statistic.work_load import WorkLoadStatistic
1417
from storage.db_interface_base import DbInterfaceError
1518
from storage.migration import db_needs_migration
19+
from version import __VERSION__
1620
except (ImportError, ModuleNotFoundError):
1721
logging.exception(
1822
'Could not load dependencies. Please make sure that you have installed FACT correctly '
@@ -37,11 +41,23 @@ def __init__(self):
3741
self.args = setup_argparser(self.PROGRAM_NAME, self.PROGRAM_DESCRIPTION)
3842
config.load(self.args.config_file)
3943
setup_logging(self.args, self.COMPONENT)
44+
python_version, *_ = sys.version.split(' ')
45+
logging.info(
46+
f'Starting {self.PROGRAM_NAME} @ {__VERSION__} ({self._get_git_revision()}, Python {python_version})'
47+
)
4048
self.do_self_test()
4149

4250
self._register_signal_handlers()
4351
self.work_load_stat = WorkLoadStatistic(component=self.COMPONENT)
4452

53+
@staticmethod
54+
def _get_git_revision() -> str:
55+
try:
56+
repo = git.Repo(Path(__file__), search_parent_directories=True)
57+
return f'commit {repo.head.object.hexsha}'
58+
except git.exc.InvalidGitRepositoryError:
59+
return 'unknown revision'
60+
4561
def _register_signal_handlers(self):
4662
# Check whether the process was started by start_fact.py
4763
parent = ' '.join(psutil.Process(os.getppid()).cmdline())

src/install/requirements_common.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ setuptools<66
77
# General python dependencies
88
appdirs==1.4.4
99
flaky==3.7.0
10+
gitpython~=3.1.40
1011
lief==0.12.3
1112
psutil==5.9.4
1213
psycopg2-binary==2.9.5

0 commit comments

Comments
 (0)