logging the commit hash

This commit is contained in:
sezanzeb 2021-01-31 15:09:47 +01:00 committed by sezanzeb
parent f94f878649
commit bbe4217aad
2 changed files with 27 additions and 1 deletions

View File

@ -34,6 +34,8 @@ start = time.time()
previous_key_spam = None
COMMIT_HASH = ''
def spam(self, message, *args, **kwargs):
"""Log a more-verbose message than debug."""
@ -149,7 +151,7 @@ def log_info():
try:
name = pkg_resources.require('key-mapper')[0].project_name
version = pkg_resources.require('key-mapper')[0].version
logger.info('%s %s', name, version)
logger.info('%s %s %s', name, version, COMMIT_HASH)
evdev_version = pkg_resources.require('evdev')[0].version
logger.info('python-evdev %s', evdev_version)

View File

@ -20,7 +20,28 @@
import glob
import os
import re
from setuptools import setup
from setuptools.command.install import install
class Install(install):
"""Add the current commit hash to logger.py."""
def run(self):
commit = os.popen('git rev-parse HEAD').read().replace('\n', '')
if re.match(r'^([a-z]|[0-9])+$', commit):
with open('keymapper/logger.py', 'r') as f:
contents = f.read()
contents = contents.replace(
"COMMIT_HASH = ''",
f"COMMIT_HASH = '{commit}'"
)
with open('keymapper/logger.py', 'w') as f:
f.write(contents)
install.run(self)
setup(
@ -54,4 +75,7 @@ setup(
'evdev',
'pydbus'
],
cmdclass={
'install': Install,
},
)