copytime.py revision f06ee5fa072931fc807527535c91a46c149a6746
1088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne#! /usr/bin/env python
2088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne
3088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne# Copy one file's atime and mtime to another
4088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne
5088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourneimport sys
6088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourneimport os
7088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbournefrom stat import ST_ATIME, ST_MTIME # Really constants 7 and 8
8088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne
9088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbournedef main():
10088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne	if len(sys.argv) <> 3:
11088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne		sys.stderr.write('usage: copytime source destination\n')
12088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne		sys.exit(2)
13088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne	file1, file2 = sys.argv[1], sys.argv[2]
14088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne	try:
15088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne		stat1 = os.stat(file1)
16799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar	except os.error:
172d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines		sys.stderr.write(file1 + ': cannot stat\n')
18088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne		sys.exit(1)
19799172d60d32feb1acba1a6867f3a9c39a999e5cPirama Arumuga Nainar	try:
20259f7063e3e4c4b94dded1e90ab0a943d0fa737bPirama Arumuga Nainar		os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
21088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne	except os.error:
2206cbed8b8ae64b7ace50c1b4e4eed97a2a8b9965Dmitry Vyukov		sys.stderr.write(file2 + ': cannot change time\n')
236d1862363c88c183b0ed7740fca876342cf0474bStephen Hines		sys.exit(2)
247847d77b246635211c3bf465421d49d7af5226c1Alexey Samsonov
257847d77b246635211c3bf465421d49d7af5226c1Alexey Samsonovmain()
26088ea2b46f97172bd0b0663a629e11cf826b84f7Peter Collingbourne