Permalink
Browse files

Now using pkg_resources to handle data files inside eggs, etc.

  • Loading branch information...
rshk committed Jan 21, 2013
1 parent 4fb5c22 commit c8bae0688ae20875b9b64bf2edf2c2e8461101a1
@@ -12,7 +12,7 @@
from PySide.QtWebKit import QWebPage, QWebSettings
from everpad.pad.editor.actions import ImagePrefs, TableWidget
from everpad.pad.tools import file_icon_path
from everpad.tools import sanitize, clean, html_unescape
from everpad.tools import sanitize, clean, html_unescape, resource_filename
from everpad.const import DEFAULT_FONT, DEFAULT_FONT_SIZE
from BeautifulSoup import BeautifulSoup
from functools import partial
@@ -21,6 +21,7 @@
import json
import re
import cgi
import sys
url = re.compile(r"((https?://|www)[-\w./#?%=&]+)")
@@ -144,7 +145,8 @@ class ContentEdit(QObject):
os.path.dirname(__file__), 'editor.html',
)
if not os.path.exists(_editor_path):
_editor_path = '/usr/share/everpad/editor.html'
_editor_path = resource_filename('share/everpad/editor.html')
_html = open(_editor_path).read()
copy_available = Signal(bool)
View
@@ -4,7 +4,7 @@
from PySide.QtGui import QApplication, QSystemTrayIcon, QMenu, QCursor
from PySide.QtNetwork import QNetworkProxyFactory
from everpad.basetypes import Note, NONE_ID, NONE_VAL
from everpad.tools import get_provider, get_pad, print_version
from everpad.tools import get_provider, get_pad, print_version, resource_filename
from everpad.pad.editor import Editor
from everpad.pad.management import Management
from everpad.pad.list import List
@@ -187,7 +187,7 @@ def __init__(self, *args, **kwargs):
self.installTranslator(self.qtTranslator)
self.appTranslator = QTranslator()
if not self.appTranslator.load(locale, os.path.join(os.path.dirname(__file__), '../../i18n')):
self.appTranslator.load(locale, '/usr/share/everpad/i18n')
self.appTranslator.load(locale, resource_filename('share/everpad/i18n'))
# This application string can be localized to 'RTL' to switch the application layout
# direction. See for example i18n/ar_EG.ts
QT_TRANSLATE_NOOP('QApplication', 'QT_LAYOUT_DIRECTION')
@@ -11,7 +11,7 @@
DEFAULT_FONT, DEFAULT_FONT_SIZE,
)
from everpad import monkey
from everpad.tools import get_proxy_config
from everpad.tools import get_proxy_config, resource_filename
import urllib
import urlparse
import oauth2 as oauth
@@ -172,7 +172,7 @@ def auto_start_state(self):
pass
else:
shutil.copyfile(
'/usr/share/applications/everpad.desktop',
resource_filename('share/applications/everpad.desktop'),
self.startup_file,
)
View
@@ -1,5 +1,7 @@
from PySide.QtGui import QIcon
import os
import sys
from everpad.tools import resource_filename
def get_icon():
@@ -16,6 +18,7 @@ def get_file_icon_path():
os.path.dirname(__file__),
'../../data/everpad-file.png',
),
resource_filename('share/icons/hicolor/48x48/actions/everpad-file.png'),
'/usr/local/share/icons/hicolor/48x48/actions/everpad-file.png',
'/usr/share/icons/hicolor/48x48/actions/everpad-file.png',
)
@@ -3,7 +3,7 @@
from singlet.lens import SingleScopeLens, ListViewCategory
from gi.repository import Gio, Unity, Notify
from singlet.utils import run_lens
from everpad.tools import get_provider, get_pad
from everpad.tools import get_provider, get_pad, resource_filename
from everpad.basetypes import Note, Tag, Notebook, Place, Resource
from everpad.const import API_VERSION
from html2text import html2text
@@ -18,7 +18,7 @@
path = os.path.join(os.path.dirname(__file__), '../../../i18n')
if not os.path.isdir(path):
path = '/usr/share/locale/'
path = resource_filename('share/locale/')
gettext.bindtextdomain('everpad', path)
gettext.textdomain('everpad')
_ = gettext.gettext
@@ -58,7 +58,7 @@ def settings_changed(self, name, value):
self.update_props()
def update_props(self):
icon = Gio.ThemedIcon.new("/usr/share/icons/unity-icon-theme/places/svg/group-recent.svg")
icon = Gio.ThemedIcon.new(resource_filename("share/icons/unity-icon-theme/places/svg/group-recent.svg"))
tags = Unity.CheckOptionFilter.new('tags', _('Tags'), icon, True)
for tag_struct in provider.list_tags():
tag = Tag.from_tuple(tag_struct)
View
@@ -6,6 +6,7 @@
import re
import sys
import os
import pkg_resources
class InterfaceWrapper(object):
@@ -147,3 +148,8 @@ def prepare_file_path(dest, file_name):
))
iteration += 1
return file_path
def resource_filename(file_name):
return pkg_resources.resource_filename(
pkg_resources.Requirement.parse("everpad"), file_name)
@@ -0,0 +1,47 @@
#!/usr/bin/env python
"""
Install dbus service files in a custom prefix.
This is needed when installing in user directory, as the standard search
path is not aware of the virtualenv.
"""
from __future__ import with_statement
import sys
import os
if len(sys.argv) > 1:
services_dir = sys.argv[1]
else:
services_dir = "~/.local/share/dbus-1/services/"
services_dir = os.path.expanduser(services_dir)
if not os.path.isdir(services_dir):
os.makedirs(services_dir)
service_files = {}
service_files["everpad-app.service"] = """\
[D-BUS Service]
Name=com.everpad.App
Exec={prefix}/bin/everpad
"""
service_files["everpad-provider.service"] = """\
[D-BUS Service]
Name=com.everpad.Provider
Exec={prefix}/bin/everpad-provider
"""
service_files["unity-lens-everpad.service"] = """\
[D-BUS Service]
Name=net.launchpad.Unity.Lens.EverpadLens
Exec={prefix}/bin/everpad-lens
"""
if __name__ == '__main__':
for filename, filetpl in service_files.iteritems():
print "Installing {} -> {}".format(filename, services_dir)
with open(os.path.join(services_dir, filename), 'w') as f:
f.write(filetpl.format(prefix=sys.prefix))

0 comments on commit c8bae06

Please sign in to comment.