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


Python shell_escape.shell_quote函数代码示例

本文整理汇总了Python中ranger.ext.shell_escape.shell_quote函数的典型用法代码示例。如果您正苦于以下问题:Python shell_quote函数的具体用法?Python shell_quote怎么用?Python shell_quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: sxiv_workaround_hook

        def sxiv_workaround_hook(command):
            import re
            from ranger.ext.shell_escape import shell_quote

            if self.settings.open_all_images and \
                    len(self.thisdir.marked_items) == 0 and \
                    re.match(r'^(feh|sxiv) ', command):

                images = [f.basename for f in self.thisdir.files if f.image]
                escaped_filenames = " ".join(shell_quote(f) \
                        for f in images if "\x00" not in f)

                if images and self.thisfile.basename in images and \
                        "[email protected]" in command:
                    new_command = None

                    if command[0:5] == 'sxiv ':
                        number = images.index(self.thisfile.basename) + 1
                        new_command = command.replace("sxiv ",
                                "sxiv -n %d " % number, 1)

                    if command[0:4] == 'feh ':
                        new_command = command.replace("feh ",
                            "feh --start-at %s " % \
                            shell_quote(self.thisfile.basename), 1)

                    if new_command:
                        command = "set -- %s; %s" % (escaped_filenames,
                                new_command)
            return old_preprocessing_hook(command)
开发者ID:anekos,项目名称:ranger,代码行数:30,代码来源:fm.py

示例2: execute

    def execute(self):
        import subprocess
        from ranger.core.loader import safeDecode
        import sys
        import os.path

        if self.rest(1):
            command = 'find . -iname ' + shell_quote('*' + self.rest(1) + '*') + \
                    '| slmenu -t -i -l $(($(tput lines)-1)) -p locate '
            self.fm.ui.suspend()
            try:
                p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
                filename = p.communicate()[0]
            finally:
                self.fm.ui.initialize()
            if p.poll() == 0: # no error returned
                if sys.version >= '3':
                    filename = safeDecode(filename)
                # remove the newline
                filename = filename.rstrip('\n')
                # make the path absolute
                filename = os.path.join(self.fm.thisdir.path, filename.lstrip('./'))
                # select the file
                self.fm.select_file(filename)
        else:
            self.fm.notify('usage: locate <name_part>', bad=True)
开发者ID:PotatoesMaster,项目名称:dotfiles,代码行数:26,代码来源:commands.py

示例3: substitute_macros

 def substitute_macros(self, string, additional=dict(), escape=False):
     macros = self._get_macros()
     macros.update(additional)
     if escape:
         for key, value in macros.items():
             if isinstance(value, list):
                 macros[key] = " ".join(shell_quote(s) for s in value)
             elif value != MACRO_FAIL:
                 macros[key] = shell_quote(value)
     else:
         for key, value in macros.items():
             if isinstance(value, list):
                 macros[key] = " ".join(value)
     result = _MacroTemplate(string).safe_substitute(macros)
     if MACRO_FAIL in result:
         raise ValueError("Could not apply macros to `%s'" % string)
     return result
开发者ID:9M2PJU,项目名称:ranger,代码行数:17,代码来源:actions.py

示例4: sxiv_workaround_hook_modified

    def sxiv_workaround_hook_modified(command):
        import re
        from ranger.ext.shell_escape import shell_quote

        if self.settings.open_all_images and \
                len(self.thisdir.marked_items) == 0 and \
                re.match(r'^(.*sxiv|feh|imv|.*pqiv) ', command):

            images = [f.relative_path for f in self.thisdir.files if f.image]
            media = [f.relative_path for f in self.thisdir.files if f.image
                     or f.video]
            escaped_filenames = " ".join(shell_quote(f) \
                    for f in images if "\x00" not in f)

            if (images and self.thisfile.relative_path in images) or \
                    (media and self.this)and \
                    "[email protected]" in command:
                new_command = None

                if 'sxiv ' in command:
                    number = images.index(self.thisfile.relative_path) + 1
                    new_command = command.replace("sxiv ",
                            "sxiv -n %d " % number, 1)

                if command[0:4] == 'feh ':
                    new_command = command.replace("feh ",
                        "feh --start-at %s " % \
                        shell_quote(self.thisfile.relative_path), 1)

                if command[0:4] == 'imv ':
                    number = images.index(self.thisfile.relative_path) + 1
                    new_command = command.replace("imv ",
                            "imv -n %d " % number, 1)

                if 'pqiv ' in command:
                    number = images.index(self.thisfile.relative_path)
                    new_command = command.replace("pqiv ",
                            "pqiv --action \"goto_file_byindex(%d)\" " % \
                            number, 1)

                if new_command:
                    command = "set -- %s; %s" % (escaped_filenames,
                            new_command)
        return old_preprocessing_hook(command)
开发者ID:noctuid,项目名称:dotfiles,代码行数:44,代码来源:sxiv_opener.py

示例5: _quot

 def _quot(self, patt):
     return patt if ag.qarg.match(patt) else shell_quote(patt)
开发者ID:amerlyq,项目名称:airy,代码行数:2,代码来源:commands.py

示例6: _get_macros

	def _get_macros(self):
		macros = {}

		if self.fm.env.cf:
			macros['f'] = shell_quote(self.fm.env.cf.basename)
		else:
			macros['f'] = ''

		macros['s'] = ' '.join(shell_quote(fl.basename) \
				for fl in self.fm.env.get_selection())

		macros['c'] = ' '.join(shell_quote(fl.path)
				for fl in self.fm.env.copy)

		macros['t'] = ' '.join(shell_quote(fl.basename)
				for fl in self.fm.env.cwd.files
				if fl.realpath in self.fm.tags)

		if self.fm.env.cwd:
			macros['d'] = shell_quote(self.fm.env.cwd.path)
		else:
			macros['d'] = '.'

		# define d/f/s macros for each tab
		for i in range(1,10):
			try:
				tab_dir_path = self.fm.tabs[i]
			except:
				continue
			tab_dir = self.fm.env.get_directory(tab_dir_path)
			i = str(i)
			macros[i + 'd'] = shell_quote(tab_dir_path)
			macros[i + 'f'] = shell_quote(tab_dir.pointed_obj.path)
			macros[i + 's'] = ' '.join(shell_quote(fl.path)
				for fl in tab_dir.get_selection())

		# define D/F/S for the next tab
		found_current_tab = False
		next_tab_path = None
		first_tab = None
		for tab in self.fm.tabs:
			if not first_tab:
				first_tab = tab
			if found_current_tab:
				next_tab_path = self.fm.tabs[tab]
				break
			if self.fm.current_tab == tab:
				found_current_tab = True
		if found_current_tab and not next_tab_path:
			next_tab_path = self.fm.tabs[first_tab]
		next_tab = self.fm.env.get_directory(next_tab_path)

		macros['D'] = shell_quote(next_tab)
		macros['F'] = shell_quote(next_tab.pointed_obj.path)
		macros['S'] = ' '.join(shell_quote(fl.path)
			for fl in next_tab.get_selection())

		return macros
开发者ID:tonttu,项目名称:ranger,代码行数:58,代码来源:actions.py

示例7: hook_init

def hook_init(fm):
    old_hook_init(fm)
    fm.get_clipboard = lambda r='b': _xsel('-o' + r)
    fm.get_clipboard_q = lambda r='b': shell_quote(_xsel('-o' + r))

    fm.set_clipboard = lambda t, r='b': _xsel('-i' + r, input=t)
开发者ID:amerlyq,项目名称:airy,代码行数:6,代码来源:clipboard.py

示例8: test_shell_escape

	def test_shell_escape(self):
		from ranger.ext.shell_escape import shell_escape, shell_quote
		self.assertEqual(r"'luigi'\''s pizza'", shell_quote("luigi's pizza"))
		self.assertEqual(r"luigi\'s\ pizza", shell_escape("luigi's pizza"))
		self.assertEqual(r"\$lol/foo\\xyz\|\>\<\]\[",
				shell_escape(r"$lol/foo\xyz|><]["))
开发者ID:Dieterbe,项目名称:ranger,代码行数:6,代码来源:tc_ext.py


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