提交 d9faeadc 编写于 作者: A Amador Pahim

avocado.core.data_dir Move _usable_rw_dir() to utils.path.

Promoting data_dir private _usable_rw_dir() function to be a
public utils.path function, since it's going to be used for the
asset fetcher feature.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 8df3859a
......@@ -60,81 +60,28 @@ USER_DATA_DIR = os.path.join(USER_BASE_DIR, 'data')
USER_LOG_DIR = os.path.join(USER_BASE_DIR, 'job-results')
def _usable_rw_dir(directory):
"""
Verify wether we can use this dir (read/write).
Checks for appropriate permissions, and creates missing dirs as needed.
:param directory: Directory
"""
if os.path.isdir(directory):
try:
fd, path = tempfile.mkstemp(dir=directory)
os.close(fd)
os.unlink(path)
return True
except OSError:
pass
else:
try:
utils_path.init_dir(directory)
return True
except OSError:
pass
return False
def _usable_ro_dir(directory):
"""
Verify whether dir exists and we can access its contents.
If a usable RO is there, use it no questions asked. If not, let's at
least try to create one.
:param directory: Directory
"""
cwd = os.getcwd()
if os.path.isdir(directory):
try:
os.chdir(directory)
os.chdir(cwd)
return True
except OSError:
pass
else:
try:
utils_path.init_dir(directory)
return True
except OSError:
pass
return False
def _get_rw_dir(settings_location, system_location, user_location):
if _usable_rw_dir(settings_location):
if utils_path.usable_rw_dir(settings_location):
return settings_location
if _usable_rw_dir(system_location):
if utils_path.usable_rw_dir(system_location):
return system_location
user_location = os.path.expanduser(user_location)
if _usable_rw_dir(user_location):
if utils_path.usable_rw_dir(user_location):
return user_location
def _get_ro_dir(settings_location, system_location, user_location):
if not settings.intree:
if _usable_ro_dir(settings_location):
if utils_path.usable_ro_dir(settings_location):
return settings_location
if _usable_ro_dir(system_location):
if utils_path.usable_ro_dir(system_location):
return system_location
user_location = os.path.expanduser(user_location)
if _usable_ro_dir(user_location):
if utils_path.usable_ro_dir(user_location):
return user_location
......
......@@ -18,6 +18,7 @@ Avocado path related functions.
import os
import stat
import tempfile
from . import aurl
......@@ -140,3 +141,56 @@ class PathInspector(object):
return True
return self.is_script(language='python')
def usable_rw_dir(directory):
"""
Verify wether we can use this dir (read/write).
Checks for appropriate permissions, and creates missing dirs as needed.
:param directory: Directory
"""
if os.path.isdir(directory):
try:
fd, path = tempfile.mkstemp(dir=directory)
os.close(fd)
os.unlink(path)
return True
except OSError:
pass
else:
try:
init_dir(directory)
return True
except OSError:
pass
return False
def usable_ro_dir(directory):
"""
Verify whether dir exists and we can access its contents.
If a usable RO is there, use it no questions asked. If not, let's at
least try to create one.
:param directory: Directory
"""
cwd = os.getcwd()
if os.path.isdir(directory):
try:
os.chdir(directory)
os.chdir(cwd)
return True
except OSError:
pass
else:
try:
init_dir(directory)
return True
except OSError:
pass
return False
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册