8
def main(source, target):
9
# TODO: debate pulling the total_size bit in from ubiquity for more
11
# TODO: Fedora's program shells out to cp and uses another thread that
12
# checks the free space on the drive and updates the UI accordingly.
13
# Is this worth replicating?
15
# Some of the code in this function was copied from Ubiquity's
18
if not os.path.exists(source) or not os.path.exists(target):
22
for dirpath, dirnames, filenames in os.walk(source):
23
for name in dirnames + filenames:
26
for dirpath, dirnames, filenames in os.walk(source):
27
sp = dirpath[len(source) + 1:]
28
for name in dirnames + filenames:
29
relpath = os.path.join(sp, name)
30
sourcepath = os.path.join(source, relpath)
31
targetpath = os.path.join(target, relpath)
32
st = os.lstat(sourcepath)
33
mode = stat.S_IMODE(st.st_mode)
34
if stat.S_ISLNK(st.st_mode):
35
if os.path.lexists(targetpath):
37
linkto = os.readlink(sourcepath)
38
#os.symlink(linkto, targetpath)
39
# FIXME: Handle this somehow?
40
#print 'trying to symlink %s' % linkto
42
elif stat.S_ISDIR(st.st_mode):
43
if not os.path.isdir(targetpath):
44
os.mkdir(targetpath, mode)
45
elif stat.S_ISCHR(st.st_mode):
46
os.mknod(targetpath, stat.S_IFCHR | mode, st.st_rdev)
47
elif stat.S_ISBLK(st.st_mode):
48
os.mknod(targetpath, stat.S_IFBLK | mode, st.st_rdev)
49
elif stat.S_ISFIFO(st.st_mode):
50
os.mknod(targetpath, stat.S_IFIFO | mode)
51
elif stat.S_ISSOCK(st.st_mode):
52
os.mknod(targetpath, stat.S_IFSOCK | mode)
53
elif stat.S_ISREG(st.st_mode):
54
if os.path.exists(targetpath):
57
sourcefh = open(sourcepath, 'rb')
58
targetfh = open(targetpath, 'wb')
59
# TODO: md5 check. Copy error handling.
60
shutil.copyfileobj(sourcefh, targetfh)
64
#print '%s -> %s' % (sourcepath, targetpath)
65
percent = percent + inc
66
# TODO: self.frontend.progress(percent)
68
#self.frontend.progress(percent)
70
if __name__ == '__main__':
74
opts, args = getopt.getopt(sys.argv[1:], 's:t:')
75
except getopt.GetoptError:
82
#print '%s %s' % (source, target)