diff options
author | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2008-12-29 23:10:02 -0500 |
---|---|---|
committer | Yaakov M. Nemoy <loupgaroublond@gmail.com> | 2008-12-29 23:10:02 -0500 |
commit | 273ddf63d4f57ec9b4d5aedfcfefdf17c8ec1122 (patch) | |
tree | e87bd97a695614adab97e40a745bbfcbd1e45c9d /base | |
parent | c4a7700faa98d75207be6096b70b9d7198f0c00b (diff) | |
download | fedora-devshell-273ddf63d4f57ec9b4d5aedfcfefdf17c8ec1122.tar.gz fedora-devshell-273ddf63d4f57ec9b4d5aedfcfefdf17c8ec1122.tar.xz fedora-devshell-273ddf63d4f57ec9b4d5aedfcfefdf17c8ec1122.zip |
Updated util functions
Diffstat (limited to 'base')
-rw-r--r-- | base/util.py | 21 |
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'] |