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