github.com/attic-labs/noms@v0.0.0-20210827224422-e5fa29d95e8b/tools/noms/copy.py (about) 1 #!/usr/bin/python 2 3 # Copyright 2016 Attic Labs, Inc. All rights reserved. 4 # Licensed under the Apache License, version 2.0: 5 # http://www.apache.org/licenses/LICENSE-2.0 6 7 import os.path, shutil 8 9 def Peers(me, dstDir): 10 """Peers copies the peers of me into dstDir. 11 12 Peers looks for files, directories and symlinks next to me 13 and copies them (with the same basenames) to dstDir, which is 14 presumed to exist. 15 """ 16 myDir = os.path.dirname(os.path.abspath(me)) 17 names = os.listdir(myDir) 18 for basename in names: 19 src = os.path.join(myDir, basename) 20 dst = os.path.join(dstDir, basename) 21 if os.path.samefile(me, src): 22 continue 23 24 if os.path.islink(src): 25 linkto = os.readlink(src) 26 os.symlink(linkto, dst) 27 elif os.path.isfile(src): 28 shutil.copy2(src, dst) 29 elif os.path.isdir(src): 30 shutil.copytree(src, dst) 31 else: 32 raise Exception("Unknown file type at " + src)