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

Python shutil.copy2函数代码示例

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

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



在下文中一共展示了copy2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():

    # Parameters.
    bookmarkdir = os.environ["HOME"] + "/Dropbox/Apps/pinboard/"
    pinboard_credentials = bookmarkdir + "pinboard_credentials.txt"
    current = bookmarkdir + "most_current_bookmarks.xml"

    pinboard_api = "https://api.pinboard.in/v1/"
    yearfmt = "%Y"
    datefmt = "%m-%d"
    homeTZ = pytz.timezone("GMT")
    y = datetime.now(pytz.utc).strftime(yearfmt)
    t = datetime.now(pytz.utc).strftime(datefmt)

    daily_file = bookmarkdir + y + "/pinboard-backup." + t + ".xml"

    # Get the user's authentication token
    with open(pinboard_credentials) as credentials:
        for line in credentials:
            me, token = line.split(":")

    if not os.path.exists(bookmarkdir + y):
        os.makedirs(bookmarkdir + y)

    # Set up a new bookmarks file
    bookmarkfile = open(daily_file, "w")

    # Get all the posts from Pinboard
    u = urllib2.urlopen(pinboard_api + "posts/all?auth_token=" + me + ":" + token)
    bookmarkfile.write(u.read())
    bookmarkfile.close()
    shutil.copy2(daily_file, current)
开发者ID:AlexKucera,项目名称:tinkertoys,代码行数:32,代码来源:exportPinboard.py


示例2: main

def main():
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    os.system("pip install certifi")

    print "Copying certifi's cacert.pem"
    import certifi
    shutil.copy2(certifi.where(), 'agkyra/resources/cacert.pem')
开发者ID:jaeko44,项目名称:agkyra,代码行数:7,代码来源:cacert_cp.py


示例3: buildApp

def buildApp():
    # ----------------------
    # Under Windows, we're just going to grab the xulrunner-stub.exe and run Resource Hacker
    # to rename it to "Kylo", set the icon, and set some version info, etc.
    reshack_temp_dir = os.path.join(Settings.prefs.build_dir, "stub")
    if not os.path.exists(reshack_temp_dir):
        os.makedirs(reshack_temp_dir)
    
    build_stub.main(Settings.config.get('App','Version'), 
                    Settings.config.get('App','BuildID'), 
                    temp_dir = reshack_temp_dir, 
                    stub_dir = os.path.join(Settings.prefs.build_dir, "application"))
    
    # ----------------------
    # We also need mozilla DLLS
    for lib in ["mozcrt19.dll", "mozutils.dll", "gkmedias.dll"]:
        f = os.path.join(Settings.prefs.xul_dir, lib)
        if (os.path.isfile(f)):
            shutil.copy2(f, os.path.join(Settings.prefs.build_dir, "application"))

    # ----------------------
    # Now let's grab the XULRunner directory and drop it in to our working application directory
    xulrunner_dir = os.path.join(Settings.prefs.build_dir, "application", "xulrunner")
    if not os.path.exists(xulrunner_dir):
        os.makedirs(xulrunner_dir)
        
    build_util.syncDirs(Settings.prefs.xul_dir, xulrunner_dir, exclude=["xulrunner-stub.exe"])
开发者ID:sparkhill,项目名称:kylo-browser,代码行数:27,代码来源:platform_build.py


示例4: copyfile

def copyfile(src, dst, logger=None, force=True, vars=None, subst_content=False):
    if vars is not None:
        src = subst_vars(src, **vars)
        dst = subst_vars(dst, **vars)
    
    if not os.path.exists(src) and not force:
        if logger is not None:
            logger.info("**Skiping copy file %s to %s. Source does not exists." % (src, dst))
        return
    
    if logger is not None:
        logger.info("Copying file %s to %s." % (src, dst))
    
    if vars is None or not subst_content:
        shutil.copy2(src, dst)
        return
    
    print ("copyfile " + src)
    f = open(src, "rt")
    content =  f.read()
    f.close()
    content = subst_vars(content, **vars)
    f = open(dst, "wt")
    f.write(content)
    f.close()
开发者ID:PySide,项目名称:packaging,代码行数:25,代码来源:utils.py


示例5: put_files_cache

 def put_files_cache(self):
     if getattr(self, "cached", None):
         return None
     sig = self.signature()
     ssig = Utils.to_hex(self.uid()) + Utils.to_hex(sig)
     dname = os.path.join(self.generator.bld.cache_global, ssig)
     tmpdir = tempfile.mkdtemp(prefix=self.generator.bld.cache_global + os.sep + "waf")
     try:
         shutil.rmtree(dname)
     except:
         pass
     try:
         for node in self.outputs:
             dest = os.path.join(tmpdir, node.name)
             shutil.copy2(node.abspath(), dest)
     except (OSError, IOError):
         try:
             shutil.rmtree(tmpdir)
         except:
             pass
     else:
         try:
             os.rename(tmpdir, dname)
         except OSError:
             try:
                 shutil.rmtree(tmpdir)
             except:
                 pass
         else:
             try:
                 os.chmod(dname, Utils.O755)
             except:
                 pass
开发者ID:jgoppert,项目名称:mavsim,代码行数:33,代码来源:Task.py


示例6: addFile

    def addFile(self, opath):
        """Copy PATH to MEDIADIR, and return new filename.
If the same name exists, compare checksums."""
        mdir = self.dir()
        # remove any dangerous characters
        base = re.sub(r"[][<>:/\\&]", "", os.path.basename(opath))
        dst = os.path.join(mdir, base)
        # if it doesn't exist, copy it directly
        if not os.path.exists(dst):
            shutil.copy2(opath, dst)
            return base
        # if it's identical, reuse
        if self.filesIdentical(opath, dst):
            return base
        # otherwise, find a unique name
        (root, ext) = os.path.splitext(base)
        def repl(match):
            n = int(match.group(1))
            return " (%d)" % (n+1)
        while True:
            path = os.path.join(mdir, root + ext)
            if not os.path.exists(path):
                break
            reg = " \((\d+)\)$"
            if not re.search(reg, root):
                root = root + " (1)"
            else:
                root = re.sub(reg, repl, root)
        # copy and return
        shutil.copy2(opath, path)
        return os.path.basename(os.path.basename(path))
开发者ID:aaronharsh,项目名称:libanki,代码行数:31,代码来源:media.py


示例7: copy_python

def copy_python(src, dst, symlinks=False):
    " Copies just Python source files "
    import shutil
    names = os.listdir(src)
    try:
        os.makedirs(dst)
    except:
        pass
    errors = []
    for name in names:
        srcname = os.path.join(src, name)
        dstname = os.path.join(dst, name)
        try:
            if symlinks and os.path.islink(srcname):
                linkto = os.readlink(srcname)
                os.symlink(linkto, dstname)
            elif os.path.isdir(srcname):
                if not name.startswith("."):
                    copy_python(srcname, dstname, symlinks)
            else:
                if name.endswith(".py"):
                    print "create", dstname
                    shutil.copy2(srcname, dstname)
            # XXX What about devices, sockets etc.?
        except (IOError, os.error), why:
            errors.append((srcname, dstname, str(why)))
        # catch the Error from the recursive copytree so that we can
        # continue with other files
        except Error, err:
            errors.extend(err.args[0])
开发者ID:frankk00,项目名称:pyxer,代码行数:30,代码来源:__init__.py


示例8: pull

    def pull(self):
        if common.isurl(self.source):
            self.download()
        else:
            shutil.copy2(self.source, self.source_dir)

        self.provision(self.source_dir)
开发者ID:Eroui,项目名称:snapcraft,代码行数:7,代码来源:sources.py


示例9: 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


示例10: 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


示例11: browse_curve_file

    def browse_curve_file(self, preferredExt="crv"):
        """
        Gets curve file from a file browser. If the returned string from the
        browser is a valid file, the curve input box is set to that new item
        and "Default Curve" and "Estimate Curve Only" are disabled

        Args:
            preferredExt (str): The extension that the browser will look for
                                whenever listing directories for a curve file
        """
        # make sure to filter out all unwanted files and leave a * (All Files)
        #
        filepaths = QtGui.QFileDialog.getOpenFileName(self, "Browse Curve Profile")
        filepaths = [x for x in filepaths if x.strip() != ""]

        for f in filepaths:
            if os.path.isfile(f) and f.lower().endswith(preferredExt):
                fname = paths.path_leaf(f)
                shutil.copy2(f, os.path.join(self.curveInputDir, fname))

                self.curveInput_cb.addItem(fname)
                index = self.curveInput_cb.findText(fname,
                                                    QtCore.Qt.MatchFixedString)
                if index >= 0:
                    self.curveInput_cb.setCurrentIndex(index)

                self.defaultCurve_cb.setEnabled(False)
                self.estimateCurve_cb.setEnabled(False)
开发者ID:gobomus,项目名称:hdrprocess,代码行数:28,代码来源:hdrprocess.py


示例12: configure_step

    def configure_step(self):
        """Configure SCOTCH build: locate the template makefile, copy it to a general Makefile.inc and patch it."""

        # pick template makefile
        comp_fam = self.toolchain.comp_family()
        if comp_fam == toolchain.INTELCOMP:  #@UndefinedVariable
            makefilename = 'Makefile.inc.x86-64_pc_linux2.icc'
        elif comp_fam == toolchain.GCC:  #@UndefinedVariable
            makefilename = 'Makefile.inc.x86-64_pc_linux2'
        else:
            self.log.error("Unknown compiler family used: %s" % comp_fam)

        # create Makefile.inc
        try:
            srcdir = os.path.join(self.cfg['start_dir'], 'src')
            src = os.path.join(srcdir, 'Make.inc', makefilename)
            dst = os.path.join(srcdir, 'Makefile.inc')
            shutil.copy2(src, dst)
            self.log.debug("Successfully copied Makefile.inc to src dir.")
        except OSError:
            self.log.error("Copying Makefile.inc to src dir failed.")

        # the default behaviour of these makefiles is still wrong
        # e.g., compiler settings, and we need -lpthread
        try:
            for line in fileinput.input(dst, inplace=1, backup='.orig.easybuild'):
                # use $CC and the likes since we're at it.
                line = re.sub(r"^CCS\s*=.*$", "CCS\t= $(CC)", line)
                line = re.sub(r"^CCP\s*=.*$", "CCP\t= $(MPICC)", line)
                line = re.sub(r"^CCD\s*=.*$", "CCD\t= $(MPICC)", line)
                # append -lpthread to LDFLAGS
                line = re.sub(r"^LDFLAGS\s*=(?P<ldflags>.*$)", "LDFLAGS\t=\g<ldflags> -lpthread", line)
                sys.stdout.write(line)
        except IOError, err:
            self.log.error("Can't modify/write Makefile in 'Makefile.inc': %s" % (err))
开发者ID:MGaafar,项目名称:easybuild-easyblocks,代码行数:35,代码来源:scotch.py


示例13: savedir

 def savedir(self, savedir):
     if savedir is None:
         self._savedir = None
     elif hasattr(self, '_savedir') and savedir == self.savedir:
         return
     else:
         if hasattr(self, '_savedir'):
             orig_dir = self.savedir
         else:
             orig_dir = False
         savedir = abspath(savedir)
         if not savedir.endswith('.sima'):
             savedir += '.sima'
         os.makedirs(savedir)
         self._savedir = savedir
         if orig_dir:
             from shutil import copy2
             for f in os.listdir(orig_dir):
                 if f.endswith('.pkl'):
                     try:
                         copy2(os.path.join(orig_dir, f), self.savedir)
                     except IOError:
                         pass
         if self._read_only:
             self._read_only = False
开发者ID:deep-introspection,项目名称:sima,代码行数:25,代码来源:imaging.py


示例14: _stage_files

    def _stage_files(self, bin_name=None):
        dirs = self.query_abs_dirs()
        abs_app_dir = self.query_abs_app_dir()

        # For mac these directories are in Contents/Resources, on other
        # platforms abs_res_dir will point to abs_app_dir.
        abs_res_dir = self.query_abs_res_dir()
        abs_res_components_dir = os.path.join(abs_res_dir, 'components')
        abs_res_plugins_dir = os.path.join(abs_res_dir, 'plugins')
        abs_res_extensions_dir = os.path.join(abs_res_dir, 'extensions')

        if bin_name:
            self.info('copying %s to %s' % (os.path.join(dirs['abs_test_bin_dir'],
                      bin_name), os.path.join(abs_app_dir, bin_name)))
            shutil.copy2(os.path.join(dirs['abs_test_bin_dir'], bin_name),
                         os.path.join(abs_app_dir, bin_name))

        self.copytree(dirs['abs_test_bin_components_dir'],
                      abs_res_components_dir,
                      overwrite='overwrite_if_exists')
        self.mkdir_p(abs_res_plugins_dir)
        self.copytree(dirs['abs_test_bin_plugins_dir'],
                      abs_res_plugins_dir,
                      overwrite='overwrite_if_exists')
        if os.path.isdir(dirs['abs_test_extensions_dir']):
            self.mkdir_p(abs_res_extensions_dir)
            self.copytree(dirs['abs_test_extensions_dir'],
                          abs_res_extensions_dir,
                          overwrite='overwrite_if_exists')
开发者ID:zbraniecki,项目名称:gecko-dev,代码行数:29,代码来源:desktop_unittest.py


示例15: _persist_file

    def _persist_file(self, abspath):
        """Persist file and bind mount it back to its current location
        """

        persisted_path = self._config_path(abspath)
        if os.path.exists(persisted_path):
            current_checksum = self.checksum(abspath)
            stored_checksum = self.checksum(persisted_path)
            if stored_checksum == current_checksum:
                self._logger.warn('File "%s" had already been persisted',
                                  abspath)
                return
            else:
                # If this happens, somehow the bind mount was undone, so we try
                # and clean up before re-persisting
                try:
                    if mount.ismount(abspath):
                        mount.umount(abspath)
                    os.unlink(persisted_path)
                except OSError as ose:
                    self._logger.error('Failed to clean up persisted file '
                                       '"%s": %s', abspath, ose.message)
        self._prepare_dir(abspath, persisted_path)
        shutil.copy2(abspath, persisted_path)
        self.copy_attributes(abspath, persisted_path)
        mount.mount(persisted_path, abspath, flags=mount.MS_BIND)
        self._logger.info('File "%s" successfully persisted', abspath)
        self._add_path_entry(abspath)
开发者ID:oVirt,项目名称:ovirt-node,代码行数:28,代码来源:__init__.py


示例16: ca

def ca(source, destination, user=None, group=None):
    """
    Copy the Certificate Authority (CA) to the destination, creating parent
    directories if needed and assign owner if set. The tls layer installs the
    CA on all the peers in /usr/local/share/ca-certificates/.

    :param string source: The path to look or the certificate, if None the
    CA will be copied from the default location.
    :param string destination: The path to save the CA certificate.
    :param string user: The optional user name to own the CA certificate.
    :param string group: The optional group name to own the CA certificate.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # When source not specified use the default CA path.
        source = \
            '/usr/local/share/ca-certificates/{0}.crt'.format(service_name())

    # Copy the ca certificate to the destination directory.
    copy2(source, destination)
    chown(destination, user, group)

    # Set the destination path for the ca certificate path on the unitdata.
    unitdata.kv().set('ca-cert-path', destination)
开发者ID:juju-solutions,项目名称:layer-tls,代码行数:25,代码来源:tlslib.py


示例17: create_reference

    def create_reference(self):
        """ Determines and passes the reference files to a reference folder.
        """
        if self.test_status == 'PASSED':
            reference_dir = os.path.join(self.ref_path, 'regtest-ref')
            create_dir(reference_dir)
            ltraj, lprop = self.get_filesname(self.test_path,
                                              reference_dir, self.io_dir)

            try:
                for prop in lprop:
                    for sprop in prop:
                        remove_file(sprop['old_filename'])
                        shutil.copy2(sprop['new_filename'],
                                     sprop['old_filename'])
                for traj in ltraj:
                    for straj in traj:
                        remove_file(straj['old_filename'])
                        shutil.copy2(straj['new_filename'],
                                     straj['old_filename'])
            except IOError, e:
                self.test_status = 'ERROR'
                self.msg += 'Error while copying the new reference!!\n'
                self.msg += "Unable to copy file. %s" % e
            else:
                self.test_status = 'COPIED'
开发者ID:epfl-cosmo,项目名称:i-pi-dev,代码行数:26,代码来源:regtest-parallel.py


示例18: server_key

def server_key(source, destination, user=None, group=None):
    """
    Copy the server key to the destination, creating directories if needed and
    assign ownership if set.

    :param string source: The directory to look for the key, if None the key
    will be copied from default location.
    :param string destination: The path to save the key.
    :param string user: The optional name of the user to own the key.
    :param string group: The optional name of the group to own key.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # Must remove the path characters from the local unit name.
        key_name = local_unit().replace('/', '_')
        # The location of server key is easy-rsa/easyrsa3/pki/private
        source = \
            os.path.join(
                charm_dir(),
                'easy-rsa/easyrsa3/pki/private/{0}.key'.format(key_name))

    # Copy the key to the destination.
    copy2(source, destination)
    chown(destination, user, group)

    # Set the destination path for the client key path on the unitdata.
    unitdata.kv().set('server-key-path', destination)
开发者ID:juju-solutions,项目名称:layer-tls,代码行数:28,代码来源:tlslib.py


示例19: _prepare_disks

def _prepare_disks(vm_settings, target_dir):
    """
    Prepare VM disks for OVF appliance creation.
    File based disks will be copied to VM creation directory.
    LVM and block-device based disks will be converted into file based images and copied to creation directory.

    @param target_dir: directory where disks will be copied
    """
    disk_list_dom = get_libvirt_conf_xml(vm_settings["vm_name"])\
                        .getElementsByTagName("domain")[0].getElementsByTagName("disk")
    disk_num, disk_list = 0, []
    for disk_dom in disk_list_dom:
        if disk_dom.getAttribute("device") == "disk":
            disk_num += 1
            source_dom = disk_dom.getElementsByTagName("source")[0]
            filename = "%s%d.img" % (vm_settings["template_name"], disk_num)
            new_path = path.join(target_dir, filename)
            if disk_dom.getAttribute("type") == "file":
                disk_path = source_dom.getAttribute("file")
                shutil.copy2(disk_path, new_path)
            elif disk_dom.getAttribute("type") == "block":
                source_dev = source_dom.getAttribute("dev")
                execute("qemu-img convert -f raw -O qcow2 %s %s" % (source_dev, new_path))
            disk_dict = {
                "file_size": str(get_file_size_bytes(new_path)),
                "filename": filename,
                "new_path": new_path,
                "file_id": "diskfile%d" % (disk_num),
                "disk_id": "vmdisk%d.img" % (disk_num),
                "disk_capacity": str(get_kvm_disk_capacity_bytes(new_path))
            }
            disk_list.append(disk_dict)
    return disk_list
开发者ID:murisfurder,项目名称:opennode-tui,代码行数:33,代码来源:kvm.py


示例20: client_cert

def client_cert(source, destination, user=None, group=None):
    """
    Copy the client certificate to the destination creating directories if
    needed and assign ownership if set.

    :param string source: The path to look for the certificate, if None
    the certificate will be copied from the default location.
    :param string destination: The path to save the certificate.
    :param string user: The optional name of the user to own the certificate.
    :param string group: The optional name of the group to own certificate.
    """
    _ensure_directory(destination, user, group)

    if not source:
        # When source not specified use the default client certificate path.
        source = os.path.join(charm_dir(),
                              'easy-rsa/easyrsa3/pki/issued/client.crt')

    # Check for the client certificate.
    if os.path.isfile(source):
        # Copy the client certificate to the destination.
        copy2(source, destination)
    else:
        # No client certificate file, get the value from unit data.
        client_cert_key = 'tls.client.certificate'
        # Save the certificate data to the destination.
        _save_unitdata(client_cert_key, destination)

    chown(destination, user, group)

    # Set the destination path for the client certificate path on the unitdata.
    unitdata.kv().set('client-cert-path', destination)
开发者ID:juju-solutions,项目名称:layer-tls,代码行数:32,代码来源:tlslib.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python shutil.copyfile函数代码示例发布时间:2022-05-27
下一篇:
Python shutil.copy函数代码示例发布时间: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