本文整理汇总了Python中ranger.core.loader.CommandLoader类的典型用法代码示例。如果您正苦于以下问题:Python CommandLoader类的具体用法?Python CommandLoader怎么用?Python CommandLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandLoader类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: execute
def execute(self):
""" Extract copied files to current directory """
cwd = self.fm.env.cwd
marked_files = tuple(cwd.get_selection())
#old version was wih copy instead of mark
#copied_files = tuple(self.fm.env.copy)
if not marked_files:
return
def refresh(_):
cwd = self.fm.env.get_directory(original_path)
cwd.load_content()
one_file = marked_files[0]
cwd = self.fm.env.cwd
original_path = cwd.path
au_flags = ['-X', cwd.path]
au_flags += self.line.split()[1:]
au_flags += ['-e']
self.fm.env.copy.clear()
self.fm.env.cut = False
if len(marked_files) == 1:
descr = "extracting: " + os.path.basename(one_file.path)
else:
descr = "extracting files from: " + os.path.basename(one_file.dirname)
obj = CommandLoader(args=['aunpack'] + au_flags \
+ [f.path for f in marked_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
开发者ID:nopjmp,项目名称:dotfiles-archive,代码行数:32,代码来源:commands.py
示例2: execute
def execute(self):
""" Extract copied files to current directory """
copied_files = tuple(self.fm.copy_buffer)
if not copied_files:
return
def refresh(_):
cwd = self.fm.get_directory(original_path)
cwd.load_content()
one_file = copied_files[0]
cwd = self.fm.thisdir
original_path = cwd.path
au_flags = ['-X', cwd.path]
au_flags += self.line.split()[1:]
au_flags += ['-e']
self.fm.copy_buffer.clear()
self.fm.cut_buffer = False
if len(copied_files) == 1:
descr = "extracting: " + os.path.basename(one_file.path)
else:
descr = "extracting files from: " + os.path.basename(one_file.dirname)
obj = CommandLoader(args=['aunpack'] + au_flags \
+ [f.path for f in copied_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
开发者ID:raphapr,项目名称:dotfiles,代码行数:29,代码来源:commands.py
示例3: execute
def execute(self):
""" Compress copied files to current directory """
copied_files = tuple(self.fm.copy_buffer)
if not copied_files:
return
def refresh(_):
cwd = self.fm.get_directory(original_path)
cwd.load_content()
one_file = copied_files[0]
cwd = self.fm.thisdir
original_path = cwd.path
parts = self.line.split()
au_flags = parts[1:]
descr = "compressing files in: " + os.path.basename(parts[1])
obj = CommandLoader(args=['apack'] + au_flags + \
[os.path.relpath(f.path, cwd.path) for f in copied_files], descr=descr)
self.fm.copy_buffer.clear()
self.fm.do_cut = False
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
开发者ID:PotatoesMaster,项目名称:dotfiles,代码行数:26,代码来源:commands.py
示例4: execute
def execute(self):
""" Compress marked files to current directory """
cwd = self.fm.env.cwd
marked_files = cwd.get_selection()
if not marked_files:
return
def refresh(_):
cwd = self.fm.env.get_directory(original_path)
cwd.load_content()
original_path = cwd.path
parts = self.line.split()
au_flags = parts[1:]
descr = "compressing files in: " + os.path.basename(parts[1])
obj = CommandLoader(args=['apack'] + au_flags + \
[os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
for f in marked_files:
cwd.mark_item(f, val=False)
开发者ID:hacklabcz,项目名称:pearl,代码行数:25,代码来源:commands.py
示例5: execute
def execute(self):
import os
cwd = self.fm.thisdir
cf = self.fm.thisfile
if not cwd or not cf:
self.fm.notify("Error: no file selected !", bad=True)
return
original_path = cwd.path
files = self.fm.thistab.get_selection()
languages = self.args[1:]
if not languages:
languages = ['en']
commandLine = ['subliminal', '-l']
commandLine += languages
commandLine += ['--']
commandLine += [f.basename for f in files]
descr = "Downloading {} subtitle(s)...".format(len(files))
obj = CommandLoader(args=commandLine , descr=descr)
def refresh(_):
cwd = self.fm.env.get_directory(original_path)
cwd.load_content()
self.fm.notify("Downloaded {} subtitle(s)".format(len(files)))
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
开发者ID:totakoko,项目名称:ranger-subliminal,代码行数:31,代码来源:commands.py
示例6: execute
def execute(self):
"""
:extract
Extract marked files to the current directory
"""
from os.path import basename
from ranger.core.loader import CommandLoader
cwd = self.fm.thisdir
marked_files = cwd.get_selection()
if not marked_files:
return
def refresh(_):
cwd = self.fm.env.get_directory(original_path)
cwd.load_content()
one_file = marked_files[0]
original_path = cwd.path
au_flags = ['-x']
au_flags += self.line.split()[1:]
au_flags += ['-e']
au_flags += ['-D']
if len(marked_files) == 1:
descr = "extracting: " + basename(one_file.path)
else:
descr = "extracting files from: " + basename(one_file.dirname)
obj = CommandLoader(args=['aunpack'] + au_flags \
+ [f.path for f in marked_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
开发者ID:gsnewmark,项目名称:dotfiles,代码行数:35,代码来源:commands.py
示例7: annex_call
def annex_call(fm, cmds, fname):
# git annex fails with absolute paths ...
thisdir = fm.thisdir
fname = os.path.basename(fname)
loader = CommandLoader(['git', 'annex'] + cmds + [fname],
'annex:{}'.format(' '.join(cmds)))
def reload_dir():
thisdir.unload()
thisdir.load_content()
loader.signal_bind('after', reload_dir)
fm.loader.add(loader)
开发者ID:matze,项目名称:ranger-annex,代码行数:13,代码来源:annex.py
示例8: _extract
def _extract(self, files, destination=None):
args = ['aunpack', '-e']
if destination is None:
args.extend((shell_escape(f.path) for f in files))
command = tmux_command(args)
else:
au_flags += ['-X', destination]
obj = CommandLoader(args=['aunpack'] + au_flags \
+ [f.path for f in files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
self.fm.execute_command(command)
开发者ID:Jdaco,项目名称:dotfiles,代码行数:13,代码来源:commands.py
示例9: paste
def paste(self, overwrite=False):
"""Paste the selected items into the current directory"""
copied_files = tuple(self.env.copy)
if not copied_files:
return
def refresh(_):
cwd = self.env.get_directory(original_path)
cwd.load_content()
cwd = self.env.cwd
original_path = cwd.path
one_file = copied_files[0]
if overwrite:
cp_flags = ['-af', '--']
mv_flags = ['-f', '--']
else:
cp_flags = ['--backup=numbered', '-a', '--']
mv_flags = ['--backup=numbered', '--']
if self.env.cut:
self.env.copy.clear()
self.env.cut = False
if len(copied_files) == 1:
descr = "moving: " + one_file.path
else:
descr = "moving files from: " + one_file.dirname
obj = CommandLoader(args=['mv'] + mv_flags \
+ [f.path for f in copied_files] \
+ [cwd.path], descr=descr)
else:
if len(copied_files) == 1:
descr = "copying: " + one_file.path
else:
descr = "copying files from: " + one_file.dirname
if not overwrite and len(copied_files) == 1 \
and one_file.dirname == cwd.path:
# Special case: yypp
# copying a file onto itself -> create a backup
obj = CommandLoader(args=['cp', '-f'] + cp_flags \
+ [one_file.path, one_file.path], descr=descr)
else:
obj = CommandLoader(args=['cp'] + cp_flags \
+ [f.path for f in copied_files] \
+ [cwd.path], descr=descr)
obj.signal_bind('after', refresh)
self.loader.add(obj)
开发者ID:tonttu,项目名称:ranger,代码行数:49,代码来源:actions.py
示例10: refresh
def refresh(_):
cwd = self.fm.get_directory(original_path)
cwd.load_content()
original_path = cwd.path
parts = self.line.split()
au_flags = parts[1:]
descr = "compressing files in: " + os.path.basename(parts[1])
obj = CommandLoader(args=['apack'] + au_flags + \
[os.path.relpath(f.path, cwd.path) for f in marked_files], descr=descr)
obj.signal_bind('after', refresh)
self.fm.loader.add(obj)
def tab(self):
""" Complete with current folder name """
extension = ['.zip', '.tar.gz', '.rar', '.7z']
return ['compress ' + os.path.basename(self.fm.thisdir.path) + ext for ext in extension]
开发者ID:c02y,项目名称:dotfiles,代码行数:15,代码来源:commands.py
示例11: get_preview
def get_preview(self, file, width, height):
pager = self.ui.get_pager()
path = file.realpath
if not path or not os.path.exists(path):
return None
if self.settings.preview_script and self.settings.use_preview_script:
# self.previews is a 2 dimensional dict:
# self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
# self.previews['/tmp/foo.jpg']['loading'] = False
# A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
# The key 'foundpreview' is added later. Values in (True, False)
# XXX: Previews can break when collapse_preview is on and the
# preview column is popping out as you move the cursor on e.g. a
# PDF file.
try:
data = self.previews[path]
except:
data = self.previews[path] = {'loading': False}
else:
if data['loading']:
return None
found = data.get((-1, -1), data.get((width, -1),
data.get((-1, height), data.get((width, height), False))))
if found == False:
try:
stat_ = os.stat(self.settings.preview_script)
except:
self.fm.notify("Preview Script `%s' doesn't exist!" %
self.settings.preview_script, bad=True)
return None
if not stat_.st_mode & S_IEXEC:
self.fm.notify("Preview Script `%s' is not executable!" %
self.settings.preview_script, bad=True)
return None
data['loading'] = True
if 'directimagepreview' in data:
data['foundpreview'] = True
data['imagepreview'] = True
pager.set_image(path)
data['loading'] = False
return path
cacheimg = os.path.join(ranger.arg.cachedir, self.sha1_encode(path))
if (os.path.isfile(cacheimg) and os.path.getmtime(cacheimg) > os.path.getmtime(path)):
data['foundpreview'] = True
data['imagepreview'] = True
pager.set_image(cacheimg)
data['loading'] = False
return cacheimg
loadable = CommandLoader(args=[self.settings.preview_script,
path, str(width), str(height), cacheimg,
str(self.settings.preview_images)], read=True,
silent=True, descr="Getting preview of %s" % path)
def on_after(signal):
exit = signal.process.poll()
content = signal.loader.stdout_buffer
data['foundpreview'] = True
if exit == 0:
data[(width, height)] = content
elif exit == 3:
data[(-1, height)] = content
elif exit == 4:
data[(width, -1)] = content
elif exit == 5:
data[(-1, -1)] = content
elif exit == 6:
data['imagepreview'] = True
elif exit == 7:
data['directimagepreview'] = True
elif exit == 1:
data[(-1, -1)] = None
data['foundpreview'] = False
elif exit == 2:
f = codecs.open(path, 'r', errors='ignore')
try:
data[(-1, -1)] = f.read(1024 * 32)
except UnicodeDecodeError:
f.close()
f = codecs.open(path, 'r', encoding='latin-1',
errors='ignore')
data[(-1, -1)] = f.read(1024 * 32)
f.close()
else:
data[(-1, -1)] = None
if self.thisfile and self.thisfile.realpath == path:
self.ui.browser.need_redraw = True
data['loading'] = False
pager = self.ui.get_pager()
if self.thisfile and self.thisfile.is_file:
if 'imagepreview' in data:
pager.set_image(cacheimg)
return cacheimg
#.........这里部分代码省略.........
开发者ID:9M2PJU,项目名称:ranger,代码行数:101,代码来源:actions.py
示例12: get_preview
def get_preview(self, path, width, height):
if self.settings.preview_script and self.settings.use_preview_script:
# self.previews is a 2 dimensional dict:
# self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
# self.previews['/tmp/foo.jpg']['loading'] = False
# A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
# The key 'foundpreview' is added later. Values in (True, False)
try:
data = self.previews[path]
except:
data = self.previews[path] = {'loading': False}
else:
if data['loading']:
return None
found = data.get((-1, -1), data.get((width, -1),
data.get((-1, height), data.get((width, height), False))))
if found == False:
data['loading'] = True
loadable = CommandLoader(args=[self.settings.preview_script,
path, str(width), str(height)], read=True,
silent=True, descr="Getting preview of %s" % path)
def on_after(signal):
exit = signal.process.poll()
content = signal.loader.stdout_buffer
data['foundpreview'] = True
if exit == 0:
data[(width, height)] = content
elif exit == 3:
data[(-1, height)] = content
elif exit == 4:
data[(width, -1)] = content
elif exit == 5:
data[(-1, -1)] = content
elif exit == 1:
data[(-1, -1)] = None
data['foundpreview'] = False
elif exit == 2:
data[(-1, -1)] = open(path, 'r').read(1024 * 32)
else:
data[(-1, -1)] = None
if self.env.cf.realpath == path:
self.ui.browser.need_redraw = True
data['loading'] = False
pager = self.ui.browser.pager
if self.env.cf and self.env.cf.is_file:
pager.set_source(self.env.cf.get_preview_source(
pager.wid, pager.hei))
def on_destroy(signal):
try:
del self.previews[path]
except:
pass
loadable.signal_bind('after', on_after)
loadable.signal_bind('destroy', on_destroy)
self.loader.add(loadable)
return None
else:
return found
else:
try:
return open(path, 'r')
except:
return None
开发者ID:tonttu,项目名称:ranger,代码行数:64,代码来源:actions.py
示例13: get_preview
def get_preview(self, path, width, height):
if self.settings.preview_script and self.settings.use_preview_script:
# self.previews is a 2 dimensional dict:
# self.previews['/tmp/foo.jpg'][(80, 24)] = "the content..."
# self.previews['/tmp/foo.jpg']['loading'] = False
# A -1 in tuples means "any"; (80, -1) = wid. of 80 and any hei.
# The key 'foundpreview' is added later. Values in (True, False)
# XXX: Previews can break when collapse_preview is on and the
# preview column is popping out as you move the cursor on e.g. a
# PDF file.
try:
data = self.previews[path]
except:
data = self.previews[path] = {'loading': False}
else:
if data['loading']:
return None
found = data.get((-1, -1), data.get((width, -1),
data.get((-1, height), data.get((width, height), False))))
if found == False:
data['loading'] = True
loadable = CommandLoader(args=[self.settings.preview_script,
path, str(width), str(height)], read=True,
silent=True, descr="Getting preview of %s" % path)
def on_after(signal):
exit = signal.process.poll()
content = signal.loader.stdout_buffer
data['foundpreview'] = True
if exit == 0:
data[(width, height)] = content
elif exit == 3:
data[(-1, height)] = content
elif exit == 4:
data[(width, -1)] = content
elif exit == 5:
data[(-1, -1)] = content
elif exit == 1:
data[(-1, -1)] = None
data['foundpreview'] = False
elif exit == 2:
f = codecs.open(path, 'r', errors='ignore')
try:
data[(-1, -1)] = f.read(1024 * 32)
except UnicodeDecodeError:
f.close()
f = codecs.open(path, 'r', encoding='latin-1',
errors='ignore')
data[(-1, -1)] = f.read(1024 * 32)
f.close()
else:
data[(-1, -1)] = None
if self.thisfile.realpath == path:
self.ui.browser.need_redraw = True
data['loading'] = False
pager = self.ui.browser.pager
if self.thisfile and self.thisfile.is_file:
pager.set_source(self.thisfile.get_preview_source(
pager.wid, pager.hei))
def on_destroy(signal):
try:
del self.previews[path]
except:
pass
loadable.signal_bind('after', on_after)
loadable.signal_bind('destroy', on_destroy)
self.loader.add(loadable)
return None
else:
return found
else:
try:
return codecs.open(path, 'r', errors='ignore')
except:
return None
开发者ID:MattWoelk,项目名称:ranger,代码行数:75,代码来源:actions.py
注:本文中的ranger.core.loader.CommandLoader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论