Trading in ~/.glymur for ~/.config/glymur. Closes #47

This commit is contained in:
John Evans 2013-06-16 11:26:02 -04:00
commit 8c6bb1cc14
3 changed files with 25 additions and 7 deletions

View file

@ -172,8 +172,8 @@ because ctypes access libraries in a platform-dependent manner, it is
recommended that you create a configuration file to help glymur properly find
the openjp2 library. You may create the configuration file as follows::
$ mkdir ~/.glymur
$ cd ~/.glymur
$ mkdir -p ~/.config/glymur
$ cd ~/.config/glymur
$ cat > glymurrc << EOF
> [library]
> openjp2: /opt/openjp2-svn/lib/libopenjp2.so

View file

@ -8,7 +8,7 @@ def _glymurrc_fname():
Search order:
1) current working directory
2) environ var GLYMURCONFIGDIR
3) HOME/.glymur/glymurrc
3) $HOME/.config/glymur/glymurrc
"""
# Current directory.
@ -62,15 +62,15 @@ def _config():
def _get_configdir():
"""Return string representing the configuration directory.
Default is HOME/.glymur. You can override this with the GLYMURCONFIGDIR
environment variable.
Default is $HOME/.config/glymur. You can override this with the
GLYMURCONFIGDIR environment variable.
"""
if 'GLYMURCONFIGDIR' in os.environ:
return os.environ['GLYMURCONFIGDIR']
if 'HOME' in os.environ:
return os.path.join(os.environ['HOME'], '.glymur')
return os.path.join(os.environ['HOME'], '.config', 'glymur')
import warnings
import sys

View file

@ -641,7 +641,7 @@ class TestJp2k(unittest.TestCase):
@unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.")
def test_home_dir_missing_config_dir(self):
# Verify no exception is raised if $HOME is missing .glymur directory.
# Verify no exception is raised if $HOME is missing .config directory.
with tempfile.TemporaryDirectory() as tdir:
with patch.dict('os.environ', {'HOME': tdir}):
# Misconfigured new configuration file should
@ -649,6 +649,24 @@ class TestJp2k(unittest.TestCase):
with self.assertWarns(UserWarning) as cw:
imp.reload(glymur)
@unittest.skipIf(sys.hexversion < 0x03020000,
"Uses features introduced in 3.2.")
def test_home_dir_missing_glymur_rc_dir(self):
# Should warn but not error if $HOME/.config but no glymurrc dir.
with tempfile.TemporaryDirectory() as tdir:
# We need the subdirectory to be specifically named as ".config"
# in order for this test to work. A specifically-named temporary
# directory does not seem to be possible, so try to symlink it.
# Supposedly the symlink gets cleaned up with tdir gets cleaned up.
with tempfile.TemporaryDirectory(suffix=".config", dir=tdir) \
as tdir_config:
os.symlink(tdir_config, os.path.join(tdir, '.config'))
with patch.dict('os.environ', {'HOME': tdir}):
# Misconfigured new configuration file should
# be rejected.
with self.assertWarns(UserWarning) as cw:
imp.reload(glymur)
def test_xmp_attribute(self):
# Verify that we can read the XMP packet in our shipping example file.
j = Jp2k(self.jp2file)