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

fix portable behavior #288

Merged
merged 2 commits into from
May 2, 2023
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
6 changes: 3 additions & 3 deletions contrib/build-wine/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN echo deb ${UBUNTU_MIRROR} ${UBUNTUDIST} main restricted universe multiverse
gnupg2=2.2.27-3ubuntu2.1 \
ca-certificates=20211016 \
wget=1.21.2-2ubuntu1 \
git=1:2.34.1-1ubuntu1.8 \
git=1:2.34.1-1ubuntu1.9 \
p7zip-full=16.02+dfsg-8 \
make=4.3-4.1build1 \
autotools-dev=20220109.1 \
Expand Down Expand Up @@ -51,9 +51,9 @@ RUN echo "78b185fabdb323971d13bd329fefc8038e08559aa51c4996de18db0639a51df6 /tmp/
# cabextract is needed for winetricks to install the .NET framework
cabextract=1.9-3 \
# xvfb is needed to launch the Visual Studio installer
xvfb=2:21.1.3-2ubuntu2.7 \
xvfb=2:21.1.4-2ubuntu1.7~22.04.1 \
# winbind is needed for the Visual Studio installer and cl.exe PDB generation
winbind=2:4.15.13+dfsg-0ubuntu1
winbind=2:4.15.13+dfsg-0ubuntu1.1

RUN rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \
Expand Down
48 changes: 36 additions & 12 deletions electrum-abc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import multiprocessing
import os
import sys
import threading
import warnings
from typing import Any

import electrumabc.web as web
Expand Down Expand Up @@ -102,12 +103,21 @@ if jnius is not None:
threading.Thread.run = thread_check_run

script_dir = os.path.dirname(os.path.realpath(__file__))
IS_BUNDLE = getattr(sys, "frozen", False)
IS_LOCAL = not IS_BUNDLE and os.path.exists(
os.path.join(script_dir, "electrum-abc.desktop")
is_pyinstaller = getattr(sys, "frozen", False)
is_appimage = "APPIMAGE" in os.environ
# is_local: unpacked tar.gz but not pip installed, or git clone
is_local = (
not is_pyinstaller
and not is_appimage
and os.path.exists(os.path.join(script_dir, "electrum-abc.desktop"))
)
is_git_clone = is_local and os.path.exists(os.path.join(script_dir, ".git"))

if IS_LOCAL:
if is_git_clone:
# developers should probably see all deprecation warnings.
warnings.simplefilter("default", DeprecationWarning)

if is_local:
sys.path.insert(0, os.path.join(script_dir, "packages"))


Expand Down Expand Up @@ -487,17 +497,31 @@ def process_config_options(args: argparse.Namespace) -> dict:
if config_options.get("server"):
config_options["auto_connect"] = False

config_options["cwd"] = cwd = os.getcwd()

# FIXME: this can probably be achieved with a runtime hook (pyinstaller)
try:
tmp_folder = os.path.join(sys._MEIPASS, "is_portable") # pylint: disable=W0212
config_options["portable"] = IS_BUNDLE and os.path.exists(tmp_folder)
except AttributeError:
config_options["portable"] = False
if is_pyinstaller and os.path.exists(os.path.join(sys._MEIPASS, "is_portable")):
config_options["portable"] = True

if config_options.get("portable"):
config_options["data_path"] = os.path.join(
os.path.dirname(os.path.realpath(__file__)), PORTABLE_DATA_DIR
)
if is_local:
# running from git clone or local source: put datadir next to main script
datadir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), PORTABLE_DATA_DIR
)
else:
# Running a binary or installed source. The most generic but still
# reasonable thing is to use the current working directory.
# note: The main script is often unpacked to a temporary directory from a
# bundled executable, and we don't want to put the datadir inside a
# temp dir.
# note: Re the portable .exe on Windows, when the user double-clicks it,
# CWD gets set to the parent dir, i.e. we will put the datadir next
# to the exe
datadir = os.path.join(
os.path.dirname(os.path.realpath(cwd)), PORTABLE_DATA_DIR
)
config_options["data_path"] = datadir

is_verbose = config_options.get("verbose")
set_verbosity(is_verbose)
Expand Down
2 changes: 1 addition & 1 deletion electrumabc/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ def add_global_options(parser):
action="store_true",
dest="portable",
default=False,
help="Use local 'electron_cash_data' directory",
help="Use local 'electrum_abc_data' directory",
)
group.add_argument(
"-w", "--wallet", dest="wallet_path", help="wallet path", type=os.path.abspath
Expand Down