From bdf3e919c9f171379e7ae938cac17ce18afc9c15 Mon Sep 17 00:00:00 2001 From: hpk Date: Mon, 5 Feb 2007 01:35:40 +0100 Subject: [PATCH] [svn r37947] added _gethomedir() helper to get at homedirectory --HG-- branch : trunk --- py/path/local/local.py | 9 +++++++++ py/path/local/testing/test_local.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/py/path/local/local.py b/py/path/local/local.py index f461f4c1f..a1c03d9fb 100644 --- a/py/path/local/local.py +++ b/py/path/local/local.py @@ -537,6 +537,15 @@ class LocalPath(common.FSPathBase, PlatformMixin): pass return None sysfind = classmethod(sysfind) + + def _gethomedir(cls): + try: + x = os.environ['HOME'] + except KeyError: + x = os.environ['HOMEPATH'] + return cls(x) + _gethomedir = classmethod(_gethomedir) + #""" #special class constructors for local filesystem paths #""" diff --git a/py/path/local/testing/test_local.py b/py/path/local/testing/test_local.py index 7e1cbb387..469cb14d4 100644 --- a/py/path/local/testing/test_local.py +++ b/py/path/local/testing/test_local.py @@ -332,6 +332,10 @@ def test_pypkgdir(): assert pkg.pypkgpath() == pkg assert pkg.join('subdir', '__init__.py').pypkgpath() == pkg +def test_homedir(): + homedir = py.path.local._gethomedir() + assert homedir.check(dir=1) + #class XTestLocalPath(TestLocalPath): # def __init__(self): # TestLocalPath.__init__(self)