当前位置: 首页>>代码示例>>Python>>正文


Python shutil.copymode方法代码示例

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


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

示例1: requirements_from_infile

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def requirements_from_infile(infile):
    outfile = infile.sibling(infile.basename()[:-len(".in")])
    with NamedTemporaryFile(
        prefix="{}.".format(outfile.basename()),
        suffix=".created-by-update-requirements-entrypoint",
        dir=os.path.dirname(outfile.parent().path),
        delete=False,
    ) as temporary_outfile:
        print "PROCESSING", infile
        check_call(
            ["docker", "run",
             "--rm",
             "--volume", "{}:/requirements.txt".format(infile.path),
             REQUIREMENTS_IMAGE],
            stdout=temporary_outfile
        )
        shutil.copymode(outfile.path, temporary_outfile.name)
        os.rename(temporary_outfile.name, outfile.path) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:20,代码来源:requirements.py

示例2: make_copyfile_symlink_aware

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def make_copyfile_symlink_aware():
    """The reasoning behind this monkeypatch is that cookiecutter doesn't
    respect symlinks at all, and at Yelp we use symlinks to reduce duplication
    in the soa configs. Maybe cookie-cutter will accept a symlink-aware PR?
    """
    orig_copyfile = shutil.copyfile
    orig_copymode = shutil.copymode

    def symlink_aware_copyfile(*args, **kwargs):
        kwargs.setdefault("follow_symlinks", False)
        orig_copyfile(*args, **kwargs)

    def symlink_aware_copymode(*args, **kwargs):
        kwargs.setdefault("follow_symlinks", False)
        orig_copymode(*args, **kwargs)

    shutil.copyfile = symlink_aware_copyfile
    shutil.copymode = symlink_aware_copymode
    try:
        yield
    finally:
        shutil.copyfile = orig_copyfile
        shutil.copymode = orig_copymode 
开发者ID:Yelp,项目名称:paasta,代码行数:25,代码来源:fsm_cmd.py

示例3: copymode

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def copymode(src, dst):
    """
    Copy the permission bits from src to dst. The file contents, owner, and
    group are unaffected. src and dst are path names given as strings.
    :Arguments:
        src - mode of the file to be copied
        dst - file on which mode has to be copied
    :Return:
        True/False - based on the success/failure of the operation
    """
    status = False
    try:
        shutil.copymode(src, dst)
        print_info("mode of src {} copied to dst {} successfully".
                   format(src, dst))
        status = True
    except Exception as e:
        print_error("copying file mode from {} to file {} raised exception {}".
                    format(src, dst, str(e)))
    return status 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:22,代码来源:file_Utils.py

示例4: main

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def main(root_path):
    for dir_path, dir_names, file_names in os.walk(root_path):
        for file_name in file_names:
            if file_name.endswith('.py') and file_name != 'setup.py':
                file_path = os.path.join(dir_path, file_name)
                with open(file_path) as file:
                    script = file.read()
                new_script = enable_absolute_imports(script, file_name)
                if new_script is not None:
                    temp_handle, temp_file_path = tempfile.mkstemp(prefix=file_name, dir=dir_path)
                    try:
                        with os.fdopen(temp_handle, 'w') as temp_file:
                            temp_file.write(new_script)
                    except:
                        os.unlink(temp_file_path)
                        raise
                    else:
                        shutil.copymode(file_path,temp_file_path)
                        os.rename(temp_file_path, file_path) 
开发者ID:DataBiosphere,项目名称:toil,代码行数:21,代码来源:absolute_imports.py

示例5: stage_new_units

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def stage_new_units(self, new_wants_dir):
        """Prepare new systemd units for activation.

        Unit files targeted by the symlinks in new_wants_dir are copied to a temporary location in the base systemd
        directory, and the symlinks are rewritten to target the intended final destination of the copied unit files.

        """
        for unit_name in self.unit_names(new_wants_dir):
            wants_symlink_path = os.path.join(new_wants_dir, unit_name)
            package_file_path = os.path.realpath(wants_symlink_path)
            systemd_file_path = os.path.join(self.__base_systemd, unit_name)
            tmp_systemd_file_path = systemd_file_path + self.new_unit_suffix

            # Copy the unit file to the systemd directory with a suffix added to the filename.
            # This file will be moved to systemd_file_path when the new package set is swapped in.
            shutil.copyfile(package_file_path, tmp_systemd_file_path)
            shutil.copymode(package_file_path, tmp_systemd_file_path)

            # Rewrite the symlink to point to the copied unit file's destination.
            # This symlink won't point to the correct file until the copied unit file is moved to its target location
            # during activate_new_unit_files().
            os.remove(wants_symlink_path)
            os.symlink(systemd_file_path, wants_symlink_path) 
开发者ID:dcos,项目名称:dcos,代码行数:25,代码来源:__init__.py

示例6: copy_file

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def copy_file(src, dst):
    """
    Tried to copy utf-8 text files line-by-line to avoid
    getting CRLF characters added on Windows.

    If the file fails to be decoded with utf-8, we revert to a regular copy.
    """
    try:
        with io.open(src, "r", encoding="utf-8") as fh_src:
            with io.open(dst, "w", encoding="utf-8", newline="\n") as fh_dst:
                for line in fh_src:
                    fh_dst.write(line)
    except UnicodeDecodeError:
        # Leave any other files alone.
        shutil.copy(src, dst)

    shutil.copymode(src, dst)

    repo = get_repo(dst)
    if repo:
        repo.index.add([dst]) 
开发者ID:conda-forge,项目名称:conda-smithy,代码行数:23,代码来源:feedstock_io.py

示例7: write_hunks

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def write_hunks(self, srcname, tgtname, hunks):
    src = open(srcname, "rb")
    tgt = open(tgtname, "wb")

    debug("processing target file %s" % tgtname)

    tgt.writelines(self.patch_stream(src, hunks))

    tgt.close()
    src.close()
    # [ ] TODO: add test for permission copy
    shutil.copymode(srcname, tgtname)
    return True 
开发者ID:costastf,项目名称:toonapilib,代码行数:15,代码来源:patch.py

示例8: _load_config

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def _load_config(self, config):
        self._mount_path = config.get('usb_drive', 'mount_path')
        self._readonly = config.getboolean('usb_drive', 'readonly')
        self._target_path = config.get('directory', 'path')
        self._copy_mode = config.get('copymode', 'mode')
        self._copyloader = config.getboolean('copymode', 'copyloader')
        self._password = config.get('copymode', 'password')

        #needs to be changed to a more generic approach to support other players
        self._extensions = '|'.join(config.get(self._config.get('video_looper', 'video_player'), 'extensions') \
                                 .translate(str.maketrans('','', ' \t\r\n.')) \
                                 .split(',')) 
开发者ID:adafruit,项目名称:pi_video_looper,代码行数:14,代码来源:usb_drive_copymode.py

示例9: copy_with_progress

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def copy_with_progress(self, src, dst, *, follow_symlinks=True):
        if os.path.isdir(dst):
            dst = os.path.join(dst, os.path.basename(src))

        # clear screen before copying
        self.clear_screen(False)

        self.copyfile(src, dst, follow_symlinks=follow_symlinks)
        # shutil.copymode(src, dst)
        return dst 
开发者ID:adafruit,项目名称:pi_video_looper,代码行数:12,代码来源:usb_drive_copymode.py

示例10: write_file

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def write_file(self, new_text, filename, old_text, encoding):
        orig_filename = filename
        if self._output_dir:
            if filename.startswith(self._input_base_dir):
                filename = os.path.join(self._output_dir,
                                        filename[len(self._input_base_dir):])
            else:
                raise ValueError('filename %s does not start with the '
                                 'input_base_dir %s' % (
                                         filename, self._input_base_dir))
        if self._append_suffix:
            filename += self._append_suffix
        if orig_filename != filename:
            output_dir = os.path.dirname(filename)
            if not os.path.isdir(output_dir) and output_dir:
                os.makedirs(output_dir)
            self.log_message('Writing converted %s to %s.', orig_filename,
                             filename)
        if not self.nobackups:
            # Make backup
            backup = filename + ".bak"
            if os.path.lexists(backup):
                try:
                    os.remove(backup)
                except OSError as err:
                    self.log_message("Can't remove backup %s", backup)
            try:
                os.rename(filename, backup)
            except OSError as err:
                self.log_message("Can't rename %s to %s", filename, backup)
        # Actually write the new file
        write = super(StdoutRefactoringTool, self).write_file
        write(new_text, filename, old_text, encoding)
        if not self.nobackups:
            shutil.copymode(backup, filename)
        if orig_filename != filename:
            # Preserve the file mode in the new output directory.
            shutil.copymode(orig_filename, filename) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:40,代码来源:main.py

示例11: copy

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def copy(self, target, mode=False, stat=False):
        """ copy path to target.

            If mode is True, will copy copy permission from path to target.
            If stat is True, copy permission, last modification
            time, last access time, and flags from path to target.
        """
        if self.check(file=1):
            if target.check(dir=1):
                target = target.join(self.basename)
            assert self!=target
            copychunked(self, target)
            if mode:
                copymode(self.strpath, target.strpath)
            if stat:
                copystat(self, target)
        else:
            def rec(p):
                return p.check(link=0)
            for x in self.visit(rec=rec):
                relpath = x.relto(self)
                newx = target.join(relpath)
                newx.dirpath().ensure(dir=1)
                if x.check(link=1):
                    newx.mksymlinkto(x.readlink())
                    continue
                elif x.check(file=1):
                    copychunked(x, newx)
                elif x.check(dir=1):
                    newx.ensure(dir=1)
                if mode:
                    copymode(x.strpath, newx.strpath)
                if stat:
                    copystat(x, newx) 
开发者ID:pytest-dev,项目名称:py,代码行数:36,代码来源:local.py

示例12: copymode

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def copymode(src, dest):
    """ copy permission from src to dst. """
    import shutil
    shutil.copymode(src, dest) 
开发者ID:pytest-dev,项目名称:py,代码行数:6,代码来源:local.py

示例13: write_hunks

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def write_hunks(self, srcname, tgtname, hunks):
        src = open(srcname, "rb")
        tgt = open(tgtname, "wb")

        debug(f"processing target file {tgtname}")

        tgt.writelines(self.patch_stream(src, hunks))

        tgt.close()
        src.close()
        shutil.copymode(srcname, tgtname)
        return True 
开发者ID:henrysky,项目名称:astroNN,代码行数:14,代码来源:patch_util.py

示例14: _copy_p

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def _copy_p(self, src, dst):
        if not self.dry_run:
            shutil.copy(src, dst)
            shutil.copymode(src, dst) 
开发者ID:glotzerlab,项目名称:signac,代码行数:6,代码来源:syncutil.py

示例15: configure_file

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import copymode [as 别名]
def configure_file(input_file, output_file, **kwargs):
    notice("Configuring '{0}' for output '{1}'", input_file, output_file)

    content = read(input_file)

    for name, value in kwargs.items():
        content = content.replace("@{0}@".format(name), value)

    write(output_file, content)

    _shutil.copymode(input_file, output_file) 
开发者ID:ssorj,项目名称:quiver,代码行数:13,代码来源:plano.py


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