summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-02 15:28:28 -0500
committerYaakov M. Nemoy <loupgaroublond@gmail.com>2009-01-02 15:28:28 -0500
commit91f29794cdaa848de34b58321b8b47a52bfa1695 (patch)
tree6d1c92e460c1501ab0856d4678352e0a1a10e83a
parent85bdbeaa11dfbd92ba888e933e93e15d2145f5d6 (diff)
downloadfedora-devshell-91f29794cdaa848de34b58321b8b47a52bfa1695.tar.gz
fedora-devshell-91f29794cdaa848de34b58321b8b47a52bfa1695.tar.xz
fedora-devshell-91f29794cdaa848de34b58321b8b47a52bfa1695.zip
Makes the copy function more universal
-rw-r--r--base/util.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/base/util.py b/base/util.py
index e133149..b9d6eac 100644
--- a/base/util.py
+++ b/base/util.py
@@ -21,9 +21,10 @@ from __future__ import with_statement
from contextlib import contextmanager
from os import chdir, getcwd, remove
from os import symlink as sym
-from os.path import abspath, lexists, isdir, islink
+from os.path import abspath, lexists, isdir, islink, isfile
from shutil import copyfileobj, rmtree
from shutil import move as mv
+from urllib import urlopen
from base import log
@@ -43,12 +44,17 @@ def rm(tgt):
remove(tgt)
def copy(src, dst):
- # we're using copyfileobj so later we can do this from a URL
- src = file(src, 'rb')
- dst = file(dst, 'wb')
- copyfileobj(src, dst)
- src.close()
- dst.close()
+ # we're using copyfileobj so we can do this from a URL
+ if isfile(src):
+ src_f = file(src, 'rb')
+ else:
+ src_f = urlopen(src)
+ dst_f = file(dst, 'wb')
+ copyfileobj(src_f, dst_f)
+ src_f.close()
+ dst_f.close()
+ # return the dst path as a matter of utility
+ return dst
def symlink(src, dst):
if lexists(dst):