Ejemplo n.º 1
0
    def _run(
            self,
            args,
            path=None,  # pylint: disable=too-many-arguments
            catchout=True,
            retbytes=False,
            rstrip_newline=True):
        """Run a command"""
        cmd = [self.repotype] + args
        if path is None:
            path = self.path

        with open(os.devnull, 'w') as devnull:
            try:
                if catchout:
                    output = spawn(cmd,
                                   cwd=path,
                                   stderr=devnull,
                                   decode=not retbytes)
                    if (not retbytes and rstrip_newline
                            and output.endswith('\n')):
                        if rstrip_newline and output.endswith('\n'):
                            return output[:-1]
                    return output
                else:
                    subprocess.check_call(cmd,
                                          cwd=path,
                                          stdout=devnull,
                                          stderr=devnull)
            except (subprocess.CalledProcessError, FileNotFoundError):
                raise VcsError('{0:s}: {1:s}'.format(str(cmd), path))
Ejemplo n.º 2
0
	def _get_mimetype(self, fname):
		# Spawn "file" to determine the mime-type of the given file.
		if self._mimetype:
			return self._mimetype
		mimetype = spawn("file", "--mime-type", "-Lb", fname)
		self._mimetype = mimetype
		return mimetype
Ejemplo n.º 3
0
 def infostring(self, file, metadata):
     if not file.is_directory:
         from subprocess import Popen, PIPE, CalledProcessError
         try:
             fileinfo = spawn(["file", "-bL", file.path]).strip()
         except CalledProcessError:
             return "unknown"
         if sys.version_info[0] >= 3:
             fileinfo = fileinfo.decode("utf-8")
         return fileinfo
     else:
         raise NotImplementedError
Ejemplo n.º 4
0
    def execute(self):
        lastword = self.arg(-1)
        force = lastword == 'force'
        hash_pattern = re.compile(r'^[\d\w]=.')
        entries = spawn('zsh', '-ic', 'hash -d')

        self.fm.bookmarks.update_if_outdated()

        for i in entries.split('\n'):
            if hash_pattern.match(i):
                key, value = i[0], i[2:]
                if force or not key in self.fm.bookmarks.dct.keys():
                    self.fm.bookmarks[key] = Directory(value)
Ejemplo n.º 5
0
def spawn_xdg_user_dir(arg, default):
    ret = ''
    try:
        ret = spawn.check_output(['xdg-user-dir', arg]).strip()
    except AttributeError:
        try:
            ret = spawn.spawn(['xdg-user-dir', arg]).strip()
        except (OSError, CalledProcessError):
            ret = default
    except (OSError, CalledProcessError):
        ret = default
    ret = path.basename(ret)
    return ret
Ejemplo n.º 6
0
 def filetype(self):
     try:
         return spawn(["file", '-Lb', '--mime-type', self.path])
     except OSError:
         return ""
Ejemplo n.º 7
0
 def filetype(self):
     try:
         return spawn(["file", "-Lb", "--mime-type", self.path])
     except OSError:
         return ""
Ejemplo n.º 8
0
import os.path
from ranger.ext.spawn import spawn

# Expand zsh hashes in ranger

vanilla_expand = os.path.expanduser
hashes = [x.split('=') for x in spawn('zsh', '-ic', 'hash -d')[:-1].split('\n')]
hashes = {k: v for (k, v) in hashes}

def zsh_expand(path):
    global hashes

    if len(path) > 1 and path[0] == '~' and path[1] != '/':
        if '/' in path:
            end = path.index('/')
        else:
            end = len(path)
        name = path[1:end]
        if name in hashes:
            return hashes[name] + path[end:]
    return vanilla_expand(path)

os.path.expanduser = zsh_expand