From fad6437726c36f02e6b43a18f519ca2b43d1b8f2 Mon Sep 17 00:00:00 2001 From: rawgni Date: Fri, 19 Aug 2016 11:19:32 +0700 Subject: [PATCH 1/2] add commit hash info --- pokecli.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pokecli.py b/pokecli.py index 85f5c4a1c4..2bb713a626 100644 --- a/pokecli.py +++ b/pokecli.py @@ -34,6 +34,7 @@ import sys import time import signal +import subprocess from datetime import timedelta from getpass import getpass from pgoapi.exceptions import NotLoggedInException, ServerSideRequestThrottlingException, ServerBusyOrOfflineException @@ -70,8 +71,12 @@ def handle_sigint(*args): raise SIGINTRecieved signal.signal(signal.SIGINT, handle_sigint) + def get_commit_hash(): + return subprocess.check_output(['git', 'rev-parse', 'HEAD']) + try: logger.info('PokemonGO Bot v1.0') + logger.info('commit: ' + get_commit_hash()) sys.stdout = codecs.getwriter('utf8')(sys.stdout) sys.stderr = codecs.getwriter('utf8')(sys.stderr) From 240345ba8b0bc166c6421dbc58bcd26d37f27949 Mon Sep 17 00:00:00 2001 From: rawgni Date: Fri, 19 Aug 2016 15:34:05 +0700 Subject: [PATCH 2/2] check if the hash if a valid hex --- pokecli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pokecli.py b/pokecli.py index 2bb713a626..a21e4a0ed8 100644 --- a/pokecli.py +++ b/pokecli.py @@ -34,6 +34,7 @@ import sys import time import signal +import string import subprocess from datetime import timedelta from getpass import getpass @@ -72,7 +73,12 @@ def handle_sigint(*args): signal.signal(signal.SIGINT, handle_sigint) def get_commit_hash(): - return subprocess.check_output(['git', 'rev-parse', 'HEAD']) + try: + hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT)[:-1] + + return hash if all(c in string.hexdigits for c in hash) else "not found" + except: + return "not found" try: logger.info('PokemonGO Bot v1.0')