diff --git a/Util/sysinfo.py b/Util/sysinfo.py new file mode 100644 index 00000000..b9b5c3e2 --- /dev/null +++ b/Util/sysinfo.py @@ -0,0 +1,27 @@ + +import os +import subprocess + +# Return the git revision as a string +def git_version(): + def _minimal_ext_cmd(cmd): + # construct minimal environment + env = {} + for k in ['SYSTEMROOT', 'PATH']: + v = os.environ.get(k) + if v is not None: + env[k] = v + # LANGUAGE is used on win32 + env['LANGUAGE'] = 'C' + env['LANG'] = 'C' + env['LC_ALL'] = 'C' + out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0] + return out + + try: + out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) + git_revision = out.strip().decode('ascii') + except OSError: + git_revision = 'Unknown' + + return git_revision \ No newline at end of file diff --git a/main.py b/main.py index aaff9a27..916f5c03 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from Engine.Framework import Framework from config.config import Config +from Util.sysinfo import git_version def set_arg_parser(): @@ -55,9 +56,6 @@ def set_arg_parser(): if __name__ == '__main__': - cli_args = set_arg_parser().parse_args() - Config().load_file(cli_args.config_file) - Config().load_parameters(cli_args) consoleFormatter = logging.Formatter('[%(levelname)-5.5s] - %(name)-22.22s: %(message)s') consoleHandler = logging.StreamHandler(stream=stdout) @@ -65,12 +63,18 @@ def set_arg_parser(): logging.basicConfig(level=logging.NOTSET, handlers=[consoleHandler]) + cli_args = set_arg_parser().parse_args() + Config().load_file(cli_args.config_file) + Config().load_parameters(cli_args) + logger = logging.getLogger('Main') logger.info('Color: {}, Field side: {}, Mode: {}'.format(Config()['GAME']['our_color'].upper(), 'NEGATIVE' if Config()['GAME']['on_negative_side'] else 'POSITIVE', 'COMPETITION' if cli_args.competition_mode else 'NORMAL')) + logger.info('Current git commit hash: ' + git_version()) + stop_framework = False while not stop_framework: try: