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