From 25559d53ff6f9dcbbf83de5e4bb72d98a7c16011 Mon Sep 17 00:00:00 2001 From: jevans Date: Sun, 16 Jun 2013 20:02:07 -0400 Subject: [PATCH] Closes #48 --- glymur/__init__.py | 8 ++++---- glymur/test/test_jp2k.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/glymur/__init__.py b/glymur/__init__.py index 795d3d9..cc8297d 100644 --- a/glymur/__init__.py +++ b/glymur/__init__.py @@ -7,7 +7,7 @@ def _glymurrc_fname(): Search order: 1) current working directory - 2) environ var GLYMURCONFIGDIR + 2) environ var XDG_CONFIG_HOME 3) $HOME/.config/glymur/glymurrc """ @@ -63,11 +63,11 @@ def _get_configdir(): """Return string representing the configuration directory. Default is $HOME/.config/glymur. You can override this with the - GLYMURCONFIGDIR environment variable. + XDG_CONFIG_HOME environment variable. """ - if 'GLYMURCONFIGDIR' in os.environ: - return os.environ['GLYMURCONFIGDIR'] + if 'XDG_CONFIG_HOME' in os.environ: + return os.path.join(os.environ['XDG_CONFIG_HOME'], 'glymur') if 'HOME' in os.environ: return os.path.join(os.environ['HOME'], '.config', 'glymur') diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 5579c8a..3c25cca 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -599,13 +599,15 @@ class TestJp2k(unittest.TestCase): def test_config_file_via_environ(self): """Verify that we can read a configuration file set via environ var.""" with tempfile.TemporaryDirectory() as tdir: - filename = os.path.join(tdir, 'glymurrc') + configdir = os.path.join(tdir, 'glymur') + os.mkdir(configdir) + filename = os.path.join(configdir, 'glymurrc') with open(filename, 'wb') as tfile: tfile.write('[library]\n'.encode()) line = 'openjp2: {0}\n'.format(glymur._OPENJP2._name) tfile.write(line.encode()) tfile.flush() - with patch.dict('os.environ', {'GLYMURCONFIGDIR': tdir}): + with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}): imp.reload(glymur) j = Jp2k(self.jp2file) @@ -614,13 +616,15 @@ class TestJp2k(unittest.TestCase): def test_config_file_via_environ_is_wrong(self): # A non-existant library location should be rejected. with tempfile.TemporaryDirectory() as tdir: - fname = os.path.join(tdir, 'glymurrc') + configdir = os.path.join(tdir, 'glymur') + os.mkdir(configdir) + fname = os.path.join(configdir, 'glymurrc') with open(fname, 'w') as fp: with tempfile.NamedTemporaryFile(suffix='.dylib') as tfile: fp.write('[library]\n') fp.write('openjp2: {0}.not.there\n'.format(tfile.name)) fp.flush() - with patch.dict('os.environ', {'GLYMURCONFIGDIR': tdir}): + with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}): # Misconfigured new configuration file should # be rejected. with self.assertWarns(UserWarning) as cw: @@ -632,7 +636,7 @@ class TestJp2k(unittest.TestCase): # Verify that we error out properly if the configuration file # specified via environment variable is not found. with tempfile.TemporaryDirectory() as tdir: - with patch.dict('os.environ', {'GLYMURCONFIGDIR': tdir}): + with patch.dict('os.environ', {'XDG_CONFIG_HOME': tdir}): # Misconfigured new configuration file should # be rejected. with self.assertWarns(UserWarning) as cw: