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-*.zip
/qutebrowser/git-commit-id
/qutebrowser/icons
/doc/*.html
/README.html
/qutebrowser/html/doc/

View File

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

View File

@ -203,7 +203,7 @@ class Application(QApplication):
icon = QIcon()
for size in (16, 24, 32, 48, 64, 96, 128, 256, 512):
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()
ok = pixmap.loadFromData(data, 'PNG')
if not ok:

View File

@ -64,15 +64,13 @@ def compact_text(text, elidelength=None):
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.
Args:
filename: The filename to open as string.
binary: Whether to return a binary string.
If False, the data is UTF-8-decoded.
use_requirement: Use a pkg_resources.Requirement object to get
non-package data.
Return:
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:
return f.read()
else:
if use_requirement:
target = pkg_resources.Requirement('qutebrowser', '', '')
else:
target = qutebrowser.__name__
data = pkg_resources.resource_string(target, filename)
data = pkg_resources.resource_string(qutebrowser.__name__, filename)
if not binary:
data = data.decode('UTF-8')
return data

View File

@ -24,16 +24,21 @@
import os
import os.path
import glob
import shutil
from scripts import setupcommon as common
import setuptools
try:
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:
@ -50,7 +55,6 @@ try:
**common.setupdata
)
finally:
if BASEDIR is not None:
path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id')
if os.path.exists(path):
os.remove(path)