Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Tribler PyQt GUI #2153

Merged
merged 9 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ doc/_build/

# Twisted
twisted/plugins/dropin.cache
twistd.pid
8 changes: 4 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ confidence=
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
#disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating
disable=C0321,W0142,invalid-name,missing-docstring
disable=C0321,W0142,invalid-name,missing-docstring,no-member,no-name-in-module,no-self-use,too-few-public-methods
#missing-type-doc


Expand Down Expand Up @@ -330,7 +330,7 @@ int-import-graph=
[DESIGN]

# Maximum number of arguments for function / method
max-args=5
max-args=6

# Argument names that match this expression will be ignored. Default to name
# with leading underscore
Expand All @@ -340,7 +340,7 @@ ignored-argument-names=_.*
max-locals=15

# Maximum number of return / yield for function / method body
max-returns=6
max-returns=8

# Maximum number of branch for function / method body
max-branches=12
Expand All @@ -352,7 +352,7 @@ max-statements=50
max-parents=7

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=10

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
Expand Down
2 changes: 0 additions & 2 deletions Tribler/Core/CacheDB/sqlitecachedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
from Tribler.dispersy.taskmanager import TaskManager
from Tribler.dispersy.util import blocking_call_on_reactor_thread, call_on_reactor_thread

from Tribler import LIBRARYNAME
from Tribler.Core.CacheDB.db_versions import LATEST_DB_VERSION


DB_SCRIPT_NAME = u"schema_sdb_v%s.sql" % str(LATEST_DB_VERSION)
DB_SCRIPT_RELATIVE_PATH = os.path.join(LIBRARYNAME, DB_SCRIPT_NAME)

DB_FILE_NAME = u"tribler.sdb"
DB_DIR_NAME = u"sqlite"
Expand Down
11 changes: 4 additions & 7 deletions Tribler/Core/Category/Category.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import logging
from ConfigParser import MissingSectionHeaderError, ParsingError

from Tribler import LIBRARYNAME
from Tribler.Core.Category.init_category import getCategoryInfo
from Tribler.Core.Category.FamilyFilter import XXXFilter
from Tribler.Core.Utilities.install_dir import determine_install_dir
from Tribler.Core.Utilities.install_dir import get_lib_path

CATEGORY_CONFIG_FILE = "category.conf"

Expand All @@ -18,20 +17,18 @@ class Category(object):

__size_change = 1024 * 1024

def __init__(self, install_dir=determine_install_dir(), ffEnabled=False):
def __init__(self, ffEnabled=False):
self._logger = logging.getLogger(self.__class__.__name__)

self.install_dir = install_dir

filename = os.path.join(self.install_dir, LIBRARYNAME, u'Core', u'Category', CATEGORY_CONFIG_FILE)
filename = os.path.join(get_lib_path(), u'Core', u'Category', CATEGORY_CONFIG_FILE)
try:
self.category_info = getCategoryInfo(filename)
self.category_info.sort(cmp_rank)
except (MissingSectionHeaderError, ParsingError, IOError):
self.category_info = []
self._logger.critical('', exc_info=True)

self.xxx_filter = XXXFilter(self.install_dir)
self.xxx_filter = XXXFilter()

self._logger.debug("category: Categories defined by user: %s", self.getCategoryNames())

Expand Down
6 changes: 3 additions & 3 deletions Tribler/Core/Category/FamilyFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import os
import logging

from Tribler import LIBRARYNAME
from Tribler.Core.Utilities.install_dir import get_lib_path

WORDS_REGEXP = re.compile('[a-zA-Z0-9]+')


class XXXFilter(object):

def __init__(self, install_dir):
def __init__(self):
super(XXXFilter, self).__init__()
self._logger = logging.getLogger(self.__class__.__name__)

termfilename = os.path.join(install_dir, LIBRARYNAME, 'Core', 'Category', 'filter_terms.filter')
termfilename = os.path.join(get_lib_path(), 'Core', 'Category', 'filter_terms.filter')
self.xxx_terms, self.xxx_searchterms = self.initTerms(termfilename)

def initTerms(self, filename):
Expand Down
3 changes: 2 additions & 1 deletion Tribler/Core/Config/tribler_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
from configobj import ConfigObj
from validate import Validator
from Tribler.Core.Utilities.install_dir import get_lib_path
from Tribler.Core.simpledefs import STATEDIR_CONFIG


CONFIGSPEC_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.spec')
CONFIGSPEC_PATH = os.path.join(get_lib_path(), 'Core', 'Config', 'config.spec')


class TriblerConfig(object):
Expand Down
8 changes: 6 additions & 2 deletions Tribler/Core/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
from Tribler.Core import NoDispersyRLock
from Tribler.Core.APIImplementation.LaunchManyCore import TriblerLaunchMany
from Tribler.Core.CacheDB.Notifier import Notifier
from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB, DB_FILE_RELATIVE_PATH, DB_SCRIPT_RELATIVE_PATH
from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB, DB_FILE_RELATIVE_PATH, DB_SCRIPT_NAME
from Tribler.Core.Config.tribler_config import TriblerConfig
from Tribler.Core.Modules.restapi.rest_manager import RESTManager
from Tribler.Core.SessionConfig import SessionConfigInterface, SessionStartupConfig
from Tribler.Core.Upgrade.upgrade import TriblerUpgrader
from Tribler.Core.Utilities.configparser import CallbackConfigParser
from Tribler.Core.Utilities.crypto_patcher import patch_crypto_be_discovery
from Tribler.Core.Utilities.install_dir import get_lib_path
from Tribler.Core.defaults import tribler_defaults
from Tribler.Core.exceptions import NotYetImplementedException, OperationNotEnabledByConfigurationException, \
DuplicateTorrentFileError
Expand Down Expand Up @@ -73,6 +75,8 @@ def __init__(self, scfg=None, ignore_singleton=False, autoload_discovery=True):
"""
addObserver(self.unhandled_error_observer)

patch_crypto_be_discovery()

if not ignore_singleton:
if Session.__single:
raise RuntimeError("Session is singleton")
Expand Down Expand Up @@ -199,7 +203,7 @@ def prestart(self):
self.lm.api_manager.start()

db_path = os.path.join(self.get_state_dir(), DB_FILE_RELATIVE_PATH)
db_script_path = os.path.join(self.get_install_dir(), DB_SCRIPT_RELATIVE_PATH)
db_script_path = os.path.join(get_lib_path(), DB_SCRIPT_NAME)

self.sqlite_db = SQLiteCacheDB(db_path, db_script_path)
self.sqlite_db.initialize()
Expand Down
25 changes: 25 additions & 0 deletions Tribler/Core/Utilities/crypto_patcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
from Tribler.Core.Utilities.install_dir import is_frozen


def patch_crypto_be_discovery():
"""
Monkey patches cryptography's backend detection.
Objective: support pyinstaller freezing.
"""
if (sys.platform == 'win32' or sys.platform == 'darwin') and is_frozen():
from cryptography.hazmat import backends

try:
from cryptography.hazmat.backends.commoncrypto.backend import backend as be_cc
except ImportError:
be_cc = None

try:
from cryptography.hazmat.backends.openssl.backend import backend as be_ossl
except ImportError:
be_ossl = None

backends._available_backends_list = [
be for be in (be_cc, be_ossl) if be is not None
]
57 changes: 32 additions & 25 deletions Tribler/Core/Utilities/install_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,40 @@
# Code:
import os.path
import sys
import Tribler

from Tribler.Core.osutils import is_android, get_home_dir


# This function is used from tribler.py too, but can't be there as tribler.py
# gets frozen into an exe on windows.
def is_frozen():
"""
Return whether we are running in a frozen environment
"""
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
return False
return True


def get_base_path():
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.join(os.path.dirname(Tribler.__file__), '..')
return base_path


def get_lib_path():
if is_frozen():
return os.path.join(get_base_path(), 'tribler_source', 'Tribler')
return os.path.join(get_base_path(), 'Tribler')


# This function is used from tribler.py too, but can't be there as tribler.py gets frozen into an exe on windows.
def determine_install_dir():
# Niels, 2011-03-03: Working dir sometimes set to a browsers working dir
# only seen on windows
Expand All @@ -52,30 +80,9 @@ def determine_install_dir():
# TODO(emilon): tribler_main.py is not frozen, so I think the special
# treatment for windows could be removed (Needs to be tested)
if sys.platform == 'win32':
def we_are_frozen():
"""Returns whether we are frozen via py2exe.
This will affect how we find out where we are located."""
return hasattr(sys, "frozen")

def module_path():
""" This will get us the program's directory,
even if we are frozen using py2exe"""
if we_are_frozen():
return os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding()))

filedir = os.path.dirname(unicode(__file__, sys.getfilesystemencoding()))
return os.path.abspath(os.path.join(filedir, '..', '..', '..'))

return module_path()

return get_base_path()
elif sys.platform == 'darwin':
# On a packaged app, this file will be at:
# Tribler.app/Contents/Resources/lib/Python2.7/site-packages.zip/Tribler/Core/Utilities/install_dir.py
cur_file = os.path.dirname(__file__)
if "site-packages.zip" in cur_file:
return os.path.abspath(os.path.join(cur_file, '..', '..', '..', '..', '..', '..'))
# Otherwise do the same than on Unix/Linux

return get_base_path()
elif is_android():
return os.path.abspath(os.path.join(unicode(os.environ['ANDROID_PRIVATE']), u'lib/python2.7/site-packages'))

Expand Down
103 changes: 50 additions & 53 deletions Tribler/Main/Build/Mac/Info.plist
Original file line number Diff line number Diff line change
@@ -1,57 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>torrent</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>TriblerDoc</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/x-bittorrent</string>
</array>
<key>CFBundleTypeName</key>
<string>BitTorrent Meta-Info</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>BTMF</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>NSDocumentClass</key>
<string>DownloadDocument</string>
</dict>
<dict>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
<string>fold</string>
<string>disk</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>Tribler</string>
<key>CFBundleIconFile</key>
<string>tribler.icns</string>
<key>CFBundleIdentifier</key>
<string>Tribler</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Tribler</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
</dict>
<dict>
<key>CFBundleVersion</key>
<string>__VERSION__</string>
<key>CFBundleShortVersionString</key>
<string>__VERSION__</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleDisplayName</key>
<string>tribler</string>
<key>CFBundleIconFile</key>
<string>tribler.icns</string>
<key>CFBundleIdentifier</key>
<string>nl.tudelft.tribler</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>magnet URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>magnet</string>
</array>
</dict>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>torrent</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>tribler.icns</string>
<key>CFBundleTypeName</key>
<string>BitTorrent Document</string>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>MacOS/tribler</string>
<key>CFBundleName</key>
<string>tribler</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>LSBackgroundOnly</key>
<string>0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Tribler/Main/Build/Ubuntu/tribler.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Icon=tribler
Terminal=false
Type=Application
Categories=Application;Network;P2P
MimeType=x-scheme-handler/ppsp;x-scheme-handler/tswift;x-scheme-handler/magnet
MimeType=x-scheme-handler/ppsp;x-scheme-handler/tswift;x-scheme-handler/magnet;application/x-bittorrent
Binary file added Tribler/Main/Build/Win/tribler.ico
Binary file not shown.
Loading