jenkins-bot has submitted this change and it was merged.
Change subject: Returns unknown version when git repo is cleaned, instead of crashing ......................................................................
Returns unknown version when git repo is cleaned, instead of crashing
When the git repo is clean, version.py can't open the git version file to get hash and crashes, causes crash of all scripts.
Bug: T91904 Change-Id: Iaa6458e60e42bf3026ff56af9e797ec580e6bb85 --- M pywikibot/version.py 1 file changed, 8 insertions(+), 3 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/version.py b/pywikibot/version.py index 3eba2a0..ee49fe7 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -117,7 +117,7 @@ date = time.strptime(date, "%Y-%m-%d %H:%M:%S") return rev, date if not rev: - return "(unknown)", time.strptime("2000-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") + raise ParseError return rev, date
@@ -185,8 +185,13 @@ subprocess.Popen([cmd], stdout=subprocess.PIPE).communicate() except: #Means git hasn't been installed, no way to get the date, retreving date from gitblit - hsh = open(os.path.join(_program_dir, '.git/refs/heads/master'), 'r').read().strip(" \n") - rev, date = getversion_git_windows(hsh, path) + file_path = os.path.join(_program_dir, '.git/refs/heads/master') + if os.path.isfile(file_path): + with open(file_path, 'r') as hash_file: + hsh = hash_file.read().strip(' \n') + rev, date = getversion_git_windows(hsh, path) + else: + raise ParseError tag = open(os.path.join(_program_dir, '.git/config'), 'r').read() s = tag.find('url = ', tag.find('[remote "origin"]')) e = tag.find('\n', s)
pywikibot-commits@lists.wikimedia.org