2014-08-06 23:51:44 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2019-02-23 06:34:17 +01:00
|
|
|
# Copyright 2014-2019 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2014-08-06 23:51:44 +02:00
|
|
|
|
2014-05-13 23:17:36 +02:00
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2017-09-21 22:53:43 +02:00
|
|
|
"""Data used by setup.py and the PyInstaller qutebrowser.spec."""
|
2014-05-13 23:17:36 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
2014-05-15 07:13:49 +02:00
|
|
|
import os.path
|
|
|
|
import subprocess
|
2014-09-22 20:41:12 +02:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
|
2014-05-13 23:17:36 +02:00
|
|
|
|
|
|
|
|
2015-03-26 07:57:39 +01:00
|
|
|
if sys.hexversion >= 0x03000000:
|
2017-09-21 22:53:43 +02:00
|
|
|
open_file = open
|
2015-03-26 07:57:39 +01:00
|
|
|
else:
|
|
|
|
import codecs
|
2017-09-21 22:53:43 +02:00
|
|
|
open_file = codecs.open
|
2015-03-26 07:57:39 +01:00
|
|
|
|
|
|
|
|
2014-06-06 18:47:01 +02:00
|
|
|
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
|
|
|
os.path.pardir)
|
2014-05-15 07:13:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _git_str():
|
|
|
|
"""Try to find out git version.
|
|
|
|
|
|
|
|
Return:
|
2014-06-23 16:19:43 +02:00
|
|
|
string containing the git commit ID and timestamp.
|
2014-05-15 07:13:49 +02:00
|
|
|
None if there was an error or we're not in a git repo.
|
|
|
|
"""
|
|
|
|
if BASEDIR is None:
|
|
|
|
return None
|
|
|
|
if not os.path.isdir(os.path.join(BASEDIR, ".git")):
|
|
|
|
return None
|
|
|
|
try:
|
2017-10-14 17:32:23 +02:00
|
|
|
# https://stackoverflow.com/questions/21017300/21017394#21017394
|
2017-10-23 11:22:56 +02:00
|
|
|
commit_hash = subprocess.run(
|
2017-10-14 17:32:23 +02:00
|
|
|
['git', 'describe', '--match=NeVeRmAtCh', '--always', '--dirty'],
|
2017-10-23 11:22:56 +02:00
|
|
|
cwd=BASEDIR, check=True,
|
|
|
|
stdout=subprocess.PIPE).stdout.decode('UTF-8').strip()
|
|
|
|
date = subprocess.run(
|
2014-06-23 16:19:43 +02:00
|
|
|
['git', 'show', '-s', '--format=%ci', 'HEAD'],
|
2017-10-23 11:22:56 +02:00
|
|
|
cwd=BASEDIR, check=True,
|
|
|
|
stdout=subprocess.PIPE).stdout.decode('UTF-8').strip()
|
2017-10-14 17:32:23 +02:00
|
|
|
return '{} ({})'.format(commit_hash, date)
|
2014-11-23 17:56:14 +01:00
|
|
|
except (subprocess.CalledProcessError, OSError):
|
2014-05-15 07:13:49 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def write_git_file():
|
2014-05-15 08:24:10 +02:00
|
|
|
"""Write the git-commit-id file with the current commit."""
|
2014-05-15 07:13:49 +02:00
|
|
|
gitstr = _git_str()
|
|
|
|
if gitstr is None:
|
|
|
|
gitstr = ''
|
2014-08-20 20:33:14 +02:00
|
|
|
path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id')
|
2017-09-21 22:53:43 +02:00
|
|
|
with open_file(path, 'w', encoding='ascii') as f:
|
2014-05-15 07:13:49 +02:00
|
|
|
f.write(gitstr)
|