comparison fetch.py @ 46:fb05b7616bd8

begin stubbing own copytree function :(
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 15 Nov 2011 14:53:08 -0800
parents 87c22bbcda2b
children 72d461e2ccbd
comparison
equal deleted inserted replaced
45:87c22bbcda2b 46:fb05b7616bd8
16 """python equivalent of which; should really be in the stdlib""" 16 """python equivalent of which; should really be in the stdlib"""
17 dirs = path.split(os.pathsep) 17 dirs = path.split(os.pathsep)
18 for dir in dirs: 18 for dir in dirs:
19 if os.path.isfile(os.path.join(dir, executable)): 19 if os.path.isfile(os.path.join(dir, executable)):
20 return os.path.join(dir, executable) 20 return os.path.join(dir, executable)
21
22 def copytree(src, dst):
23 """
24 replacement for shutil.copytree because of this nonsense from help(shutil.copytree):
25 "The destination directory must not already exist."
26 """
27
28 # if its a file, just copy it
29 if os.path.isfile(src):
30 shutil.copy2(src, dst)
31 return
32
33 # otherwise a directory
34 assert os.path.isdir(src)
35 if os.path.exists(dst):
36 assert os.path.isdir(dst), "%s is a file, %s is a directory" % (src, dst)
37 else:
38 os.makedirs(dst)
39
40 for dirpath, dirnames, filenames in os.walk(src):
41 import pdb; pdb.set_trace()
21 42
22 class Fetcher(object): 43 class Fetcher(object):
23 """abstract base class for resource fetchers""" 44 """abstract base class for resource fetchers"""
24 45
25 @classmethod 46 @classmethod
160 if os.path.isdir(path): 181 if os.path.isdir(path):
161 if os.path.exists(dest): 182 if os.path.exists(dest):
162 assert os.path.isdir(dest), "source is a directory; destination is a file" 183 assert os.path.isdir(dest), "source is a directory; destination is a file"
163 else: 184 else:
164 os.makedirs(dest) 185 os.makedirs(dest)
165 shutil.copytree(path, dest) 186 copytree(path, dest)
166 else: 187 else:
167 if not os.path.exists(dest): 188 if not os.path.exists(dest):
168 directory, filename = os.path.split(dest) 189 directory, filename = os.path.split(dest)
169 if os.path.exists(directory): 190 if os.path.exists(directory):
170 assert os.path.isdir(directory), "%s is not a directory" % directory 191 assert os.path.isdir(directory), "%s is not a directory" % directory