[Pkg-privacy-commits] [onionshare] 50/66: Move all resources (locale, images, html, version.txt) into central resources dir, and clean up logic to find absolute paths to resources

Ulrike Uhlig u-guest at moszumanska.debian.org
Wed Apr 13 22:17:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

u-guest pushed a commit to branch master
in repository onionshare.

commit e81f809882b38c2b0890a71ae6e7e00eab7f0687
Author: Micah Lee <micah at micahflee.com>
Date:   Tue Apr 12 15:14:02 2016 -0700

    Move all resources (locale, images, html, version.txt) into central resources dir, and clean up logic to find absolute paths to resources
---
 MANIFEST.in                                     |  10 ++---
 install/build_deb.sh                            |   2 +-
 install/build_rpm.sh                            |   2 +-
 onionshare/helpers.py                           |  53 ++++++++----------------
 onionshare/strings.py                           |   7 +---
 onionshare/web.py                               |   4 +-
 onionshare_gui/common.py                        |  50 ----------------------
 onionshare_gui/downloads.py                     |   2 -
 onionshare_gui/file_selection.py                |   4 +-
 onionshare_gui/onionshare_gui.py                |   4 +-
 onionshare_gui/options.py                       |   2 -
 onionshare_gui/server_status.py                 |   8 ++--
 {onionshare => resources/html}/404.html         |   0
 {onionshare => resources/html}/index.html       |   0
 {images => resources/images}/drop_files.png     | Bin
 {images => resources/images}/logo.png           | Bin
 {images => resources/images}/server_started.png | Bin
 {images => resources/images}/server_stopped.png | Bin
 {images => resources/images}/server_working.png | Bin
 {locale => resources/locale}/cs.json            |   0
 {locale => resources/locale}/de.json            |   0
 {locale => resources/locale}/en.json            |   0
 {locale => resources/locale}/eo.json            |   0
 {locale => resources/locale}/es.json            |   0
 {locale => resources/locale}/fi.json            |   0
 {locale => resources/locale}/fr.json            |   0
 {locale => resources/locale}/it.json            |   0
 {locale => resources/locale}/nl.json            |   0
 {locale => resources/locale}/no.json            |   0
 {locale => resources/locale}/pt.json            |   0
 {locale => resources/locale}/ru.json            |   0
 {locale => resources/locale}/tr.json            |   0
 version.txt => resources/version.txt            |   0
 setup.py                                        |  48 +++++++++++----------
 34 files changed, 59 insertions(+), 137 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index c932660..f3b104e 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,12 +1,10 @@
 include LICENSE
 include README.md
 include BUILD.md
-include version.txt
-include onionshare/index.html
-include onionshare/404.html
-include onionshare/strings.json
+include resources/*
+include resources/images/*
+include resources/locale/*
+include resources/html/*
 include install/onionshare.desktop
 include install/onionshare.appdata.xml
 include install/onionshare80.xpm
-include images/*.png
-include locale/*.json
diff --git a/install/build_deb.sh b/install/build_deb.sh
index 1c4678d..8c4d487 100755
--- a/install/build_deb.sh
+++ b/install/build_deb.sh
@@ -3,7 +3,7 @@
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
 cd $DIR
 
-VERSION=`cat version.txt`
+VERSION=`cat resources/version.txt`
 
 # clean up from last build
 rm -r deb_dist >/dev/null 2>&1
diff --git a/install/build_rpm.sh b/install/build_rpm.sh
index f00d4fd..b127eed 100755
--- a/install/build_rpm.sh
+++ b/install/build_rpm.sh
@@ -3,7 +3,7 @@
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
 cd $DIR
 
-VERSION=`cat version.txt`
+VERSION=`cat resources/version.txt`
 
 # clean up from last build
 rm -r build dist >/dev/null 2>&1
diff --git a/onionshare/helpers.py b/onionshare/helpers.py
index 977ae37..d55573b 100644
--- a/onionshare/helpers.py
+++ b/onionshare/helpers.py
@@ -26,51 +26,34 @@ def get_platform():
     """
     return platform.system()
 
-def get_onionshare_dir():
+def get_resource_path(filename):
     """
-    Returns the OnionShare directory.
-    """
-    return os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
-
-def get_pyinstaller_resource_path(filename):
-    """
-    Returns the path a resource file in a frozen PyInstall app
-    """
-    # Check if app is "frozen" with pyinstaller
-    # https://pythonhosted.org/PyInstaller/#run-time-information
-    if getattr(sys, 'frozen', False):
-        p = get_platform()
-        if p == 'Darwin':
-            return os.path.join(os.path.join(os.path.dirname(sys._MEIPASS), 'Resources'), filename)
-        elif p == 'Windows':
-            return os.path.join(sys._MEIPASS, filename)
-    else:
-        return os.path.join(os.path.dirname(os.path.dirname(__file__)), filename)
-
-def get_html_path(filename):
-    """
-    Returns the path of the html files.
+    Returns the absolute path of a resource, regardless of whether OnionShare is installed
+    systemwide, and whether regardless of platform
     """
     p = get_platform()
-    if p == 'Darwin' or p == 'Windows':
-        prefix = get_pyinstaller_resource_path('html')
+    if p == 'Linux':
+        # OnionShare is installed systemwide in Linux
+        if len(sys.argv) > 0 and sys.argv[0].startswith('/usr/bin/onionshare'):
+            resources_dir = os.path.join(sys.prefix, 'share/onionshare')
+        # Look for resources directory relative to python file
+        else:
+            resources_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))), 'resources')
     else:
-        prefix = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
-    return os.path.join(prefix, filename)
+        # Check if app is "frozen" with pyinstaller
+        # https://pythonhosted.org/pyinstaller/#run-time-information
+        if getattr(sys, 'frozen', false):
+            resources_dir = sys._meipass
+        else:
+            resources_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))), 'resources')
 
+    return os.path.join(resources_dir, filename)
 
 def get_version():
     """
     Returns the version of OnionShare that is running.
     """
-    p = get_platform()
-    if p == 'Linux':
-        version_filename = os.path.join(sys.prefix, 'share/onionshare/version.txt')
-    elif p == 'Darwin' or p == 'Windows':
-        version_filename = get_pyinstaller_resource_path('version.txt')
-    else:
-        return None
-    return open(version_filename).read().strip()
+    return open(get_resource_path('version.txt')).read().strip()
 
 
 def constant_time_compare(val1, val2):
diff --git a/onionshare/strings.py b/onionshare/strings.py
index 71f0b79..61235e2 100644
--- a/onionshare/strings.py
+++ b/onionshare/strings.py
@@ -33,12 +33,7 @@ def load_strings(default="en"):
     p = helpers.get_platform()
 
     # find locale dir
-    if p == 'Linux':
-        locale_dir = os.path.join(sys.prefix, 'share/onionshare/locale')
-    elif p == 'Darwin' or p == 'Windows':
-        locale_dir = helpers.get_pyinstaller_resource_path('locale')
-    else:
-        locale_dir = ''
+    locale_dir = helpers.get_resource_path('locale')
 
     # load all translations
     translations = {}
diff --git a/onionshare/web.py b/onionshare/web.py
index 17e6fde..72b74cd 100644
--- a/onionshare/web.py
+++ b/onionshare/web.py
@@ -153,7 +153,7 @@ def index(slug_candidate):
 
     add_request(REQUEST_LOAD, request.path)
     return render_template_string(
-        open(helpers.get_html_path('index.html')).read(),
+        open(helpers.get_resource_path('html/index.html')).read(),
         slug=slug,
         file_info=file_info,
         filename=os.path.basename(zip_filename),
@@ -261,7 +261,7 @@ def page_not_found(e):
     404 error page.
     """
     add_request(REQUEST_OTHER, request.path)
-    return render_template_string(open(helpers.get_html_path('404.html')).read())
+    return render_template_string(open(helpers.get_resource_path('html/404.html')).read())
 
 # shutting down the server only works within the context of flask, so the easiest way to do it is over http
 shutdown_slug = helpers.random_string(16)
diff --git a/onionshare_gui/common.py b/onionshare_gui/common.py
deleted file mode 100644
index 6c531d9..0000000
--- a/onionshare_gui/common.py
+++ /dev/null
@@ -1,50 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-OnionShare | https://onionshare.org/
-
-Copyright (C) 2016 Micah Lee <micah at micahflee.com>
-
-This program 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.
-
-This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
-import os, sys, inspect, platform
-
-from onionshare import helpers
-
-
-def get_onionshare_gui_dir():
-    """
-    Returns the OnionShare gui directory.
-    """
-    p = helpers.get_platform()
-    if p == 'Darwin':
-        onionshare_gui_dir = os.path.dirname(__file__)
-    else:
-        onionshare_gui_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
-    return onionshare_gui_dir
-
-onionshare_gui_dir = get_onionshare_gui_dir()
-
-
-def get_image_path(filename):
-    """
-    Returns the OnionShare image path.
-    """
-    p = helpers.get_platform()
-    if p == 'Linux':
-        prefix = os.path.join(sys.prefix, 'share/onionshare/images')
-    elif p == 'Darwin' or p == 'Windows':
-        prefix = locale_dir = helpers.get_pyinstaller_resource_path('images')
-    else:
-        return None
-    return os.path.join(prefix, filename)
diff --git a/onionshare_gui/downloads.py b/onionshare_gui/downloads.py
index b9f1443..265b9bf 100644
--- a/onionshare_gui/downloads.py
+++ b/onionshare_gui/downloads.py
@@ -23,8 +23,6 @@ from PyQt5 import QtCore, QtWidgets
 
 from onionshare import strings, helpers
 
-from . import common
-
 class Download(object):
 
     def __init__(self, download_id, total_bytes):
diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py
index dae7bfa..cf1dc75 100644
--- a/onionshare_gui/file_selection.py
+++ b/onionshare_gui/file_selection.py
@@ -22,8 +22,6 @@ from PyQt5 import QtCore, QtWidgets, QtGui
 
 from onionshare import strings, helpers
 
-from . import common
-
 class FileList(QtWidgets.QListWidget):
     """
     The list of files and folders in the GUI.
@@ -49,7 +47,7 @@ class FileList(QtWidgets.QListWidget):
                 self.setAlignment(QtCore.Qt.AlignCenter)
 
                 if image:
-                    self.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(common.get_image_path('drop_files.png'))))
+                    self.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(helpers.get_resource_path('images/drop_files.png'))))
                 else:
                     self.setText(strings._('gui_drag_and_drop', True))
                     self.setStyleSheet('color: #999999;')
diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py
index 96e49d9..3e55931 100644
--- a/onionshare_gui/onionshare_gui.py
+++ b/onionshare_gui/onionshare_gui.py
@@ -21,8 +21,6 @@ from __future__ import division
 import os, sys, subprocess, inspect, platform, argparse, threading, time, math, inspect, platform
 from PyQt5 import QtCore, QtWidgets, QtGui
 
-from . import common
-
 import onionshare
 from onionshare import strings, helpers, web
 
@@ -306,7 +304,7 @@ def main():
 
     # create the onionshare icon
     global window_icon
-    window_icon = QtGui.QIcon(common.get_image_path('logo.png'))
+    window_icon = QtGui.QIcon(helpers.get_resource_path('images/logo.png'))
 
     # validation
     if filenames:
diff --git a/onionshare_gui/options.py b/onionshare_gui/options.py
index f8e0e86..386ea85 100644
--- a/onionshare_gui/options.py
+++ b/onionshare_gui/options.py
@@ -21,8 +21,6 @@ from PyQt5 import QtCore, QtWidgets
 
 from onionshare import strings, helpers
 
-from . import common
-
 class Options(QtWidgets.QHBoxLayout):
     """
     The extra onionshare options in the GUI.
diff --git a/onionshare_gui/server_status.py b/onionshare_gui/server_status.py
index 5def494..ee4c5d3 100644
--- a/onionshare_gui/server_status.py
+++ b/onionshare_gui/server_status.py
@@ -22,8 +22,6 @@ from PyQt5 import QtCore, QtWidgets, QtGui
 
 from onionshare import strings, helpers
 
-from . import common
-
 class ServerStatus(QtWidgets.QVBoxLayout):
     """
     The server status chunk of the GUI.
@@ -46,9 +44,9 @@ class ServerStatus(QtWidgets.QVBoxLayout):
         self.file_selection = file_selection
 
         # server layout
-        self.status_image_stopped = QtGui.QImage(common.get_image_path('server_stopped.png'))
-        self.status_image_working = QtGui.QImage(common.get_image_path('server_working.png'))
-        self.status_image_started = QtGui.QImage(common.get_image_path('server_started.png'))
+        self.status_image_stopped = QtGui.QImage(helpers.get_resource_path('images/server_stopped.png'))
+        self.status_image_working = QtGui.QImage(helpers.get_resource_path('images/server_working.png'))
+        self.status_image_started = QtGui.QImage(helpers.get_resource_path('images/server_started.png'))
         self.status_image_label = QtWidgets.QLabel()
         self.status_image_label.setFixedWidth(30)
         self.server_button = QtWidgets.QPushButton()
diff --git a/onionshare/404.html b/resources/html/404.html
similarity index 100%
rename from onionshare/404.html
rename to resources/html/404.html
diff --git a/onionshare/index.html b/resources/html/index.html
similarity index 100%
rename from onionshare/index.html
rename to resources/html/index.html
diff --git a/images/drop_files.png b/resources/images/drop_files.png
similarity index 100%
rename from images/drop_files.png
rename to resources/images/drop_files.png
diff --git a/images/logo.png b/resources/images/logo.png
similarity index 100%
rename from images/logo.png
rename to resources/images/logo.png
diff --git a/images/server_started.png b/resources/images/server_started.png
similarity index 100%
rename from images/server_started.png
rename to resources/images/server_started.png
diff --git a/images/server_stopped.png b/resources/images/server_stopped.png
similarity index 100%
rename from images/server_stopped.png
rename to resources/images/server_stopped.png
diff --git a/images/server_working.png b/resources/images/server_working.png
similarity index 100%
rename from images/server_working.png
rename to resources/images/server_working.png
diff --git a/locale/cs.json b/resources/locale/cs.json
similarity index 100%
rename from locale/cs.json
rename to resources/locale/cs.json
diff --git a/locale/de.json b/resources/locale/de.json
similarity index 100%
rename from locale/de.json
rename to resources/locale/de.json
diff --git a/locale/en.json b/resources/locale/en.json
similarity index 100%
rename from locale/en.json
rename to resources/locale/en.json
diff --git a/locale/eo.json b/resources/locale/eo.json
similarity index 100%
rename from locale/eo.json
rename to resources/locale/eo.json
diff --git a/locale/es.json b/resources/locale/es.json
similarity index 100%
rename from locale/es.json
rename to resources/locale/es.json
diff --git a/locale/fi.json b/resources/locale/fi.json
similarity index 100%
rename from locale/fi.json
rename to resources/locale/fi.json
diff --git a/locale/fr.json b/resources/locale/fr.json
similarity index 100%
rename from locale/fr.json
rename to resources/locale/fr.json
diff --git a/locale/it.json b/resources/locale/it.json
similarity index 100%
rename from locale/it.json
rename to resources/locale/it.json
diff --git a/locale/nl.json b/resources/locale/nl.json
similarity index 100%
rename from locale/nl.json
rename to resources/locale/nl.json
diff --git a/locale/no.json b/resources/locale/no.json
similarity index 100%
rename from locale/no.json
rename to resources/locale/no.json
diff --git a/locale/pt.json b/resources/locale/pt.json
similarity index 100%
rename from locale/pt.json
rename to resources/locale/pt.json
diff --git a/locale/ru.json b/resources/locale/ru.json
similarity index 100%
rename from locale/ru.json
rename to resources/locale/ru.json
diff --git a/locale/tr.json b/resources/locale/tr.json
similarity index 100%
rename from locale/tr.json
rename to resources/locale/tr.json
diff --git a/version.txt b/resources/version.txt
similarity index 100%
rename from version.txt
rename to resources/version.txt
diff --git a/setup.py b/setup.py
index 0854a80..48e5469 100644
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@ def file_list(path):
             files.append(os.path.join(path, filename))
     return files
 
-version = open('version.txt').read().strip()
+version = open('resources/version.txt').read().strip()
 
 description = (
     """OnionShare lets you securely and anonymously share a file of any size with someone. """
@@ -48,27 +48,32 @@ long_description = description + " " + (
 )
 
 images = [
-    'images/logo.png',
-    'images/drop_files.png',
-    'images/server_stopped.png',
-    'images/server_started.png',
-    'images/server_working.png'
+    'resources/images/logo.png',
+    'resources/images/drop_files.png',
+    'resources/images/server_stopped.png',
+    'resources/images/server_started.png',
+    'resources/images/server_working.png'
 ]
 
 locale = [
-    'locale/cs.json',
-    'locale/de.json',
-    'locale/en.json',
-    'locale/eo.json',
-    'locale/es.json',
-    'locale/fi.json',
-    'locale/fr.json',
-    'locale/it.json',
-    'locale/nl.json',
-    'locale/no.json',
-    'locale/pt.json',
-    'locale/ru.json',
-    'locale/tr.json'
+    'resources/locale/cs.json',
+    'resources/locale/de.json',
+    'resources/locale/en.json',
+    'resources/locale/eo.json',
+    'resources/locale/es.json',
+    'resources/locale/fi.json',
+    'resources/locale/fr.json',
+    'resources/locale/it.json',
+    'resources/locale/nl.json',
+    'resources/locale/no.json',
+    'resources/locale/pt.json',
+    'resources/locale/ru.json',
+    'resources/locale/tr.json'
+]
+
+html = [
+    'resources/html/index.html',
+    'resources/html/404.html',
 ]
 
 setup(
@@ -88,8 +93,9 @@ setup(
         (os.path.join(sys.prefix, 'share/applications'), ['install/onionshare.desktop']),
         (os.path.join(sys.prefix, 'share/appdata'), ['install/onionshare.appdata.xml']),
         (os.path.join(sys.prefix, 'share/pixmaps'), ['install/onionshare80.xpm']),
-        (os.path.join(sys.prefix, 'share/onionshare'), ['version.txt']),
+        (os.path.join(sys.prefix, 'share/onionshare'), ['resources/version.txt']),
         (os.path.join(sys.prefix, 'share/onionshare/images'), images),
-        (os.path.join(sys.prefix, 'share/onionshare/locale'), locale)
+        (os.path.join(sys.prefix, 'share/onionshare/locale'), locale),
+        (os.path.join(sys.prefix, 'share/onionshare/html'), html)
     ]
 )

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list