Thanks to visit codestin.com
Credit goes to github.com

Skip to content

would crash if get_home() returns None #2300

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

Merged
merged 1 commit into from
Sep 30, 2013
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
50 changes: 33 additions & 17 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ def _get_xdg_config_dir():
base directory spec
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
"""
return os.environ.get('XDG_CONFIG_HOME', os.path.join(get_home(), '.config'))
home = get_home()
if home is None:
return None
else:
return os.environ.get('XDG_CONFIG_HOME', os.path.join(home, '.config'))


def _get_xdg_cache_dir():
Expand All @@ -541,7 +545,11 @@ def _get_xdg_cache_dir():
base directory spec
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_.
"""
return os.environ.get('XDG_CACHE_HOME', os.path.join(get_home(), '.cache'))
home = get_home()
if home is None:
return None
else:
return os.environ.get('XDG_CACHE_HOME', os.path.join(home, '.cache'))


def _get_config_or_cache_dir(xdg_base):
Expand All @@ -557,22 +565,28 @@ def _get_config_or_cache_dir(xdg_base):
return _create_tmp_config_dir()
return configdir

p = None
h = get_home()
p = os.path.join(h, '.matplotlib')
if (sys.platform.startswith('linux') and
not os.path.exists(p)):
p = os.path.join(xdg_base, 'matplotlib')

if os.path.exists(p):
if not _is_writable_dir(p):
return _create_tmp_config_dir()
else:
try:
mkdirs(p)
except OSError:
return _create_tmp_config_dir()
if h is not None:
p = os.path.join(h, '.matplotlib')
if (sys.platform.startswith('linux') and
not os.path.exists(p) and
xdg_base is not None):
p = os.path.join(xdg_base, 'matplotlib')

if p is not None:
if os.path.exists(p):
if _is_writable_dir(p):
return p
else:
try:
mkdirs(p)
except OSError:
pass
else:
return p

return p
return _create_tmp_config_dir()


def _get_configdir():
Expand Down Expand Up @@ -728,9 +742,11 @@ def matplotlib_fname():
if configdir is not None:
fname = os.path.join(configdir, 'matplotlibrc')
if os.path.exists(fname):
home = get_home()
if (sys.platform.startswith('linux') and
home is not None and
fname == os.path.join(
get_home(), '.matplotlib', 'matplotlibrc')):
home, '.matplotlib', 'matplotlibrc')):
warnings.warn(
"Found matplotlib configuration in ~/.matplotlib/. "
"To conform with the XDG base directory standard, "
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,15 +1324,15 @@ def findfont(prop, fontext='ttf'):
return result

else:
_fmcache = None

if not 'TRAVIS' in os.environ:
cachedir = get_cachedir()
if cachedir is not None:
if sys.version_info[0] >= 3:
_fmcache = os.path.join(cachedir, 'fontList.py3k.cache')
else:
_fmcache = os.path.join(cachedir, 'fontList.cache')
else:
_fmcache = None

fontManager = None

Expand Down