Files
dolt/tools/noms/copy.py
Erik Arvidsson 893d0fa360 stage.py needs to import sys before using it (#2513)
Also changes the tabs to spaces. Thanks pylint.
2016-09-02 13:38:43 -07:00

33 lines
1001 B
Python

#!/usr/bin/python
# Copyright 2016 Attic Labs, Inc. All rights reserved.
# Licensed under the Apache License, version 2.0:
# http://www.apache.org/licenses/LICENSE-2.0
import os.path, shutil
def Peers(me, dstDir):
"""Peers copies the peers of me into dstDir.
Peers looks for files, directories and symlinks next to me
and copies them (with the same basenames) to dstDir, which is
presumed to exist.
"""
myDir = os.path.dirname(os.path.abspath(me))
names = os.listdir(myDir)
for basename in names:
src = os.path.join(myDir, basename)
dst = os.path.join(dstDir, basename)
if os.path.samefile(me, src):
continue
if os.path.islink(src):
linkto = os.readlink(src)
os.symlink(linkto, dst)
elif os.path.isfile(src):
shutil.copy2(src, dst)
elif os.path.isdir(src):
shutil.copytree(src, dst)
else:
raise Exception("Unknown file type at " + src)