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


Python file.File方法代码示例

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


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

示例1: execute

# 需要导入模块: from ranger.container import file [as 别名]
# 或者: from ranger.container.file import File [as 别名]
def execute(self):
        from ranger.container.file import File

        new_path = self.rest(1)
        cf = self.fm.thisfile

        if not new_path:
            return self.fm.notify('Syntax: relink <newpath>', bad=True)

        if not cf.is_link:
            return self.fm.notify('%s is not a symlink!' % cf.relative_path, bad=True)

        if new_path == os.readlink(cf.path):
            return

        try:
            os.remove(cf.path)
            os.symlink(new_path, cf.path)
        except OSError as err:
            self.fm.notify(err)

        self.fm.reset()
        self.fm.thisdir.pointed_obj = cf
        self.fm.thisfile = cf 
开发者ID:i-PUSH,项目名称:arch-setup-i3wm,代码行数:26,代码来源:commands_full.py

示例2: execute

# 需要导入模块: from ranger.container import file [as 别名]
# 或者: from ranger.container.file import File [as 别名]
def execute(self):
        from ranger.container.file import File
        from os import access

        new_name = self.rest(1)

        if not new_name:
            return self.fm.notify('Syntax: rename <newname>', bad=True)

        if new_name == self.fm.thisfile.basename:
            return

        if access(new_name, os.F_OK):
            return self.fm.notify("Can't rename: file already exists!", bad=True)

        self.fm.rename(self.fm.thisfile, new_name)
        f = File(new_name)
        self.fm.thisdir.pointed_obj = f
        self.fm.thisfile = f 
开发者ID:bookletchoir,项目名称:dotfiles,代码行数:21,代码来源:commands.py

示例3: execute

# 需要导入模块: from ranger.container import file [as 别名]
# 或者: from ranger.container.file import File [as 别名]
def execute(self):
        from ranger.container.file import File

        new_path = self.rest(1)
        cf = self.fm.thisfile

        if not new_path:
            return self.fm.notify('Syntax: relink <newpath>', bad=True)

        if not cf.is_link:
            return self.fm.notify('%s is not a symlink!' % cf.basename, bad=True)

        if new_path == os.readlink(cf.path):
            return

        try:
            os.remove(cf.path)
            os.symlink(new_path, cf.path)
        except OSError as err:
            self.fm.notify(err)

        self.fm.reset()
        self.fm.thisdir.pointed_obj = cf
        self.fm.thisfile = cf 
开发者ID:francoiscote,项目名称:dotfiles,代码行数:26,代码来源:commands_full.py

示例4: execute

# 需要导入模块: from ranger.container import file [as 别名]
# 或者: from ranger.container.file import File [as 别名]
def execute(self):
        import os
        import shlex
        from functools import partial
        from ranger.container.file import File

        def is_directory_with_files(f):
            import os.path
            return (os.path.isdir(f) and not os.path.islink(f)
                and len(os.listdir(f)) > 0)

        if self.rest(1):
            files = shlex.split(self.rest(1))
            many_files = (len(files) > 1 or is_directory_with_files(files[0]))
        else:
            cwd = self.fm.thisdir
            cf = self.fm.thisfile
            if not cwd or not cf:
                self.fm.notify("Error: no file selected for deletion!", bad=True)
                return

            # relative_path used for a user-friendly output in the confirmation.
            files = [f.relative_path for f in self.fm.thistab.get_selection()]
            many_files = (cwd.marked_items or is_directory_with_files(cf.path))

        confirm = self.fm.settings.confirm_on_delete
        if confirm != 'never' and (confirm != 'multiple' or many_files):
            filename_list = files
            self.fm.ui.console.ask("Confirm deletion of: %s (y/N)" %
                ', '.join(files),
                partial(self._question_callback, files), ('n', 'N', 'y', 'Y'))
        else:
            # no need for a confirmation, just delete
            self.fm.delete(files) 
开发者ID:GuidoFe,项目名称:myDotFiles,代码行数:36,代码来源:commands_full.py


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