Permalink
Browse files

Use pkg_resources to access icons files and store them in the egg.

Now that icons are stored within the egg and that we can use pkg_resources
to find them, this also remove a bunch of lines which wer trying to guess where
was the icons.
  • Loading branch information...
1 parent 42d72da commit 077e1e7a0e84411ac700d338eeedf36f61827239 @multani committed Jan 1, 2012
Showing with 17 additions and 26 deletions.
  1. +4 −2 setup.py
  2. +13 −24 sonata/main.py
View
@@ -76,7 +76,7 @@ def rmgeneric(path, __func__):
'Topic :: Multimedia :: Sound :: Players',
],
packages=["sonata", "sonata.plugins"],
- package_dir={"sonata": "sonata/"},
+ package_dir={"sonata": "sonata"},
ext_modules=[
Extension(
"mmkeys",
@@ -89,7 +89,6 @@ def rmgeneric(path, __func__):
data_files=[
('share/sonata', ['README.old', 'CHANGELOG', 'TODO', 'TRANSLATORS']),
('share/applications', ['sonata.desktop']),
- ('share/pixmaps', glob.glob('sonata/pixmaps/*')),
('share/man/man1', ['sonata.1']),
('share/locale/de/LC_MESSAGES', ['mo/de/sonata.mo']),
('share/locale/pl/LC_MESSAGES', ['mo/pl/sonata.mo']),
@@ -116,6 +115,9 @@ def rmgeneric(path, __func__):
('share/locale/zh_TW/LC_MESSAGES', ['mo/zh_TW/sonata.mo']),
('share/locale/uk/LC_MESSAGES', ['mo/uk/sonata.mo'])
],
+ package_data={
+ 'sonata': ['pixmaps/*.*'],
+ },
entry_points={
'console_scripts': [
'sonata=sonata.launcher:run',
View
@@ -38,6 +38,8 @@
import gtk
import pango
+import pkg_resources
+
# Default to no sugar, then test...
HAVE_SUGAR = False
@@ -3446,34 +3448,21 @@ def update_menu_visibility(self, show_songinfo_only=False):
'pl', 'update', 'sort', 'tag']:
self.UIManager.get_widget('/mainmenu/' + menu + 'menu/').hide()
- def find_path(self, filename):
- full_filename = None
+ def find_path(self, icon_name):
+ # TOOD: when Sugar support has been removed, simplify this function:
+ # remove temporary variables, simplify the check on the file existence
if HAVE_SUGAR:
full_filename = os.path.join(activity.get_bundle_path(),
- 'share', filename)
+ 'share', icon_name)
else:
- if os.path.exists(os.path.join(os.path.split(__file__)[0],
- filename)):
- full_filename = os.path.join(os.path.split(__file__)[0],
- filename)
- elif os.path.exists(os.path.join(os.path.split(__file__)[0],
- 'pixmaps', filename)):
- full_filename = os.path.join(os.path.split(__file__)[0],
- 'pixmaps', filename)
- elif os.path.exists(os.path.join(os.path.split(__file__)[0],
- 'share', filename)):
- full_filename = os.path.join(os.path.split(__file__)[0],
- 'share', filename)
- elif os.path.exists(os.path.join(__file__.split('/lib')[0],
- 'share', 'pixmaps', filename)):
- full_filename = os.path.join(__file__.split('/lib')[0],
- 'share', 'pixmaps', filename)
- elif os.path.exists(os.path.join(sys.prefix,
- 'share', 'pixmaps', filename)):
- full_filename = os.path.join(sys.prefix,
- 'share', 'pixmaps', filename)
+ full_filename = pkg_resources.resource_filename(
+ __name__, "pixmaps/%s" % icon_name)
+
+ if not os.path.exists(full_filename):
+ full_filename = None
+
if not full_filename:
- self.logger.critical("%r cannot be found. Aborting...", filename)
+ self.logger.critical("Icon %r cannot be found. Aborting...", icon_name)
sys.exit(1)
return full_filename

0 comments on commit 077e1e7

Please sign in to comment.