本文整理汇总了Python中shutil.copytree函数的典型用法代码示例。如果您正苦于以下问题:Python copytree函数的具体用法?Python copytree怎么用?Python copytree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copytree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _InstrumentExecutables
def _InstrumentExecutables(self):
build_dir = self._build_dir
work_dir = self._work_dir
_LOGGER.info('Build dir "%s".', build_dir)
# Make a copy of all unittest executables, DLLs, PDBs and test_data in
# the build directory.
for pattern in ('*_unittests.exe', '*.dll', '*.pdb', 'test_data'):
files = glob.glob(os.path.join(build_dir, pattern))
for path in files:
_LOGGER.info('Copying "%s" to "%s".', path, work_dir)
if os.path.isdir(path):
# If the source file is a directory, do a recursive copy.
dst = os.path.join(work_dir, os.path.basename(path))
shutil.copytree(path, dst)
else:
shutil.copy(path, work_dir)
# Instrument all EXEs in the work dir.
for exe in glob.glob(os.path.join(work_dir, '*.exe')):
self._InstrumentOneFile(exe)
# And the DLLs we've specified.
for dll in _DLLS_TO_INSTRUMENT:
self._InstrumentOneFile(os.path.join(work_dir, dll))
示例2: install
def install(self, spec, prefix):
# cppcheck does not have a configure script
make("CFGDIR=%s" % os.path.join(prefix, 'cfg'))
# manually install the final cppcheck binary
mkdirp(prefix.bin)
install('cppcheck', prefix.bin)
shutil.copytree('cfg', os.path.join(prefix, 'cfg'))
示例3: cleanupFiles
def cleanupFiles():
# First get rid of modified files
for l in ["l1", "l2", "l3"]:
arcpy.Delete_management(l)
for f in glob.glob("C:\\Arctmp\\*"):
try:
shutil.rmtree(f)
except:
print "UNABLE TO REMOVE:", f
# Now remove the old directory
for i in xrange(0, 1000000):
new_workspace = "C:\\Arctmp\\workspace." + str(i)
if not os.path.exists(new_workspace):
break
print "TESTING USING WORKSPACE", new_workspace
# Now move in fresh copies
shutil.copytree("C:\\Arcbase", new_workspace)
print "CONTENTS:"
arcpy.env.workspace = new_workspace
for f in sorted(glob.glob(arcpy.env.workspace + "\\*.shp")):
print f
for f in sorted(glob.glob(arcpy.env.workspace + "\\*.lyr")):
print f
for f in sorted(glob.glob(arcpy.env.workspace + "\\*.gdb")):
print f
示例4: share_static
def share_static(main):
"""Makes the sphinx _static folder shared.
Can be run multiple times to dedup newly added modules.
"""
rewrite_static_links(main)
roots = []
for entry in os.listdir(main):
if entry.startswith(("_", ".")) or "-" not in entry:
continue
path = os.path.join(main, entry)
if not os.path.isdir(path):
continue
roots.append(path)
shared = os.path.join(main, "_static")
if not os.path.exists(shared):
# copy one to the root
shutil.rmtree(shared, ignore_errors=True)
shutil.copytree(os.path.join(roots[0], "_static"), shared)
# remove all others
for root in roots:
static = os.path.join(root, "_static")
shutil.rmtree(static, ignore_errors=True)
示例5: copy_template
def copy_template():
config_prompt(template)
shutil.copytree(template, name)
if os.path.exists('%s/%s' % (name, 'config.yaml')):
os.remove('%s/%s' % (name, 'config.yaml'))
for dirname, dirnames, files in os.walk(name):
for d in dirnames:
if d == options.template:
shutil.copytree('%s/%s' % (dirname, d), '%s/%s' % (dirname, name))
shutil.rmtree('%s/%s' % (dirname, d))
for dirname, dirnames, files in os.walk(name):
for filename in files:
f = open('%s/%s' % (dirname, filename), 'r')
lines = f.readlines()
f.close()
first_pass = [re.sub('{{\s*(\w+)\s*}}', replace_variable, line) for line in lines]
new_lines = [re.sub('__config_(\w+)__', replace_variable, line) for line in first_pass]
f = open('%s/%s' % (dirname, filename), 'w')
f.write(''.join(new_lines))
f.close()
示例6: run
def run(self):
dst = self.config.get_dst_folder()
cdv_dst = self.config.get_cordova_dst_folder(self.key)
if os.path.exists(cdv_dst):
names = os.listdir(cdv_dst)
for name in names:
if not name.startswith('.'):
name = os.path.join(cdv_dst, name)
if os.path.isfile(name):
os.remove(name)
else:
shutil.rmtree(name)
names = os.listdir(dst)
for name in names:
if not name.startswith('.'):
src = os.path.join(dst, name)
copy = os.path.join(cdv_dst, name)
if os.path.isfile(src):
shutil.copy(src, copy)
else:
shutil.copytree(src, copy, ignore=shutil.ignore_patterns('.*'))
for r, d, f in os.walk(cdv_dst):
for files in filter(lambda x: x.endswith('.html'), f):
p = os.path.join(r, files)
self.replace_cordova_tag(p)
self.copy_icons(dst)
self.copy_splash(dst)
示例7: mvtree
def mvtree(simstr,comp_end=None):
"""
Moves an entire run tree without changing file names.
"""
# Set constants
usrcomp=mmlinfo.hostname2compid()
complist=mmlinfo.complist()
usrindx=complist['compid'].index(usrcomp)
# Get location of sim
comp_beg=simstr['memcomp']
# Get computer memory info
if comp_beg not in complist['memlist'][usrindx]:
raise Exception('Cannot access computer {} from the current one {}. Switch to bender.'.format(comp_beg,usrcomp))
print 'Current tree location: {}'.format(comp_beg)
if comp_end not in complist['memlist'][usrindx]:
comp_end=mmlio.askselect('What computer should the tree be moved to?',complist['memlist'][usrindx])
# Get filenames
files_beg=simstr.mkfiledict(memcomp=comp_beg,checkaccess=True)
files_end=simstr.mkfiledict(memcomp=comp_end,checkaccess=True)
# Copy the tree
print 'Source run tree: '+files_beg['rundir']
print 'Destination run tree: '+files_end['rundir']
if mmlio.yorn('Continue moving tree?'):
mmlfiles.mkdirs(files_end['simdir'])
shutil.copytree(files_beg['rundir'],files_end['rundir'])
else:
return
# Remove the old tree
if mmlio.yorn('Remove old run tree?'):
shutil.rmtree(files_beg['rundir'])
# Update the run files
if mmlio.yorn('Update the run files?'):
simstr['memcomp']=comp_end
mmlparam.savepar('mmlyt.simlist','galsim',dict(simstr),overwrite=True)
return
示例8: _run_install
def _run_install(self):
"""
The definition of the "run" method for the CustomInstallCommand metaclass.
"""
# Get paths
tethysapp_dir = get_tethysapp_directory()
destination_dir = os.path.join(tethysapp_dir, self.app_package)
# Notify user
print('Copying App Package: {0} to {1}'.format(self.app_package_dir, destination_dir))
# Copy files
try:
shutil.copytree(self.app_package_dir, destination_dir)
except:
try:
shutil.rmtree(destination_dir)
except:
os.remove(destination_dir)
shutil.copytree(self.app_package_dir, destination_dir)
# Install dependencies
for dependency in self.dependencies:
subprocess.call(['pip', 'install', dependency])
# Run the original install command
install.run(self)
示例9: copytree
def copytree(src, dest, dry_run=None, echo=True):
dry_run = _coerce_dry_run(dry_run)
if dry_run or echo:
_echo_command(dry_run, ['cp', '-r', src, dest])
if dry_run:
return
shutil.copytree(src, dest)
示例10: convert
def convert(input_file_path, output_file_path):
temp_dir = tempfile.mkdtemp()
shutil.copytree(template_dir, temp_dir+'/template')
shutil.copy(input_file_path, temp_dir+'/template/customXml/item1.xml')
output_file = zipfile.ZipFile(output_file_path, mode='w', compression=zipfile.ZIP_DEFLATED)
pwd = os.path.abspath('.')
os.chdir(temp_dir+'/template')
files_to_ignore = ['.DS_Store']
for dir_path, dir_names, file_names in os.walk('.'):
for file_name in file_names:
if file_name in files_to_ignore:
continue
template_file_path = os.path.join(dir_path, file_name)
output_file.write(template_file_path, template_file_path[2:])
output_file.close()
os.chdir(pwd)
示例11: install
def install(host, src, dstdir):
if isLocal(host):
if not exists(host, src):
util.output("file does not exist: %s" % src)
return False
dst = os.path.join(dstdir, os.path.basename(src))
if exists(host, dst):
# Do not clobber existing files/dirs (this is not an error)
return True
util.debug(1, "cp %s %s" % (src, dstdir))
try:
if os.path.isfile(src):
shutil.copy2(src, dstdir)
elif os.path.isdir(src):
shutil.copytree(src, dst)
except OSError:
# Python 2.6 has a bug where this may fail on NFS. So we just
# ignore errors.
pass
else:
util.error("install() not yet supported for remote hosts")
return True
示例12: testPluginPath
def testPluginPath(self):
for t in ['test_plugins', 'test plugins', 'test_pluginsé€']:
# get a unicode test dir
if sys.version_info.major == 2:
t = t.encode(locale.getpreferredencoding())
testDir = os.path.join(self.TMP_DIR, t)
# copy from testdata
if not os.path.exists(testDir):
os.mkdir(testDir)
test_plug_dir = os.path.join(TEST_DATA_DIR, 'test_plugin_path')
for item in os.listdir(test_plug_dir):
shutil.copytree(os.path.join(test_plug_dir, item),
os.path.join(testDir, item))
# we use here a minimal plugin that writes to 'plugin_started.txt'
# when it is started. if QGIS_PLUGINPATH is correctly parsed, this
# plugin is executed and the file is created
self.doTestStartup(
option="--optionspath",
testDir=testDir,
testFile="plugin_started.txt",
timeOut=360,
loadPlugins=True,
env={'QGIS_PLUGINPATH': testDir})
示例13: copy_packages
def copy_packages(packages_names, dest, create_links=False, extra_ignores=None):
"""Copy python packages ``packages_names`` to ``dest``, spurious data.
Copy will happen without tests, testdata, mercurial data or C extension module source with it.
``py2app`` include and exclude rules are **quite** funky, and doing this is the only reliable
way to make sure we don't end up with useless stuff in our app.
"""
if ISWINDOWS:
create_links = False
if not extra_ignores:
extra_ignores = []
ignore = shutil.ignore_patterns('.hg*', 'tests', 'testdata', 'modules', 'docs', 'locale', *extra_ignores)
for package_name in packages_names:
if op.exists(package_name):
source_path = package_name
else:
mod = __import__(package_name)
source_path = mod.__file__
if mod.__file__.endswith('__init__.py'):
source_path = op.dirname(source_path)
dest_name = op.basename(source_path)
dest_path = op.join(dest, dest_name)
if op.exists(dest_path):
if op.islink(dest_path):
os.unlink(dest_path)
else:
shutil.rmtree(dest_path)
print("Copying package at {0} to {1}".format(source_path, dest_path))
if create_links:
os.symlink(op.abspath(source_path), dest_path)
else:
if op.isdir(source_path):
shutil.copytree(source_path, dest_path, ignore=ignore)
else:
shutil.copy(source_path, dest_path)
示例14: exportIndex
def exportIndex(self, name, dir="."):
if self.indexes.has_section(name):
print "Exporting index properties for %s" % name
global tempdir
global tarName
global extension
tempdir = tempfile.mkdtemp()
exportConfig = ConfigParser.ConfigParser()
exportConfig.add_section(name)
for opt in self.indexes.options(name):
exportConfig.set(name, opt, self.getIndexProp(name, opt))
exportConfig.set(name, INDEX_DIR, "indexes")
exportConfig.set(name, CONTENT_DIR, "contents")
exportConfig.write(open(os.path.join(tempdir, "indexes.cfg"), "w"))
print "Copying index files (this may take a while)..."
import shutil
shutil.copytree(self.getIndexProp(name, INDEX_DIR), os.path.join(tempdir, INDEX_DIR))
print "Copying content files (this may take a while)..."
shutil.copytree(self.getIndexProp(name, INDEX_DIR), os.path.join(tempdir, CONTENT_DIR))
tarName = utils.createSafeFilename(name)
archive = tarfile.open(os.path.join(dir, tarName + extension), "w:bz2")
os.path.walk(tempdir, walker, archive)
archive.close()
shutil.rmtree(tempdir)
示例15: copyDir
def copyDir():
for file in os.listdir("."):
if file in file_list:
shutil.copy(file, dest)
elif file in dir_list:
destDir = dest + "/" + file
shutil.copytree(file, destDir)