-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathutils.py
28 lines (22 loc) · 878 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from fabric.api import sudo
from fabric.contrib.files import exists
def _read_boolean(env, name, default):
## TODO: Replace calls to this with calls to cloudbio.custom.shared version
property_str = env.get(name, str(default))
return property_str.upper() in ["TRUE", "YES"]
def _chown_galaxy(env, path):
"""
Recursively change ownership of ``path``, first checking if ``path`` exists.
"""
chown_command = "chown --recursive %s:%s %s"
galaxy_user = env.get("galaxy_user", "galaxy")
if env.safe_exists(path):
env.safe_sudo(chown_command % (galaxy_user, galaxy_user, path))
def _dir_is_empty(path):
"""
Return ``True`` is ``path`` directory has no files or folders in it.
Return ``False`` otherwise.
"""
if "empty" in sudo('[ "$(ls -A {0})" ] || echo "empty"'.format(path)):
return True
return False