當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。