Ejemplo n.º 1
0
    def on_file_input(self, fpath):
        def doit(_fpath, _suffix, _opener, _rest):
            if ope(_fpath) and not isdir(_fpath):
                if _opener is not None:
                    self.report(
                        'Using _opener "{0}" for "{1}"'.format(_opener, _suffix))
                    return '{0} {1}'.format(_opener, _fpath + _rest)
                else:
                    msg = "Legit file input, but no _suffix alias could be found for " + \
                        _suffix
                    self.report(msg)
                    if is_editable(_fpath):
                        self.report(
                            "File looks like ASCII text, assuming I should edit it")
                        return doit(_fpath, _suffix, 'ed', _rest)
            else:
                msg = 'Attempted file input, but path "{0}" does not exist'
                msg = msg.format(fpath)
                smash_log.info(msg)

        fpath = abspath(expanduser(fpath))

        if isdir(fpath) and self.automatic_cd:
            self.report('cd ' + fpath)
            self.smash.shell.magic('pushd ' + fpath)
            return True

        # handle input like .foo/bin/python,
        # this shouldn't really even get here but
        # ipython throws a syntax error
        if os.access(fpath, os.X_OK):
            return self.smash.shell.system(fpath)

        # isolate file:col:row syntax
        if not ope(fpath) and ':' in fpath:
            tmp = fpath
            fpath = tmp[:tmp.find(':')]
            rest = tmp[tmp.find(':'):]
        else:
            rest = ''

        # isolate file suffix, guess an opener
        suffix = splitext(fpath)[-1][1:].lower()
        opener = self.suffix_aliases.get(suffix, None)
        cmd = doit(fpath, suffix, opener, rest)
        if cmd:
            self.smash.shell.run_cell(cmd)
            return True
Ejemplo n.º 2
0
def unload_ipython_extension(ip):
    plugin_name = splitext(ops(__file__)[-1])[0]
    raise Exception(plugin_name)
    get_smash().plugins[plugin_name].uninstall()