Use a dirty hack to copy icon files into package.

See #325.
This commit is contained in:
Florian Bruhin 2014-12-28 14:50:25 +01:00
parent 2a4e884e1b
commit f1435ce51f
5 changed files with 17 additions and 17 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ __pycache__
/setuptools-*.egg /setuptools-*.egg
/setuptools-*.zip /setuptools-*.zip
/qutebrowser/git-commit-id /qutebrowser/git-commit-id
/qutebrowser/icons
/doc/*.html /doc/*.html
/README.html /README.html
/qutebrowser/html/doc/ /qutebrowser/html/doc/

View File

@ -1,5 +1,6 @@
recursive-include qutebrowser/html *.html recursive-include qutebrowser/html *.html
recursive-include qutebrowser/test *.py recursive-include qutebrowser/test *.py
recursive-include qutebrowser/icons *
recursive-include icons * recursive-include icons *
include qutebrowser/test/testfile include qutebrowser/test/testfile
include qutebrowser/git-commit-id include qutebrowser/git-commit-id

View File

@ -203,7 +203,7 @@ class Application(QApplication):
icon = QIcon() icon = QIcon()
for size in (16, 24, 32, 48, 64, 96, 128, 256, 512): for size in (16, 24, 32, 48, 64, 96, 128, 256, 512):
filename = 'icons/qutebrowser-{}x{}.png'.format(size, size) filename = 'icons/qutebrowser-{}x{}.png'.format(size, size)
data = utils.read_file(filename, binary=True, use_requirement=True) data = utils.read_file(filename, binary=True)
pixmap = QPixmap() pixmap = QPixmap()
ok = pixmap.loadFromData(data, 'PNG') ok = pixmap.loadFromData(data, 'PNG')
if not ok: if not ok:

View File

@ -64,15 +64,13 @@ def compact_text(text, elidelength=None):
return out return out
def read_file(filename, binary=False, use_requirement=False): def read_file(filename, binary=False):
"""Get the contents of a file contained with qutebrowser. """Get the contents of a file contained with qutebrowser.
Args: Args:
filename: The filename to open as string. filename: The filename to open as string.
binary: Whether to return a binary string. binary: Whether to return a binary string.
If False, the data is UTF-8-decoded. If False, the data is UTF-8-decoded.
use_requirement: Use a pkg_resources.Requirement object to get
non-package data.
Return: Return:
The file contents as string. The file contents as string.
@ -87,11 +85,7 @@ def read_file(filename, binary=False, use_requirement=False):
with open(fn, 'r', encoding='utf-8') as f: with open(fn, 'r', encoding='utf-8') as f:
return f.read() return f.read()
else: else:
if use_requirement: data = pkg_resources.resource_string(qutebrowser.__name__, filename)
target = pkg_resources.Requirement('qutebrowser', '', '')
else:
target = qutebrowser.__name__
data = pkg_resources.resource_string(target, filename)
if not binary: if not binary:
data = data.decode('UTF-8') data = data.decode('UTF-8')
return data return data

View File

@ -24,16 +24,21 @@
import os import os
import os.path import os.path
import glob import glob
import shutil
from scripts import setupcommon as common from scripts import setupcommon as common
import setuptools import setuptools
try: BASEDIR = os.path.dirname(os.path.realpath(__file__))
BASEDIR = os.path.dirname(os.path.realpath(__file__))
except NameError:
BASEDIR = None icon_path = os.path.join('qutebrowser', 'icons')
shutil.rmtree(icon_path)
os.mkdir(icon_path)
for fn in glob.glob('icons/*.png'):
shutil.copy(fn, icon_path)
try: try:
@ -50,7 +55,6 @@ try:
**common.setupdata **common.setupdata
) )
finally: finally:
if BASEDIR is not None:
path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id') path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id')
if os.path.exists(path): if os.path.exists(path):
os.remove(path) os.remove(path)