qutebrowser/scripts/setupcommon.py

123 lines
4.0 KiB
Python
Raw Normal View History

# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2014-05-13 23:17:36 +02:00
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
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/>.
2014-05-15 08:24:10 +02:00
"""Data used by setup.py and scripts/freeze.py."""
2014-05-13 23:17:36 +02:00
import sys
2014-06-06 18:47:01 +02:00
import re
import ast
2014-05-13 23:17:36 +02:00
import os
import os.path
import subprocess
2014-05-13 23:17:36 +02:00
sys.path.insert(0, os.getcwd())
2014-06-06 18:47:01 +02:00
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
os.path.pardir)
2014-05-13 23:17:36 +02:00
def read_file(name):
2014-05-15 08:24:10 +02:00
"""Get the string contained in the file named name."""
2014-05-13 23:17:36 +02:00
with open(name, encoding='utf-8') as f:
return f.read()
2014-06-06 18:47:01 +02:00
def _get_constant(name):
"""Read a __magic__ constant from qutebrowser/__init__.py.
We don't import qutebrowser here because it can go wrong for multiple
reasons. Instead we use re/ast to get the value directly from the source
file.
Args:
name: The name of the argument to get.
Return:
The value of the argument.
"""
field_re = re.compile(r'__{}__\s+=\s+(.*)'.format(re.escape(name)))
path = os.path.join(BASEDIR, 'qutebrowser', '__init__.py')
line = field_re.search(read_file(path)).group(1)
2014-06-19 10:11:14 +02:00
value = ast.literal_eval(line)
2014-06-06 18:47:01 +02:00
return value
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.
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:
2014-06-23 16:19:43 +02:00
cid = subprocess.check_output(
['git', 'describe', '--tags', '--dirty', '--always'],
cwd=BASEDIR).decode('UTF-8').strip()
2014-06-23 16:19:43 +02:00
date = subprocess.check_output(
['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=BASEDIR).decode('UTF-8').strip()
return '{} ({})'.format(cid, date)
except (subprocess.CalledProcessError, FileNotFoundError):
return None
def write_git_file():
2014-05-15 08:24:10 +02:00
"""Write the git-commit-id file with the current commit."""
gitstr = _git_str()
if gitstr is None:
gitstr = ''
with open(os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id'), 'w') as f:
f.write(gitstr)
2014-05-13 23:17:36 +02:00
setupdata = {
'name': 'qutebrowser',
2014-06-06 18:47:01 +02:00
'version': '.'.join(map(str, _get_constant('version_info'))),
2014-07-18 07:48:33 +02:00
'description': _get_constant('description'),
2014-06-27 09:39:33 +02:00
'long_description': read_file('README.asciidoc'),
2014-05-13 23:17:36 +02:00
'url': 'http://www.qutebrowser.org/',
2014-06-20 08:14:52 +02:00
'requires': ['rfc6266'],
2014-06-06 18:47:01 +02:00
'author': _get_constant('author'),
'author_email': _get_constant('email'),
'license': _get_constant('license'),
2014-05-13 23:17:36 +02:00
'classifiers': [
'Development Status :: 3 - Alpha',
'Environment :: X11 Applications :: Qt',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU General Public License v3 or later '
'(GPLv3+)',
'Natural Language :: English',
'Operating System :: Microsoft :: Windows',
'Operating System :: Microsoft :: Windows :: Windows XP',
'Operating System :: Microsoft :: Windows :: Windows 7',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Topic :: Internet',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Browsers',
],
'keywords': 'pyqt browser web qt webkit',
}