• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python shutil.copytree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shutil.copytree函数的典型用法代码示例。如果您正苦于以下问题:Python copytree函数的具体用法?Python copytree怎么用?Python copytree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了copytree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:chromium-googlesource-mirror,项目名称:sawbuck,代码行数:25,代码来源:generate_coverage.py


示例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'))
开发者ID:justintoo,项目名称:spack,代码行数:7,代码来源:package.py


示例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
开发者ID:pramttl,项目名称:tstl,代码行数:26,代码来源:standalone3.py


示例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)
开发者ID:lazka,项目名称:pgi-docgen,代码行数:28,代码来源:build.py


示例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()
开发者ID:rlayte,项目名称:kickstart,代码行数:25,代码来源:kickstart.py


示例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)
开发者ID:abdelhai,项目名称:lavaca,代码行数:27,代码来源:build.py


示例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
开发者ID:cfh5058,项目名称:mmlpy,代码行数:35,代码来源:simfile.py


示例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)
开发者ID:astraiophos,项目名称:tethys,代码行数:29,代码来源:app_installation.py


示例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)
开发者ID:DevAndArtist,项目名称:swift,代码行数:7,代码来源:shell.py


示例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)
开发者ID:cstatz,项目名称:word2007bib2docxbib,代码行数:25,代码来源:tools.py


示例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
开发者ID:cubic1271,项目名称:broctl,代码行数:27,代码来源:execute.py


示例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})
开发者ID:medspx,项目名称:QGIS,代码行数:26,代码来源:test_qgsappstartup.py


示例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)
开发者ID:BrokenSilence,项目名称:dupeguru,代码行数:35,代码来源:build.py


示例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)
开发者ID:kollivier,项目名称:brightwriter,代码行数:32,代码来源:index_manager.py


示例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)
开发者ID:bigcomputing,项目名称:matlab-big,代码行数:7,代码来源:matlab_package.py


示例16: setup

 def setup(self):
     self.temp_dir = tempfile.mkdtemp(prefix='setup.cfg-test-')
     self.package_dir = os.path.join(self.temp_dir, 'testpackage')
     shutil.copytree(os.path.join(os.path.dirname(__file__), 'testpackage'),
                     self.package_dir)
     self.oldcwd = os.getcwd()
     os.chdir(self.package_dir)
开发者ID:embray,项目名称:setup.cfg,代码行数:7,代码来源:__init__.py


示例17: clone_from

 def clone_from(self, source_url):
     '''Initialize a repo as a clone of another'''
     self._repo.set_status('cloning')
     log.info('Initialize %r as a clone of %s',
              self._repo, source_url)
     try:
         fullname = self._setup_paths(create_repo_dir=False)
         if os.path.exists(fullname):
             shutil.rmtree(fullname)
         if self.can_hotcopy(source_url):
             shutil.copytree(source_url, fullname)
             post_receive = os.path.join(
                 self._repo.full_fs_path, 'hooks', 'post-receive')
             if os.path.exists(post_receive):
                 os.rename(post_receive, post_receive + '-user')
             repo = git.Repo(fullname)
         else:
             repo = git.Repo.clone_from(
                 source_url,
                 to_path=fullname,
                 bare=True)
         self.__dict__['_git'] = repo
         self._setup_special_files(source_url)
     except:
         self._repo.set_status('ready')
         raise
开发者ID:joequant,项目名称:allura,代码行数:26,代码来源:git_repo.py


示例18: get_pulsar_binary

def get_pulsar_binary():
    binary = "pulsar" + (PLATFORM["os"] == "windows" and ".exe" or "")

    platform = PLATFORM.copy()
    if platform["os"] == "darwin": # 64 bits anyway on Darwin
        platform["arch"] = "x64"
    elif platform["os"] == "windows": # 32 bits anyway on Windows
        platform["arch"] = "x86"

    binary_dir = os.path.join(ADDON.getAddonInfo("path"), "resources", "bin", "%(os)s_%(arch)s" % platform)
    if platform["os"] == "android":
        app_id = android_get_current_appid()
        xbmc_data_path = os.path.join("/data", "data", app_id)
        if os.path.exists(xbmc_data_path) and uid == os.stat(xbmc_data_path).st_uid:
            binary_dir = os.path.join(xbmc_data_path, "files", ADDON_ID)
    else:
        dest_binary_dir = os.path.join(xbmc.translatePath(ADDON.getAddonInfo("profile")), "bin", "%(os)s_%(arch)s" % platform)

    binary_path = os.path.join(binary_dir, binary)
    dest_binary_path = os.path.join(dest_binary_dir, binary)

    # Testing for size to see if update is needed. This is a poor test indeed, but it's sufficient.
    if not os.path.exists(dest_binary_path) or os.path.getsize(dest_binary_path) != os.path.getsize(binary_path):
        log.info("pulsar daemon is outdated, updating...")
        import shutil
        try:
            os.makedirs(dest_binary_dir)
        except OSError:
            pass
        shutil.rmtree(dest_binary_dir)
        shutil.copytree(binary_dir, dest_binary_dir)

    return dest_binary_dir, ensure_exec_perms(dest_binary_path)
开发者ID:hungrybeetle,项目名称:plugin.video.pulsar,代码行数:33,代码来源:daemon.py


示例19: run_check

 def run_check(*args):
     # create a fresh tree for the profile work everytime.
     # do this, so that it's always a unique pathway- this sidesteps
     # any potential issues of ProfileNode instance caching.
     path = pjoin(self.dir, 'foo', str(counter.next()))
     shutil.copytree(pjoin(self.dir, 'foo'), path, symlinks=True)
     return self.process_check(path, list(args))
开发者ID:den4ix,项目名称:pkgcheck,代码行数:7,代码来源:test_addons.py


示例20: walk

def walk(src, dest):
    print '****************************************************************'
    print dest
    print '****************************************************************'
    dirCmp = filecmp.dircmp(src, dest, ignore=['Thumbs.db'])
    for destFile in dirCmp.right_only:
        destFilePath = dest+'/'+destFile
        if os.path.isfile(destFilePath):
            print u'删除文件\n',destFilePath
            os.remove(destFilePath)
        else:
            print u'删除文件夹\n',destFilePath
#            os.rmdir(destFilePath)
            shutil.rmtree(destFilePath)
    for srcFile in dirCmp.left_only:
        srcFilePath = src+'/'+srcFile
        destFilePath = dest+'/'+srcFile
        if os.path.isfile(srcFilePath):
            print u'复制文件\n',destFilePath
            shutil.copy2(srcFilePath, dest)
        else:
            print u'复制文件夹\n',destFilePath
            shutil.copytree(srcFilePath, destFilePath)
    for srcFile in dirCmp.diff_files:
        srcFilePath = src+'/'+srcFile
        destFilePath = dest+'/'+srcFile
        print u'同步文件\n',destFilePath
        shutil.copy2(srcFilePath, dest)
    subDirs = set(os.listdir(src))-set(dirCmp.left_only)
    targetDirs = [subDir for subDir in subDirs if os.path.isdir(src+'/'+subDir)]
    for targetDir in targetDirs:
        walk(src+'/'+targetDir, dest+'/'+targetDir)
开发者ID:mrwlwan,项目名称:workspace2014,代码行数:32,代码来源:syncfiles_office.py



注:本文中的shutil.copytree函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shutil.disk_usage函数代码示例发布时间:2022-05-27
下一篇:
Python shutil.copystat函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap