本文整理汇总了Python中ranger.ext.shell_escape.esc函数的典型用法代码示例。如果您正苦于以下问题:Python esc函数的具体用法?Python esc怎么用?Python esc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了esc函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self):
import os
import sys
import tempfile
from ranger.container.file import File
from ranger.ext.shell_escape import shell_escape as esc
py3 = sys.version_info[0] >= 3
output = self.arg(1)
if not self.arg(1):
output = "output.pdf"
# Create and edit the file list
filenames = [f.relative_path for f in self.fm.thistab.get_selection()]
listfile = tempfile.NamedTemporaryFile(delete=False)
listpath = listfile.name
if py3:
listfile.write("\n".join(filenames).encode("utf-8"))
else:
listfile.write("\n".join(filenames))
listfile.close()
self.fm.execute_file([File(listpath)], app='editor')
listfile = open(listpath, 'r')
# TODO check name and number consistance
new_filenames = listfile.read().split("\n")
listfile.close()
os.unlink(listpath)
listfilenames = " ".join((esc(f) for f in new_filenames))
# if all(a == b for a, b in zip(filenames, new_filenames)):
# self.fm.notify("No renaming to be done!")
# return
# TODO check output name
# Generate script
cmdfile = tempfile.NamedTemporaryFile()
script_lines = []
script_lines.append("# This file will be executed when you close the editor.\n")
script_lines.append("# Please double-check everything, clear the file to abort.\n")
script_lines.extend("pdfjam %s -o %s\n" % (listfilenames, esc(output)))
script_content = "".join(script_lines)
if py3:
cmdfile.write(script_content.encode("utf-8"))
else:
cmdfile.write(script_content)
cmdfile.flush()
# Open the script and let the user review it, then check if the script
# was modified by the user
self.fm.execute_file([File(cmdfile.name)], app='editor')
cmdfile.seek(0)
script_was_edited = (script_content != cmdfile.read())
# # Do the renaming
self.fm.run(['/bin/sh', cmdfile.name], flags='w')
cmdfile.close()
开发者ID:VincentVigneron,项目名称:vimconf,代码行数:57,代码来源:commands.py
示例2: execute
def execute(self):
archive = self.rest(1)
if not archive:
self.fm.notify("Error: missing archive filename", bad=True)
return
cmd = self.command.format(esc(archive))
if '%' in cmd:
cmd = self.fm.substitute_macros(cmd, escape=True)
self.fm.execute_command(cmd)
开发者ID:jmcantrell,项目名称:dotfiles,代码行数:9,代码来源:commands.py
示例3: execute
def execute(self):
import sys
import tempfile
from os.path import relpath
from ranger.container.file import File
from ranger.ext.shell_escape import shell_escape as esc
py3 = sys.version > "3"
# Create and edit the file list
filenames = [relpath(f.path, start=self.fm.thisdir.path)
for f in self.fm.thistab.get_selection()]
listfile = tempfile.NamedTemporaryFile(delete=False)
listpath = listfile.name
if py3:
listfile.write("\n".join(filenames).encode("utf-8"))
else:
listfile.write("\n".join(filenames))
listfile.close()
self.fm.execute_file([File(listpath)], app='editor')
listfile = open(listpath, 'r')
new_filenames = listfile.read().split("\n")
listfile.close()
os.unlink(listpath)
if all(a == b for a, b in zip(filenames, new_filenames)):
self.fm.notify("No renaming to be done!")
return
# Generate and execute script
cmdfile = tempfile.NamedTemporaryFile()
cmdfile.write(b"# This file will be executed when you close the editor.\n")
cmdfile.write(b"# Please double-check everything, clear the file to abort.\n")
if py3:
cmdfile.write("\n".join("mv -vi -- " + esc(old) + " " + esc(new) \
for old, new in zip(filenames, new_filenames) \
if old != new).encode("utf-8"))
else:
cmdfile.write("\n".join("mv -vi -- " + esc(old) + " " + esc(new) \
for old, new in zip(filenames, new_filenames) if old != new))
cmdfile.flush()
self.fm.execute_file([File(cmdfile.name)], app='editor')
self.fm.run(['/bin/sh', cmdfile.name], flags='w')
cmdfile.close()
开发者ID:none23,项目名称:dotfiles,代码行数:43,代码来源:commands.py
示例4: execute
def execute(self): # pylint: disable=too-many-locals,too-many-statements
import sys
import tempfile
from ranger.container.file import File
from ranger.ext.shell_escape import shell_escape as esc
py3 = sys.version_info[0] >= 3
# Create and edit the file list
filenames = [f.relative_path for f in self.fm.thistab.get_selection()]
listfile = tempfile.NamedTemporaryFile(delete=False)
listpath = listfile.name
if py3:
listfile.write("\n".join(filenames).encode("utf-8"))
else:
listfile.write("\n".join(filenames))
listfile.close()
self.fm.execute_file([File(listpath)], app='editor')
listfile = open(listpath, 'r')
new_filenames = listfile.read().split("\n")
listfile.close()
os.unlink(listpath)
if all(a == b for a, b in zip(filenames, new_filenames)):
self.fm.notify("No renaming to be done!")
return
# Generate script
cmdfile = tempfile.NamedTemporaryFile()
script_lines = []
script_lines.append("# This file will be executed when you close the editor.\n")
script_lines.append("# Please double-check everything, clear the file to abort.\n")
script_lines.extend("mv -vi -- %s %s\n" % (esc(old), esc(new))
for old, new in zip(filenames, new_filenames) if old != new)
script_content = "".join(script_lines)
if py3:
cmdfile.write(script_content.encode("utf-8"))
else:
cmdfile.write(script_content)
cmdfile.flush()
# Open the script and let the user review it, then check if the script
# was modified by the user
self.fm.execute_file([File(cmdfile.name)], app='editor')
cmdfile.seek(0)
script_was_edited = (script_content != cmdfile.read())
# Do the renaming
self.fm.run(['/bin/sh', cmdfile.name], flags='w')
cmdfile.close()
# Retag the files, but only if the script wasn't changed during review,
# because only then we know which are the source and destination files.
if not script_was_edited:
tags_changed = False
for old, new in zip(filenames, new_filenames):
if old != new:
oldpath = self.fm.thisdir.path + '/' + old
newpath = self.fm.thisdir.path + '/' + new
if oldpath in self.fm.tags:
old_tag = self.fm.tags.tags[oldpath]
self.fm.tags.remove(oldpath)
self.fm.tags.tags[newpath] = old_tag
tags_changed = True
if tags_changed:
self.fm.tags.dump()
else:
fm.notify("files have not been retagged")
开发者ID:sim590,项目名称:dotfiles,代码行数:67,代码来源:commands.py
注:本文中的ranger.ext.shell_escape.esc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论