Skip to content

Fix the issues with non-ASCII characters in path on Windows #1613

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

Draft
wants to merge 4 commits into
base: v0.6
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/bitmessagemain.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import sys

app_dir = os.path.dirname(os.path.abspath(__file__))
app_dir = os.path.dirname(os.path.abspath(unicode(__file__)))
os.chdir(app_dir)
sys.path.insert(0, app_dir)

Expand Down
3 changes: 2 additions & 1 deletion src/class_sqlThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self):
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
helper_sql.sql_available = True
self.conn = sqlite3.connect(state.appdata + 'messages.dat')
self.conn = sqlite3.connect(
os.path.join(state.appdata, 'messages.dat'))
self.conn.text_factory = str
self.cur = self.conn.cursor()

Expand Down
32 changes: 2 additions & 30 deletions src/namecoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import base64
import httplib
import json
import os
import socket
import sys

import defaults
import paths
import tr # translate
from addresses import decodeAddress
from bmconfigparser import BMConfigParser
Expand Down Expand Up @@ -267,34 +267,6 @@ def queryServer(self, data):
raise Exception("Socket error in RPC connection: %s" % exc)


def lookupNamecoinFolder():
"""
Look up the namecoin data folder.

.. todo:: Check whether this works on other platforms as well!
"""

app = "namecoin"
from os import path, environ
if sys.platform == "darwin":
if "HOME" in environ:
dataFolder = path.join(os.environ["HOME"],
"Library/Application Support/", app) + '/'
else:
print(
"Could not find home folder, please report this message"
" and your OS X version to the BitMessage Github."
)
sys.exit()

elif "win32" in sys.platform or "win64" in sys.platform:
dataFolder = path.join(environ["APPDATA"], app) + "\\"
else:
dataFolder = path.join(environ["HOME"], ".%s" % app) + "/"

return dataFolder


def ensureNamecoinOptions():
"""
Ensure all namecoin options are set, by setting those to default values
Expand All @@ -313,7 +285,7 @@ def ensureNamecoinOptions():
# Try to read user/password from .namecoin configuration file.
defaultUser = ""
defaultPass = ""
nmcFolder = lookupNamecoinFolder()
nmcFolder = paths.lookupUserconfigDir('namecoin')
nmcConfig = nmcFolder + "namecoin.conf"
try:
nmc = open(nmcConfig, "r")
Expand Down
62 changes: 41 additions & 21 deletions src/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,72 @@ def lookupExeFolder():
# targetdir/Bitmessage.app/Contents/MacOS/Bitmessage
os.path.dirname(sys.executable).split(os.path.sep)[0] + os.path.sep
if frozen == "macosx_app" else
os.path.dirname(sys.executable) + os.path.sep)
os.path.dirname(sys.executable).decode(
sys.getfilesystemencoding(), 'ignore') + os.path.sep)
elif __file__:
exeFolder = os.path.dirname(__file__) + os.path.sep
else:
exeFolder = ''
return exeFolder


def lookupUserconfigDir(appname):
"""Lookup user data directory for the *appname* application"""
try:
from appdirs import user_config_dir
return user_config_dir(appname, False, roaming=True) + os.path.sep
except ImportError:
pass

if sys.platform == 'darwin':
try:
dataFolder = os.path.join(
os.environ['HOME'],
"Library/Application Support/", appname) + '/'
except KeyError:
sys.exit(
"Could not find home folder, please report this message"
" and your OS X version to the BitMessage Github.")
elif sys.platform.startswith('win'):
dataFolder = os.path.join(
os.environ['APPDATA'], appname
).decode(sys.getfilesystemencoding(), 'ignore') + os.path.sep
else:
dataFolder = os.path.join(
os.environ['HOME'], '.%s' % appname) + os.path.sep

return dataFolder


def lookupAppdataFolder():
"""Returns path of the folder where application data is stored"""
APPNAME = "PyBitmessage"

dataFolder = os.environ.get('BITMESSAGE_HOME')
if dataFolder:
if dataFolder[-1] not in (os.path.sep, os.path.altsep):
dataFolder += os.path.sep
elif sys.platform == 'darwin':
try:
dataFolder = os.path.join(
os.environ['HOME'],
'Library/Application Support/', APPNAME
) + '/'
return dataFolder

except KeyError:
sys.exit(
'Could not find home folder, please report this message'
' and your OS X version to the BitMessage Github.')
elif 'win32' in sys.platform or 'win64' in sys.platform:
dataFolder = os.path.join(
os.environ['APPDATA'].decode(
sys.getfilesystemencoding(), 'ignore'), APPNAME
) + os.path.sep
else:
dataFolder = lookupUserconfigDir(APPNAME)
# Try to follow XDG spec on Linux, Unix or BSD
# TODO: use pyxdg
if os.name == 'posix' and sys.platform != 'darwin':
try:
dataFolder = os.path.join(os.environ['XDG_CONFIG_HOME'], APPNAME)
datadir = os.path.join(os.environ['XDG_CONFIG_HOME'], APPNAME)
except KeyError:
dataFolder = os.path.join(os.environ['HOME'], '.config', APPNAME)
datadir = os.path.join(os.environ['HOME'], '.config', APPNAME)

# Migrate existing data to the proper location
# if this is an existing install
try:
move(os.path.join(os.environ['HOME'], '.%s' % APPNAME), dataFolder)
move(dataFolder, datadir)
dataFolder = datadir + os.path.sep
logger.info('Moving data folder to %s', dataFolder)
except IOError:
# Old directory may not exist.
pass
dataFolder = dataFolder + os.path.sep

return dataFolder


Expand Down