3 """Symlinks, or on Windows copies, an existing file to a second location.
5 Overwrites the target location if it exists.
6 Updates the mtime on a stamp file when done."""
15 parser
= argparse
.ArgumentParser(description
=__doc__
)
16 parser
.add_argument('--stamp', required
=True,
17 help='name of a file whose mtime is updated on run')
18 parser
.add_argument('source')
19 parser
.add_argument('output')
20 args
= parser
.parse_args()
22 # FIXME: This should not check the host platform but the target platform
23 # (which needs to be passed in as an arg), for cross builds.
24 if sys
.platform
!= 'win32':
26 os
.makedirs(os
.path
.dirname(args
.output
))
28 if e
.errno
!= errno
.EEXIST
:
31 os
.symlink(args
.source
, args
.output
)
33 if e
.errno
== errno
.EEXIST
:
34 os
.remove(args
.output
)
35 os
.symlink(args
.source
, args
.output
)
40 output
= args
.output
+ ".exe"
41 source
= args
.source
+ ".exe"
42 shutil
.copyfile(os
.path
.join(os
.path
.dirname(output
), source
), output
)
44 open(args
.stamp
, 'w') # Update mtime on stamp file.
47 if __name__
== '__main__':