summaryrefslogtreecommitdiffstats
path: root/base/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'base/util.py')
-rw-r--r--base/util.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/base/util.py b/base/util.py
index 87da8af..b53a918 100644
--- a/base/util.py
+++ b/base/util.py
@@ -1,9 +1,9 @@
from __future__ import with_statement
from contextlib import contextmanager
-from os import chdir, getcwd
+from os import chdir, getcwd, remove
from os import symlink as sym
-from os.path import abspath, lexists
+from os.path import abspath, lexists, isdir, islink
from shutil import copyfileobj, rmtree
from shutil import move as mv
@@ -18,6 +18,12 @@ def pwd(dir):
log.debug('changing dir to %s' % old_dir)
chdir(old_dir)
+def rm(tgt):
+ if isdir(tgt):
+ rmtree(tgt)
+ else:
+ remove(tgt)
+
def copy(src, dst):
# we're using copyfileobj so later we can do this from a URL
src = file(src, 'rb')
@@ -28,12 +34,17 @@ def copy(src, dst):
def symlink(src, dst):
if lexists(dst):
- remove(dst)
+ rm(dst)
sym(abspath(src), abspath(dst))
def move(src, dst):
if lexists(dst):
- rmtree(dst)
+ rm(dst)
mv(src, dst)
+
+def one(l, f):
+ for x in l:
+ if f(x):
+ return x
-__all__ = ['pwd', 'copy'] \ No newline at end of file
+__all__ = ['pwd', 'copy', 'with_sudo', 'with_su', 'symlink', 'move']