本文整理匯總了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
示例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
示例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
示例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)