def mount_sftp(self, remote_conf, mount_path): cmd = 'curlftpfs {host} {mount} -o user={user}:{pw}'.format( host=remote_conf['host'], mount=mount_path, user=shell_escape(remote_conf['username']), pw=shell_escape(remote_conf['password'])) return self.fm.run(cmd).returncode
def mount_sshfs(self, remote_conf, mount_path): pw_echo = 'echo ' + shell_escape(remote_conf['password']) ssh_uri = shell_escape('{}@{}:'.format( remote_conf['username'], remote_conf['host'], )) if remote_conf['root'] and len(remote_conf['root']) > 0: ssh_uri += shell_escape(remote_conf['root']) if remote_conf['password'] != '': cmd = '{pw} | sshfs {uri} {mount} -o password_stdin'.format( pw=pw_echo, uri=ssh_uri, mount=shell_escape(mount_path)) else: cmd = 'sshfs {uri} {mount}'.format(uri=ssh_uri, mount=shell_escape(mount_path)) return self.fm.run(cmd).returncode
def execute(self): remote_name = self.arg(1) template = '\n'.join([ 'protocol(ftp/sftp):', 'host:', 'username:'******'remote directory (default \'/\'):', ]) if not remote_name: self.fm.notify('Syntax: radd <name>{3,}') return conf_path = os.path.join(CONFIGS_DIR, remote_name) conf_existed = False if os.path.exists(conf_path): conf_existed = True else: with open(conf_path, 'w') as conf_file: conf_file.write(template) proc = self.fm.run('nvim ' + shell_escape(conf_path)) if proc.returncode != 0: self.fn.notify('Editor returned non-zero exit code. Aborting.') if not conf_existed: os.remove(conf_path) return if os.path.getsize(conf_path) == 0: self.fn.notify('File was empty. Aborting.') os.remove(conf_path) return
def shell_escaped_basename(self): return shell_escape(self.basename)
def _trash(self, files, relative_paths): from ranger.ext.shell_escape import shell_escape escaped_paths = ' '.join([shell_escape(f.path) for f in files]) self.fm.execute_command(f"trash-put -- {escaped_paths}", flags='s') self.fm.notify(f"Trashing {relative_paths}!")
def _trash(self, tfile): from ranger.ext.shell_escape import shell_escape escaped_path = shell_escape(tfile.path) self.fm.execute_command(f"trash-put -- {escaped_path}", flags='s') self.fm.notify(f"Trashing {tfile.relative_path}!")
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|><]["))
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|><]["))