Пример #1
0
 def guess_project_type(self, project_name):
     # if cwd is under project_dir, look there too
     # and combine the lists by priority with dedupe
     pdir = self.project_map[project_name]
     subdir = os.getcwd()
     if abspath(subdir).startswith(abspath(pdir)):
         fine = guess_dir_type(subdir)
     else:
         fine = []
     coarse = guess_dir_type(pdir)
     tmp = fine + [x for x in coarse if x not in fine]
     return tmp
Пример #2
0
    def _activate(self, path):
        absfpath = abspath(expanduser(path))
        self.publish(C_PRE_ACTIVATE, name=absfpath)
        if True:
            vbin = to_vbin(absfpath)
            vlib = to_vlib(absfpath)

            # compute e.g. <venv>/lib/python2.6.
            # we call bullshit if they have a more than one dir;
            # it might be a chroot but i dont think it's a venv
            python_dir = glob.glob(opj(vlib, 'python*/'))
            if len(python_dir) == 0:
                raise RuntimeError('no python dir in {0}'.format(vlib))
            if len(python_dir) > 1:
                err = "multiple python dirs matching in {0}".format(vlib)
                raise RuntimeError(err)
            python_dir = python_dir[0]

            # this bit might enable switching between two venv's
            # that are be "no-global-site" vs "use-global-site"
            # .. tabling it for now
            # site_file = opj(python_dir, 'site.py')
            # assert ope(site_file)
            # tmp = dict(__file__=site_file)
            # execfile(site_file, tmp)
            #  tmp['main']()

            # some environment variable manipulation that would
            # normally be done by 'source bin/activate', but is
            # not handled by activate_this.py
            #path = get_path().split(':')
            os.environ['VIRTUAL_ENV'] = absfpath

            sandbox = dict(__file__=opj(vbin, 'activate_this.py'))
            execfile(opj(vbin, 'activate_this.py'), sandbox)
            self.reset_path = sandbox['prev_sys_path']

            # libraries like 'datetime' can very occasionally fail on import
            # if this isnt done, and i'm not sure why activate_this.py doesnt
            # accomplish it.  it might have something to do with venv's using
            # mixed pythons (different versions) or mixed --no-site-packages
            # tabling it for now
            # dynload = opj(python_dir, 'lib-dynload')
            # sys.path.append(dynload)

            # NB: this rehash will update bins but iirc kills aliases!
            msg = '$PATH was adjusted to {0}'.format(os.environ['PATH'])
            smash_log.debug(msg)
            self.report('Adjusting $PATH')
            msg = 'rehashing aliases'
            smash_log.info(msg)
            self.shell.magic('rehashx')
            self.publish(C_POST_ACTIVATE, absfpath)
Пример #3
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
Пример #4
0
 def _event_set_project_map(self, key, val):
     """ final word in cleaning/verifying/binding
         input that goes to project_map.  project_map
         should have only pristine data. Therefore DO
         NOT abstract the helper method "_bind_project".
     """
     def _bind_project(name, path):
         """ NOTE: be aware this is also used for re-binding """
         if not ope(path):
             self.report("bound project {0} to nonexistent {1}".format(
                 name, path))
         self.update_interface()
     name = key
     clean_name = clean_project_name(name)
     clean_path = abspath(expanduser(val))
     dict.__setitem__(
         self.project_map,
         clean_name,
         clean_path)
     _bind_project(clean_name, clean_path)