OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # This program operates much like dd, but with two important differences: | 3 # This program operates much like dd, but with two important differences: |
4 # 1. Many features lacking | 4 # 1. Many features lacking |
5 # 2. seek_bytes= param can specify seek offset in bytes, not block size | 5 # 2. seek_bytes= param can specify seek offset in bytes, not block size |
6 | 6 |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 import time | 9 import time |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 t1 = time.time() | 79 t1 = time.time() |
80 | 80 |
81 buf = os.read(if_fd, arg_bs) | 81 buf = os.read(if_fd, arg_bs) |
82 while len(buf) > 0: | 82 while len(buf) > 0: |
83 bytes_written = 0 | 83 bytes_written = 0 |
84 while bytes_written < len(buf): | 84 while bytes_written < len(buf): |
85 bytes_written += os.write(of_fd, buf[bytes_written:]) | 85 bytes_written += os.write(of_fd, buf[bytes_written:]) |
86 bytes_copied += bytes_written | 86 bytes_copied += bytes_written |
87 buf = os.read(if_fd, arg_bs) | 87 buf = os.read(if_fd, arg_bs) |
88 | 88 |
89 t2 = time.time() | |
90 | |
91 os.close(if_fd) | 89 os.close(if_fd) |
92 os.close(of_fd) | 90 os.close(of_fd) |
| 91 |
| 92 t2 = time.time() |
93 | 93 |
94 # print timing info | 94 # print timing info |
95 print >> sys.stderr, 'copy %d bytes took %0.3f s' % (bytes_copied, t2 - t1) | 95 print >> sys.stderr, 'copy %d bytes took %0.3f s' % (bytes_copied, t2 - t1) |
96 print >> sys.stderr, 'speed: %0.1f MB/s' % \ | 96 print >> sys.stderr, 'speed: %0.1f MB/s' % \ |
97 ((bytes_copied / 1000000) / (t2 - t1)) | 97 ((bytes_copied / 1000000) / (t2 - t1)) |
98 | 98 |
99 if __name__ == '__main__': | 99 if __name__ == '__main__': |
100 main(sys.argv) | 100 main(sys.argv) |
OLD | NEW |