1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import sys, os
21
23 """Internal method to read bytes from a source file descriptor, and write to a destination file descriptor.
24
25 @param fsrc: The source file descriptor
26 @param fdst: The destination file descriptor
27 @param length: The buffer length to read from the src and write to the destination
28
29 """
30 while 1:
31 buf = fsrc.read(length)
32 if not buf:
33 break
34 fdst.write(buf)
35
36
38 """Copy source file to a destination file.
39
40 @param src: Full path to the source filename
41 @param dst: Full path the destination filename
42 @raises FileNotFoundException: Raised if the source file does not exist
43
44 """
45 if not os.path.exists(src):
46 raise FileNotFoundException, "unable to find file %s" % (os.path.basename(src))
47
48 fsrc = None
49 fdst = None
50 try:
51 fsrc = open(src, 'rb')
52 fdst = open(dst, 'wb')
53 copyfileobj(fsrc, fdst)
54 finally:
55 if fdst:
56 fdst.close()
57 if fsrc:
58 fsrc.close()
59
60
61
62 if __name__ == "__main__":
63 if len(sys.argv) < 2:
64 print "Usage: fileunzip <src> <dst>"
65 sys.exit()
66 else:
67 filecopy(sys.argv[1], sys.argv[2])
68